MessageHandler.c 922 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986
  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. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  3512. //offline MeterValue Interval
  3513. TempMeterValueInterval = 0;
  3514. return result;
  3515. }
  3516. int ProcessShareMemory()
  3517. {
  3518. int result = PASS;
  3519. if(InitShareMemory() == FAIL)
  3520. {
  3521. DEBUG_ERROR("InitShareMemory NG\n");
  3522. if(ShmStatusCodeData!=NULL)
  3523. {
  3524. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3525. }
  3526. result = FAIL;
  3527. }
  3528. // Model name parsing
  3529. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3530. {
  3531. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3532. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3533. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3534. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3535. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3536. ) // 'D' means DC
  3537. {
  3538. // DO series
  3539. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3540. {
  3541. SystemInitial += 1;
  3542. gunTotalNumber += 1;
  3543. gunType[gun_index] = GUN_TYPE_DO;
  3544. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3545. {
  3546. case Gun_Type_Chademo:
  3547. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3548. break;
  3549. case Gun_Type_CCS_2:
  3550. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3551. break;
  3552. case Gun_Type_GB:
  3553. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3554. break;
  3555. case Gun_Type_AC:
  3556. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3557. break;
  3558. default:
  3559. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3560. break;
  3561. }
  3562. }
  3563. }
  3564. else
  3565. {
  3566. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3567. {
  3568. SystemInitial += 1;
  3569. gunTotalNumber += 1;
  3570. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3571. {
  3572. case Gun_Type_Chademo:
  3573. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3574. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3575. break;
  3576. case Gun_Type_CCS_2:
  3577. gunType[gun_index] = GUN_TYPE_CCS;
  3578. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3579. break;
  3580. case Gun_Type_GB:
  3581. gunType[gun_index] = GUN_TYPE_GBT;
  3582. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3583. break;
  3584. case Gun_Type_AC:
  3585. gunType[gun_index] = GUN_TYPE_AC;
  3586. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3587. break;
  3588. default:
  3589. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3590. break;
  3591. }
  3592. }
  3593. }
  3594. }
  3595. else
  3596. {
  3597. DEBUG_ERROR("Model name parsing fail.\n");
  3598. result = FAIL;
  3599. }
  3600. if(result != PASS)sleep(5);
  3601. return result;
  3602. }
  3603. void checkRemoteStart(uint8_t connectorIdInt)
  3604. {
  3605. uint8_t tempIndex;
  3606. int result = PASS;
  3607. char cmdBuf[512];
  3608. //check Transaction active
  3609. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3610. {
  3611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3612. {
  3613. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3614. }
  3615. else
  3616. {
  3617. tempIndex = connectorIdInt -1;
  3618. }
  3619. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3620. {
  3621. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3622. {
  3623. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3624. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3625. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3626. {
  3627. //Reserved
  3628. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3629. }
  3630. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3631. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3632. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3633. {
  3634. //Reserved
  3635. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3636. result = FAIL;
  3637. goto end;
  3638. }
  3639. else
  3640. {
  3641. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3642. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3643. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3644. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3645. {
  3646. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  3647. result = FAIL;
  3648. goto end;
  3649. }
  3650. }//END FOR ELSE
  3651. }
  3652. }// END FOR CHAdeMO_QUANTITY
  3653. }
  3654. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3655. {
  3656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3657. {
  3658. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3659. }
  3660. else
  3661. {
  3662. tempIndex = connectorIdInt -1;
  3663. }
  3664. for (int index = 0; index < CCS_QUANTITY; index++)
  3665. {
  3666. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3667. {
  3668. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3669. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3670. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3671. {
  3672. //Reserved
  3673. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3674. }
  3675. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3676. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3677. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3678. {
  3679. //Reserved
  3680. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3681. result = FAIL;
  3682. goto end;
  3683. }
  3684. else
  3685. {
  3686. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3687. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3688. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3689. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3690. {
  3691. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3692. result = FAIL;
  3693. goto end;
  3694. }
  3695. }// END FOR ELSE
  3696. }
  3697. }// END FOR CCS_QUANTITY
  3698. }
  3699. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3700. {
  3701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3702. {
  3703. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3704. }
  3705. else
  3706. {
  3707. tempIndex = connectorIdInt -1;
  3708. }
  3709. for (int index = 0; index < GB_QUANTITY; index++)
  3710. {
  3711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3712. {
  3713. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3714. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3715. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3716. {
  3717. //Reserved
  3718. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3719. }
  3720. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3721. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3722. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3723. {
  3724. //Reserved
  3725. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3726. result = FAIL;
  3727. goto end;
  3728. }
  3729. else
  3730. {
  3731. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3732. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3733. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3734. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3735. {
  3736. DEBUG_WARN("GBT connector not allow start cause busy.\n.");
  3737. result = FAIL;
  3738. goto end;
  3739. }
  3740. }// END FOR ELSE
  3741. }
  3742. } // END FOR GB_QUANTITY
  3743. }
  3744. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3745. {
  3746. tempIndex = connectorIdInt -1;
  3747. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3748. {
  3749. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3750. {
  3751. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3752. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3753. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3754. {
  3755. //Reserved
  3756. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3757. }
  3758. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3759. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3760. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3761. {
  3762. //Reserved
  3763. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3764. result = FAIL;
  3765. goto end;
  3766. }
  3767. else
  3768. {
  3769. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3770. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3771. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3772. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3773. {
  3774. DEBUG_WARN("Dispenser connector not allow start cause busy.\n.");
  3775. result = FAIL;
  3776. goto end;
  3777. }
  3778. }// END FOR ELSE
  3779. }
  3780. } // END FOR GB_QUANTITY
  3781. }
  3782. else
  3783. {
  3784. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3785. {
  3786. tempIndex = 2;
  3787. }
  3788. else
  3789. {
  3790. tempIndex = connectorIdInt -1;
  3791. }
  3792. for (int index = 0; index < AC_QUANTITY; index++)
  3793. {
  3794. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3795. {
  3796. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3797. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3798. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3799. {
  3800. //Reserved
  3801. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3802. }
  3803. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3804. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3805. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3806. {
  3807. //Reserved
  3808. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3809. result = FAIL;
  3810. goto end;
  3811. }
  3812. else
  3813. {
  3814. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3815. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3816. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3817. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3818. {
  3819. DEBUG_WARN("AC connector not allow start cause busy.\n.");
  3820. result = FAIL;
  3821. goto end;
  3822. }
  3823. }//END FOR ELSE
  3824. }
  3825. }// END FOR AC_QUANTITY
  3826. }
  3827. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3828. {
  3829. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3830. {
  3831. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3832. if((access("/Storage/OCPP_PH/TxProfile_Tmp.json", F_OK))!=-1)
  3833. {
  3834. sprintf(cmdBuf, "mv /Storage/OCPP_PH/TxProfile_Tmp.json /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  3835. system(cmdBuf);
  3836. }
  3837. }
  3838. else
  3839. {
  3840. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3841. result = FAIL;
  3842. }
  3843. }
  3844. end:
  3845. if(result == PASS)
  3846. {
  3847. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3848. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3849. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3850. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3851. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3852. }
  3853. }
  3854. void CheckSystemValue(void)
  3855. {
  3856. char filenmae[100]={0};
  3857. char str[100]={0};
  3858. int tempIndex = 0;
  3859. //===============================
  3860. // send Heartbeat
  3861. //===============================
  3862. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3863. {
  3864. //parameter for test
  3865. sendHeartbeatRequest(0);
  3866. //==============================================
  3867. // Reset Waiting Time
  3868. //==============================================
  3869. HeartBeatWithNOResponse += 2;
  3870. }
  3871. //===============================
  3872. // Credit deduct report
  3873. //===============================
  3874. if(ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq)
  3875. {
  3876. OCPP_insert_deduct_info(ShmOCPP16DataPH->TcciCustomData.DeductInfo.txId, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.creditNo,
  3877. ShmOCPP16DataPH->TcciCustomData.DeductInfo.deductResult, ShmOCPP16DataPH->TcciCustomData.DeductInfo.isDonateInvoice,
  3878. ShmOCPP16DataPH->TcciCustomData.DeductInfo.amount, (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.vemData,
  3879. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.ROC,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.RRN,
  3880. (char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.approvalNo,(char*)ShmOCPP16DataPH->TcciCustomData.DeductInfo.storeId);
  3881. ShmOCPP16DataPH->TcciCustomData.ReportCreditDeductReq = FALSE;
  3882. }
  3883. if(getDiffSecNow(clientTime.TcciQueryDeduct) > 5)
  3884. {
  3885. OCPP_query_deduct_info();
  3886. refreshStartTimer(&clientTime.TcciQueryDeduct);
  3887. }
  3888. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  3889. {
  3890. // ClockAlign MeterValue
  3891. if((server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3892. {
  3893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3894. {
  3895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3896. {
  3897. tempIndex = ((gun_index==2) ? 1: 0);
  3898. }
  3899. else
  3900. {
  3901. tempIndex = gun_index;
  3902. }
  3903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3904. {
  3905. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3906. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3907. {
  3908. reqClockAlignMeter[gun_index] = 1;
  3909. }
  3910. }// End for CHAdeMO
  3911. }
  3912. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3913. {
  3914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3915. {
  3916. tempIndex = ((gun_index==2) ? 1: 0);
  3917. }
  3918. else
  3919. {
  3920. tempIndex = gun_index;
  3921. }
  3922. for (int index = 0; index < CCS_QUANTITY; index++)
  3923. {
  3924. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3925. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3926. {
  3927. reqClockAlignMeter[gun_index] = 1;
  3928. }
  3929. } // End for CCS
  3930. }
  3931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3932. {
  3933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3934. {
  3935. tempIndex = ((gun_index==2) ? 1: 0);
  3936. }
  3937. else
  3938. {
  3939. tempIndex = gun_index;
  3940. }
  3941. for (int index = 0; index < GB_QUANTITY; index++)
  3942. {
  3943. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3944. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3945. {
  3946. reqClockAlignMeter[gun_index] = 1;
  3947. }
  3948. }// End for GB
  3949. }
  3950. else if(gunType[gun_index] == GUN_TYPE_DO)
  3951. {
  3952. tempIndex = gun_index;
  3953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3954. {
  3955. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3956. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3957. {
  3958. reqClockAlignMeter[gun_index] = 1;
  3959. }
  3960. }
  3961. }
  3962. else
  3963. {
  3964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3965. {
  3966. tempIndex = 2;
  3967. }
  3968. else
  3969. {
  3970. tempIndex = gun_index;
  3971. }
  3972. for (int index = 0; index < AC_QUANTITY; index++)
  3973. {
  3974. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3975. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3976. {
  3977. reqClockAlignMeter[gun_index] = 1;
  3978. }
  3979. }//End for AC
  3980. }
  3981. }
  3982. }
  3983. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3984. {
  3985. //==========================================
  3986. // Check remote start without connector id
  3987. //==========================================
  3988. if(ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq)
  3989. {
  3990. int connectorIdInt = -1;
  3991. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3992. {
  3993. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3994. {
  3995. connectorIdInt = (gun_index+1);
  3996. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3997. checkRemoteStart(connectorIdInt);
  3998. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  3999. break;
  4000. }
  4001. }
  4002. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  4003. {
  4004. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  4005. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 0;
  4006. }
  4007. }
  4008. //==========================================
  4009. // csu trigger DataTransferReq
  4010. //==========================================
  4011. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  4012. {
  4013. sendDataTransferRequest(gun_index);
  4014. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  4015. }
  4016. //===============================
  4017. // CSU Trigger Authorize Request
  4018. //===============================
  4019. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  4020. {
  4021. sendAuthorizeRequest(0);
  4022. authorizeRetryTimes = authorizeRetryTimes + 1;
  4023. if(authorizeRetryTimes < 3)
  4024. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4025. }
  4026. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  4027. {
  4028. authorizeRetryTimes = 0;
  4029. SetOcppConnStatus(FALSE);
  4030. server_sign = FALSE;
  4031. }
  4032. 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))
  4033. {
  4034. sendAuthorizeRequest(0);
  4035. }
  4036. //==============================================
  4037. // Charger start transaction
  4038. //==============================================
  4039. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  4040. {
  4041. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  4042. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  4043. sendStartTransactionRequest(gun_index);
  4044. refreshStartTimer(&clientTime.StartTransaction);
  4045. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4046. //storeTempStopTransaction(gun_index);
  4047. }
  4048. //==============================================
  4049. // Charger stop transaction
  4050. //==============================================
  4051. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  4052. {
  4053. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4054. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  4055. sendStopTransactionRequest(gun_index);
  4056. refreshStartTimer(&clientTime.StopTransaction);
  4057. memset(&ShmOCPP16DataPH->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  4058. }
  4059. //==============================================
  4060. // Charger status report
  4061. //==============================================
  4062. //--- Check Mode Change ---//
  4063. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4064. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4065. {
  4066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4067. {
  4068. tempIndex = ((gun_index==2) ? 1: 0);
  4069. }
  4070. else
  4071. {
  4072. tempIndex = gun_index;
  4073. }
  4074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4075. {
  4076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4077. {
  4078. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4079. {
  4080. // Sent unplug message for California pricing logic
  4081. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  4082. {
  4083. uint8_t ts[20];
  4084. getNowDatetime(ts);
  4085. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4086. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4087. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4088. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4089. }
  4090. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4091. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4092. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4093. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4094. {
  4095. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4096. if((access(filenmae,F_OK))!=-1)
  4097. {
  4098. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4099. sprintf(str,"rm -f %s",filenmae);
  4100. system(str);
  4101. }
  4102. }
  4103. }
  4104. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4105. #if 1 // for TempStopTransaction
  4106. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4107. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4108. {
  4109. checkTempStopTransaction(gun_index);
  4110. }
  4111. #endif
  4112. }
  4113. }
  4114. }
  4115. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4116. {
  4117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4118. {
  4119. tempIndex = ((gun_index==2) ? 1: 0);
  4120. }
  4121. else
  4122. {
  4123. tempIndex = gun_index;
  4124. }
  4125. for (int index = 0; index < CCS_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4128. {
  4129. 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]*/ )
  4130. {
  4131. // Sent unplug message for California pricing logic
  4132. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  4133. {
  4134. uint8_t ts[20];
  4135. getNowDatetime(ts);
  4136. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4137. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4138. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4139. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4140. }
  4141. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4142. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4143. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4144. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4145. {
  4146. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4147. if((access(filenmae,F_OK))!=-1)
  4148. {
  4149. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4150. sprintf(str,"rm -f %s",filenmae);
  4151. system(str);
  4152. }
  4153. }
  4154. }
  4155. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4156. #if 1 // for TempStopTransaction
  4157. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4158. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4159. {
  4160. checkTempStopTransaction(gun_index);
  4161. }
  4162. #endif
  4163. }
  4164. }
  4165. }
  4166. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4167. {
  4168. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4169. {
  4170. tempIndex = ((gun_index==2) ? 1: 0);
  4171. }
  4172. else
  4173. {
  4174. tempIndex = gun_index;
  4175. }
  4176. for (int index = 0; index < GB_QUANTITY; index++)
  4177. {
  4178. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4179. {
  4180. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4181. {
  4182. // Sent unplug message for California pricing logic
  4183. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  4184. {
  4185. uint8_t ts[20];
  4186. getNowDatetime(ts);
  4187. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4188. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4189. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4190. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4191. }
  4192. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4193. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4194. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4195. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4196. {
  4197. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4198. if((access(filenmae,F_OK))!=-1)
  4199. {
  4200. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4201. sprintf(str,"rm -f %s",filenmae);
  4202. system(str);
  4203. }
  4204. }
  4205. }
  4206. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4207. #if 1 // for TempStopTransaction
  4208. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4209. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4210. {
  4211. checkTempStopTransaction(gun_index);
  4212. }
  4213. #endif
  4214. }
  4215. }
  4216. }
  4217. else if(gunType[gun_index] == GUN_TYPE_DO)
  4218. {
  4219. tempIndex = gun_index;
  4220. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4221. {
  4222. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4223. {
  4224. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4225. {
  4226. // Sent unplug message for California pricing logic
  4227. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  4228. {
  4229. uint8_t ts[20];
  4230. getNowDatetime(ts);
  4231. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4232. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4233. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4234. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4235. }
  4236. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4237. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4238. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4239. 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
  4240. {
  4241. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4242. if((access(filenmae,F_OK))!=-1)
  4243. {
  4244. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4245. sprintf(str,"rm -f %s",filenmae);
  4246. system(str);
  4247. }
  4248. }
  4249. }
  4250. 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);
  4251. #if 1 // for TempStopTransaction
  4252. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4253. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4254. {
  4255. checkTempStopTransaction(gun_index);
  4256. }
  4257. #endif
  4258. }
  4259. }
  4260. }
  4261. else
  4262. {
  4263. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4264. {
  4265. tempIndex = 2;
  4266. }
  4267. else
  4268. {
  4269. tempIndex = gun_index;
  4270. }
  4271. for (int index = 0; index < AC_QUANTITY; index++)
  4272. {
  4273. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4274. {
  4275. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4276. {
  4277. // Sent unplug message for California pricing logic
  4278. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4279. {
  4280. uint8_t ts[20];
  4281. getNowDatetime(ts);
  4282. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4283. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4284. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  4285. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  4286. }
  4287. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4288. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4289. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4290. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4291. {
  4292. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  4293. if((access(filenmae,F_OK))!=-1)
  4294. {
  4295. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4296. sprintf(str,"rm -f %s",filenmae);
  4297. system(str);
  4298. }
  4299. }
  4300. }
  4301. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4302. #if 1 // for TempStopTransaction
  4303. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4304. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4305. {
  4306. checkTempStopTransaction(gun_index);
  4307. }
  4308. #endif
  4309. }
  4310. }// END
  4311. }
  4312. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 1) &&
  4313. (
  4314. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1) ||
  4315. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") == 0) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData)))
  4316. )
  4317. )
  4318. {
  4319. if(SystemInitial > 0)
  4320. SystemInitial -= 1;
  4321. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  4322. sendStatusNotificationRequest(gun_index);
  4323. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4324. }
  4325. //==============================================
  4326. // TCCI reader status report
  4327. //==============================================
  4328. if(ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq == 1)
  4329. {
  4330. reportReaderStatus(gun_index);
  4331. ShmOCPP16DataPH->TcciCustomData.ReaderStatus[gun_index].ReportReaderStatusReq = 0;
  4332. }
  4333. //==============================================
  4334. // CSU Trigger Smart Charging Profile
  4335. //==============================================
  4336. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4337. {
  4338. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  4339. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4340. }
  4341. //==============================================
  4342. // Meter report
  4343. //==============================================
  4344. // Trigger MeterValue
  4345. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4346. {
  4347. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4348. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4349. }
  4350. // Clock-aligned Meter value
  4351. if(isWebsocketSendable && (reqClockAlignMeter[gun_index] == 1))
  4352. {
  4353. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4354. reqClockAlignMeter[gun_index] = 0;
  4355. }
  4356. // Sample period MeterValue
  4357. 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))))
  4358. {
  4359. //check Transaction active
  4360. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4361. {
  4362. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4363. {
  4364. tempIndex = ((gun_index==2) ? 1: 0);
  4365. }
  4366. else
  4367. {
  4368. tempIndex = gun_index;
  4369. }
  4370. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4371. {
  4372. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4373. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4374. {
  4375. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4376. {
  4377. reqSampleMeter[gun_index] = 1;
  4378. }
  4379. }
  4380. }// End for CHAdeMO
  4381. }
  4382. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4383. {
  4384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4385. {
  4386. tempIndex = ((gun_index==2) ? 1: 0);
  4387. }
  4388. else
  4389. {
  4390. tempIndex = gun_index;
  4391. }
  4392. for (int index = 0; index < CCS_QUANTITY; index++)
  4393. {
  4394. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4395. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4396. {
  4397. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4398. {
  4399. reqSampleMeter[gun_index] = 1;
  4400. }
  4401. }
  4402. } // End for CCS
  4403. }
  4404. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4405. {
  4406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4407. {
  4408. tempIndex = ((gun_index==2) ? 1: 0);
  4409. }
  4410. else
  4411. {
  4412. tempIndex = gun_index;
  4413. }
  4414. for (int index = 0; index < GB_QUANTITY; index++)
  4415. {
  4416. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4417. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4420. {
  4421. reqSampleMeter[gun_index] = 1;
  4422. }
  4423. }
  4424. }// End for GB
  4425. }
  4426. else if(gunType[gun_index] == GUN_TYPE_DO)
  4427. {
  4428. tempIndex = gun_index;
  4429. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4430. {
  4431. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4432. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4433. {
  4434. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4435. {
  4436. reqSampleMeter[gun_index] = 1;
  4437. }
  4438. }
  4439. }
  4440. }
  4441. else
  4442. {
  4443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4444. {
  4445. tempIndex = 2;
  4446. }
  4447. else
  4448. {
  4449. tempIndex = gun_index;
  4450. }
  4451. for (int index = 0; index < AC_QUANTITY; index++)
  4452. {
  4453. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4454. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4455. {
  4456. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4457. {
  4458. reqSampleMeter[gun_index] = 1;
  4459. }
  4460. }
  4461. }//End for AC
  4462. }
  4463. if(reqSampleMeter[gun_index] == 1)
  4464. {
  4465. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4466. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4467. //storeTempStopTransaction(gun_index);
  4468. reqSampleMeter[gun_index] = 0;
  4469. }
  4470. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4471. }
  4472. //==============================================
  4473. // Check Connector reserved
  4474. //==============================================
  4475. //===============================
  4476. // Check if Reserve is expired
  4477. //===============================
  4478. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  4479. {
  4480. double diff_t;
  4481. struct tm tp;
  4482. // current time
  4483. time_t t = time(NULL);
  4484. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  4485. tp.tm_isdst = -1;
  4486. time_t utc = mktime(&tp);
  4487. diff_t = difftime(utc, t);
  4488. if(diff_t <= 0)
  4489. {
  4490. DEBUG_INFO("reserve expired.\n");
  4491. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  4492. }
  4493. }//END OF Check if Reserve is expired
  4494. //==========================================
  4495. // csu trigger FirmwareStatusNotificationReq
  4496. //==========================================
  4497. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4498. {
  4499. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  4500. }
  4501. //==========================================
  4502. // csu trigger DiagnosticsStatusNotificationReq
  4503. //==========================================
  4504. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4505. {
  4506. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  4507. }
  4508. //==========================================
  4509. // csu trigger CancelReservationConf
  4510. //==========================================
  4511. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4512. {
  4513. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  4514. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4515. }
  4516. //==========================================
  4517. // csu trigger ChangeAvailabilityConf
  4518. //==========================================
  4519. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4520. {
  4521. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  4522. }
  4523. //==========================================
  4524. // csu trigger UnlockConnectorConf
  4525. //==========================================
  4526. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4527. {
  4528. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  4529. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4530. }
  4531. //==========================================
  4532. // csu trigger ReserveNowConf
  4533. //==========================================
  4534. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4535. {
  4536. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  4537. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4538. }
  4539. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  4540. {
  4541. sendSignCertificateRequest();
  4542. }
  4543. }
  4544. }
  4545. //==========================================
  4546. // send request routine
  4547. //==========================================
  4548. int sendAuthorizeRequest(int gun_index)
  4549. {
  4550. mtrace();
  4551. int result = FAIL;
  4552. char message[100]={0};
  4553. char guid[37];
  4554. char tempdata[65]={0};
  4555. DEBUG_INFO("sendAuthorizeRequest...\n");
  4556. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4557. //Local Authorize
  4558. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  4559. {
  4560. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4561. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4562. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4563. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4564. result = PASS;
  4565. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4566. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4567. authorizeRetryTimes = 0;
  4568. return result;
  4569. }
  4570. 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))||
  4571. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4572. {
  4573. // Query from cache
  4574. DEBUG_INFO("Authorize from cache.\n");
  4575. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4576. // Query from list
  4577. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4578. {
  4579. DEBUG_INFO("Authorize from list.\n");
  4580. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4581. }
  4582. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4583. {
  4584. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4585. {
  4586. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4587. }
  4588. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4589. {
  4590. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4591. }
  4592. if(!GetOcppConnStatus())
  4593. {
  4594. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4595. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4596. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4597. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4598. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4599. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4600. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4601. authorizeRetryTimes = 0;
  4602. return result;
  4603. }
  4604. }
  4605. else
  4606. {
  4607. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4608. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4609. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4610. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4611. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  4612. else
  4613. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4614. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  4615. result = PASS;
  4616. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4617. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4618. authorizeRetryTimes = 0;
  4619. return result;
  4620. }
  4621. }
  4622. //initialize struct Authorize
  4623. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  4624. //get data from shared memory
  4625. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4626. random_uuid(guid);
  4627. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  4628. LWS_Send(message);
  4629. sprintf(tempdata, "Authorize,%d", gun_index);
  4630. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4631. {
  4632. result = PASS;
  4633. DEBUG_INFO("Authorize mapItem pass\n");
  4634. }
  4635. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  4636. return result;
  4637. }
  4638. int sendBootNotificationRequest(void)
  4639. {
  4640. mtrace();
  4641. int result = FAIL;
  4642. char message[500]={0}, payload[700]={0};
  4643. char guid[37]={0};
  4644. char tempdata[65]={0};
  4645. // Fill BootNotification fields
  4646. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  4647. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4648. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4649. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4650. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4651. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4652. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4653. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4654. ShmOCPP16DataPH->ChargeBoxId
  4655. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4656. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4657. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4658. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  4659. ,ShmOCPP16DataPH->BootNotification.CpIccid
  4660. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  4661. random_uuid(guid);
  4662. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4663. LWS_Send(message);
  4664. sprintf(tempdata, "BootNotification,0");
  4665. 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*/)
  4666. {
  4667. result = PASS;
  4668. }
  4669. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4670. strcpy(queuedata,message);
  4671. return result;
  4672. }
  4673. int sendDataTransferRequest(int gun_index)
  4674. {
  4675. mtrace();
  4676. char message[1000]={0};
  4677. char guid[37]={0};
  4678. char tempdata[65]={0};
  4679. int result = FAIL;
  4680. random_uuid(guid);
  4681. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4682. MESSAGE_TYPE_CALL,
  4683. guid,
  4684. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  4685. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  4686. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  4687. LWS_Send(message);
  4688. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4689. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4690. {
  4691. result = PASS;
  4692. DEBUG_INFO("DataTransfer mapItem pass\n");
  4693. }
  4694. return result;
  4695. }
  4696. int sendDiagnosticsStatusNotificationRequest(char *status)
  4697. {
  4698. mtrace();
  4699. int result = FAIL;
  4700. char message[110]={0};
  4701. char guid[37]={0};
  4702. char tempdata[65]={0};
  4703. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4704. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4705. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4706. random_uuid(guid);
  4707. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4708. LWS_SendNow(message);
  4709. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4710. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4711. {
  4712. result = PASS;
  4713. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4714. }
  4715. //#ifdef SystemLogMessage
  4716. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4717. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4718. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4719. //#endif
  4720. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4721. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4722. //record status
  4723. if(strcmp(status,"Idle")==0)
  4724. {
  4725. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4726. }
  4727. else if(strcmp(status,"Uploaded")==0)
  4728. {
  4729. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4730. }
  4731. else if(strcmp(status,"UploadFailed")==0)
  4732. {
  4733. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4734. }
  4735. else if(strcmp(status,"Uploading")==0)
  4736. {
  4737. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4738. }
  4739. return result;
  4740. }
  4741. int sendFirmwareStatusNotificationRequest(char *status)
  4742. {
  4743. mtrace();
  4744. int result = FAIL;
  4745. char message[110]={0};
  4746. char guid[37]={0};
  4747. char tempdata[65]={0};
  4748. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4749. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4750. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4751. random_uuid(guid);
  4752. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4753. LWS_SendNow(message);
  4754. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4755. 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*/)
  4756. {
  4757. result = PASS;
  4758. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4759. }
  4760. //#ifdef SystemLogMessage
  4761. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4762. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4763. //#endif
  4764. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4765. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4766. //record status
  4767. if(strcmp(status,"Downloaded")==0)
  4768. {
  4769. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4770. }
  4771. else if(strcmp(status,"DownloadFailed")==0)
  4772. {
  4773. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4774. }
  4775. else if(strcmp(status,"Downloading")==0)
  4776. {
  4777. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4778. }
  4779. else if(strcmp(status,"Idle")==0)
  4780. {
  4781. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4782. }
  4783. else if(strcmp(status,"InstallationFailed")==0)
  4784. {
  4785. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4786. }
  4787. else if(strcmp(status,"Installing")==0)
  4788. {
  4789. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4790. }
  4791. else if(strcmp(status,"Installed")==0)
  4792. {
  4793. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4794. }
  4795. return result;
  4796. }
  4797. int sendHeartbeatRequest(int gun_index)
  4798. {
  4799. mtrace();
  4800. int result = FAIL;
  4801. char message[80]={0};
  4802. char guid[37]={0};
  4803. char tempdata[65]={0};
  4804. random_uuid(guid);
  4805. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4806. , MESSAGE_TYPE_CALL
  4807. , guid );
  4808. LWS_Send(message);
  4809. sprintf(tempdata, "Heartbeat,%d", 0);
  4810. 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*/)
  4811. {
  4812. result = PASS;
  4813. }
  4814. return result;
  4815. }
  4816. int sendStartTransactionRequest(int gun_index)
  4817. {
  4818. mtrace();
  4819. int result = FAIL;
  4820. char message[250]={0};
  4821. char guid[37]={0};
  4822. struct timeval tmnow;
  4823. struct tm *tm;
  4824. char buf[28];//, usec_buf[6];
  4825. char tempdata[65]={0};
  4826. int tempIndex = 0;
  4827. DEBUG_INFO("sendStartTransactionRequest...\n");
  4828. gettimeofday(&tmnow, NULL);
  4829. time_t t;
  4830. t = time(NULL);
  4831. /*UTC time and date*/
  4832. tm = gmtime(&t);
  4833. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4834. #if 0 // remove temporally
  4835. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4836. strcat(buf,".");
  4837. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4838. strcat(buf,usec_buf);
  4839. #endif
  4840. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4841. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4842. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4843. // clear StartTransaction Response
  4844. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4845. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4846. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4847. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4848. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4849. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4850. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4851. {
  4852. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4853. {
  4854. tempIndex = ((gun_index==2) ? 1: 0);
  4855. }
  4856. else
  4857. {
  4858. tempIndex = gun_index;
  4859. }
  4860. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4861. {
  4862. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4863. {
  4864. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4865. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4866. }
  4867. }
  4868. }
  4869. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4870. {
  4871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4872. {
  4873. tempIndex = ((gun_index==2) ? 1: 0);
  4874. }
  4875. else
  4876. {
  4877. tempIndex = gun_index;
  4878. }
  4879. for (int index = 0; index < CCS_QUANTITY; index++)
  4880. {
  4881. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4882. {
  4883. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4884. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4885. }
  4886. }
  4887. }
  4888. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4889. {
  4890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4891. {
  4892. tempIndex = ((gun_index==2) ? 1: 0);
  4893. }
  4894. else
  4895. {
  4896. tempIndex = gun_index;
  4897. }
  4898. for (int index = 0; index < GB_QUANTITY; index++)
  4899. {
  4900. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4901. {
  4902. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4903. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4904. }
  4905. }
  4906. }
  4907. else if(gunType[gun_index] == GUN_TYPE_DO)
  4908. {
  4909. tempIndex = gun_index;
  4910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4911. {
  4912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4913. {
  4914. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4915. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4916. }
  4917. }
  4918. }
  4919. else
  4920. {
  4921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4922. {
  4923. tempIndex = 2;
  4924. }
  4925. else
  4926. {
  4927. tempIndex = gun_index;
  4928. }
  4929. for (int index = 0; index < AC_QUANTITY; index++)
  4930. {
  4931. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4932. {
  4933. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4934. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4935. }
  4936. }
  4937. }
  4938. random_uuid(guid);
  4939. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4940. {
  4941. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4942. , gun_index +1
  4943. , MESSAGE_TYPE_CALL
  4944. , guid
  4945. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4946. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4947. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4948. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4949. }
  4950. else
  4951. {
  4952. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4953. , gun_index +1
  4954. , MESSAGE_TYPE_CALL
  4955. , guid
  4956. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4957. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4958. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4959. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4960. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4961. }
  4962. #if 1
  4963. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4964. 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*/)
  4965. {
  4966. result = PASS;
  4967. }
  4968. #endif
  4969. strcpy(queuedata, message);
  4970. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4971. OCPP_insert_transaction_msg(YES, queuedata);
  4972. return result;
  4973. }
  4974. int sendStatusNotificationRequest(int gun_index)
  4975. {
  4976. mtrace();
  4977. int result = FAIL;
  4978. char message[600]={0};
  4979. char guid[37];
  4980. int currentStatus = 0;
  4981. struct timeval tmnow;
  4982. struct tm *tm;
  4983. char buf[28];//, usec_buf[6];
  4984. char tempdata[65]={0};
  4985. int tempIndex = 0;
  4986. uint8_t isStateChanged = TRUE;
  4987. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4988. gettimeofday(&tmnow, NULL);
  4989. time_t t;
  4990. t = time(NULL);
  4991. /*UTC time and date*/
  4992. tm = gmtime(&t);
  4993. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4994. #if 0 // remove temporally
  4995. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4996. strcat(buf,".");
  4997. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4998. strcat(buf,usec_buf);
  4999. #endif
  5000. //printf("%s",buf);
  5001. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  5002. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  5003. // it's option
  5004. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  5005. /*
  5006. enum _SYSTEM_STATUS
  5007. {
  5008. S_BOOTING = 0,
  5009. S_IDLE, = 1
  5010. S_AUTHORIZING, =2
  5011. S_REASSIGN_CHECK, =3
  5012. S_REASSIGN, =4
  5013. S_PRECHARGE, =5
  5014. S_PREPARING_FOR_EV, =6
  5015. S_PREPARING_FOR_EVSE, =7
  5016. S_CHARGING, =8
  5017. S_TERMINATING, =9
  5018. S_COMPLETE, =10
  5019. S_ALARM, =11
  5020. S_FAULT =12
  5021. }
  5022. */
  5023. //check Transaction active
  5024. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5025. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5026. {
  5027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5028. {
  5029. tempIndex = ((gun_index==2) ? 1: 0);
  5030. }
  5031. else
  5032. {
  5033. tempIndex = gun_index;
  5034. }
  5035. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5036. {
  5037. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  5038. {
  5039. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  5040. {
  5041. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5042. {
  5043. currentStatus = Preparing; //OCPP Status: Preparing
  5044. }
  5045. else
  5046. {
  5047. currentStatus = Available; //OCPP Status: Available
  5048. }
  5049. }
  5050. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5051. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5052. ) //S_PRECHARGE
  5053. {
  5054. currentStatus = Preparing; //OCPP Status: Preparing
  5055. }
  5056. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5057. {
  5058. currentStatus = Charging; //OCPP Status: Charging
  5059. }
  5060. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5061. {
  5062. currentStatus = Finishing; //OCPP Status: Finishing
  5063. }
  5064. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5065. {
  5066. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5067. }
  5068. 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
  5069. {
  5070. currentStatus = Unavailable; //OCPP Status: Unavailable
  5071. }
  5072. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5073. {
  5074. currentStatus = Faulted; //OCPP Status: Faulted
  5075. }
  5076. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5077. {
  5078. currentStatus = Reserved; //OCPP Status: Reserved
  5079. }
  5080. } //end of the same index
  5081. }//end of for CHAdeMO_QUANTITY
  5082. }
  5083. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5084. {
  5085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5086. {
  5087. tempIndex = ((gun_index==2) ? 1: 0);
  5088. }
  5089. else
  5090. {
  5091. tempIndex = gun_index;
  5092. }
  5093. for (int index = 0; index < CCS_QUANTITY; index++)
  5094. {
  5095. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5096. {
  5097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5098. {
  5099. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  5100. {
  5101. currentStatus = Preparing; //OCPP Status: Preparing
  5102. }
  5103. else
  5104. {
  5105. currentStatus = Available; //OCPP Status: Available
  5106. }
  5107. }
  5108. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5109. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5110. ) //S_PRECHARGE
  5111. {
  5112. currentStatus = Preparing; //OCPP Status: Preparing
  5113. }
  5114. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5115. {
  5116. currentStatus = Charging; //OCPP Status: Charging
  5117. }
  5118. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5119. {
  5120. currentStatus = Finishing; //OCPP Status: Finishing
  5121. }
  5122. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  5123. {
  5124. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5125. }
  5126. 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
  5127. {
  5128. currentStatus = Unavailable; //OCPP Status : Unavailable
  5129. }
  5130. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5131. {
  5132. currentStatus = Faulted; //OCPP Status: Faulted
  5133. }
  5134. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5135. {
  5136. currentStatus = Reserved; //OCPP Status: Reserved
  5137. }
  5138. } //end of the same index
  5139. } // end of for CCS_QUANTITY
  5140. }
  5141. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5142. {
  5143. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5144. {
  5145. tempIndex = ((gun_index==2) ? 1: 0);
  5146. }
  5147. else
  5148. {
  5149. tempIndex = gun_index;
  5150. }
  5151. for (int index = 0; index < GB_QUANTITY; index++)
  5152. {
  5153. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5154. {
  5155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5156. {
  5157. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5158. {
  5159. currentStatus = Preparing; //OCPP Status: Preparing
  5160. }
  5161. else
  5162. {
  5163. currentStatus = Available; //OCPP Status: Available
  5164. }
  5165. }
  5166. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5167. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5168. ) //S_PRECHARGE
  5169. {
  5170. currentStatus = Preparing; //OCPP Status: Preparing
  5171. }
  5172. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5173. {
  5174. currentStatus = Charging; //OCPP Status: Charging
  5175. }
  5176. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5177. {
  5178. currentStatus = Finishing; //OCPP Status: Finishing
  5179. }
  5180. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5181. {
  5182. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5183. }
  5184. 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
  5185. {
  5186. currentStatus = Unavailable; //OCPP Status: Unavailable
  5187. }
  5188. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5189. {
  5190. currentStatus = Faulted; //OCPP Status: Faulted
  5191. }
  5192. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5193. {
  5194. currentStatus = Reserved; //OCPP Status: Reserved
  5195. }
  5196. } //end of the same index
  5197. } // end of for GB_QUANTITY
  5198. }
  5199. else if(gunType[gun_index] == GUN_TYPE_DO)
  5200. {
  5201. tempIndex = gun_index;
  5202. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5203. {
  5204. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5205. {
  5206. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5207. {
  5208. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5209. {
  5210. currentStatus = Preparing; //OCPP Status: Preparing
  5211. }
  5212. else
  5213. {
  5214. currentStatus = Available; //OCPP Status: Available
  5215. }
  5216. }
  5217. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5218. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5219. ) //S_PRECHARGE
  5220. {
  5221. currentStatus = Preparing; //OCPP Status: Preparing
  5222. }
  5223. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5224. {
  5225. currentStatus = Charging; //OCPP Status: Charging
  5226. }
  5227. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5228. {
  5229. currentStatus = Finishing; //OCPP Status: Finishing
  5230. }
  5231. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5232. {
  5233. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5234. }
  5235. 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
  5236. {
  5237. currentStatus = Unavailable; //OCPP Status: Unavailable
  5238. }
  5239. 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
  5240. {
  5241. currentStatus = Faulted; //OCPP Status: Faulted
  5242. }
  5243. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5244. {
  5245. currentStatus = Reserved; //OCPP Status: Reserved
  5246. }
  5247. } //end of the same index
  5248. }
  5249. }
  5250. else
  5251. {
  5252. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5253. {
  5254. tempIndex = 2;
  5255. }
  5256. else
  5257. {
  5258. tempIndex = gun_index;
  5259. }
  5260. for (int index = 0; index < AC_QUANTITY; index++)
  5261. {
  5262. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5263. {
  5264. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5265. {
  5266. 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))
  5267. {
  5268. currentStatus = Preparing; //OCPP Status: Preparing
  5269. }
  5270. else
  5271. {
  5272. currentStatus = Available; //OCPP Status: Available
  5273. }
  5274. }
  5275. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5276. {
  5277. currentStatus = Preparing; //OCPP Status: Preparing
  5278. }
  5279. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5280. {
  5281. currentStatus = Charging; //OCPP Status: Charging
  5282. }
  5283. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5284. {
  5285. currentStatus = Finishing; //OCPP Status: Finishing
  5286. }
  5287. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5288. {
  5289. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5290. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5291. else
  5292. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5293. }
  5294. 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
  5295. {
  5296. currentStatus = Unavailable; //OCPP Status: Unavailable
  5297. }
  5298. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5299. {
  5300. currentStatus = Faulted; //OCPP Status: Faulted
  5301. }
  5302. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5303. {
  5304. currentStatus = Reserved; //OCPP Status: Reserved
  5305. }
  5306. }//end of the same index
  5307. }//end of for AC_QUANTITY
  5308. }
  5309. //it's option
  5310. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5311. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  5312. (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "TRUE") != 0))
  5313. {
  5314. isStateChanged = FALSE;
  5315. }
  5316. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5317. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  5318. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5319. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5320. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  5321. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  5322. random_uuid(guid);
  5323. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5324. , MESSAGE_TYPE_CALL
  5325. , guid
  5326. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  5327. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  5328. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  5329. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  5330. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  5331. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  5332. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  5333. if((server_sign == TRUE) && isStateChanged)
  5334. {
  5335. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5336. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5337. LWS_Send(message);
  5338. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5339. 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*/)
  5340. {
  5341. //DEBUG_ERROR("statusNotification mapitem pass");
  5342. result = PASS;
  5343. }
  5344. }
  5345. else
  5346. {
  5347. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5348. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5349. result = PASS;
  5350. }
  5351. return result;
  5352. }
  5353. int sendStopTransactionRequest(int gun_index)
  5354. {
  5355. mtrace();
  5356. int result = FAIL;
  5357. //char message[1500]={0};
  5358. char guid[37]={0};
  5359. char tempdata[65]={0};
  5360. int tempIndex = 0;
  5361. char TempStopTransaction[256];
  5362. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  5363. //int idx_sample=0;
  5364. DEBUG_INFO("sendStopTransactionRequest \n");
  5365. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5366. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  5367. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5368. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5369. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5370. {
  5371. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5372. {
  5373. tempIndex = ((gun_index==2) ? 1: 0);
  5374. }
  5375. else
  5376. {
  5377. tempIndex = gun_index;
  5378. }
  5379. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5380. {
  5381. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5382. {
  5383. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5384. }
  5385. }// END OF CHAdeMO_QUANTITY
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5388. {
  5389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5390. {
  5391. tempIndex = ((gun_index==2) ? 1: 0);
  5392. }
  5393. else
  5394. {
  5395. tempIndex = gun_index;
  5396. }
  5397. for (int index = 0; index < CCS_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5400. {
  5401. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5402. }
  5403. }// END OF CCS_QUANTITY
  5404. }
  5405. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5408. {
  5409. tempIndex = ((gun_index==2) ? 1: 0);
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < GB_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5418. {
  5419. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5420. }
  5421. }// END OF GB_QUANTITY
  5422. }
  5423. else if(gunType[gun_index] == GUN_TYPE_DO)
  5424. {
  5425. tempIndex = gun_index;
  5426. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5429. {
  5430. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5431. }
  5432. }// END OF GB_QUANTITY
  5433. }
  5434. else
  5435. {
  5436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5437. {
  5438. tempIndex = 2;
  5439. }
  5440. else
  5441. {
  5442. tempIndex = gun_index;
  5443. }
  5444. for (int index = 0; index < AC_QUANTITY; index++)
  5445. {
  5446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5447. {
  5448. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5449. }
  5450. }// END OF AC_QUANTITY
  5451. }
  5452. //====================================== Stop Transaction Time =====================================================
  5453. struct timeval tmnow;
  5454. struct tm *tm;
  5455. char buf[28];//, usec_buf[6];
  5456. gettimeofday(&tmnow, NULL);
  5457. time_t t;
  5458. t = time(NULL);
  5459. /*UTC time and date*/
  5460. tm = gmtime(&t);
  5461. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5462. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  5463. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  5464. random_uuid(guid);
  5465. /***********************************transactionData******************************************************/
  5466. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5467. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5468. //=================================
  5469. // Transaction_Begin
  5470. //=================================
  5471. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5472. {
  5473. //============================================ Energy.Active.Import.Interval ================================
  5474. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5475. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5476. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5477. 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*/]);
  5478. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5479. 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))
  5480. {
  5481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5482. }
  5483. else
  5484. {
  5485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5486. }
  5487. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5488. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5489. }
  5490. //=================================
  5491. // Transaction_End
  5492. //=================================
  5493. // ================================= Current.Import L1 ===============================================
  5494. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5495. {
  5496. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5497. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5498. {
  5499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5500. {
  5501. tempIndex = ((gun_index==2) ? 1: 0);
  5502. }
  5503. else
  5504. {
  5505. tempIndex = gun_index;
  5506. }
  5507. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5508. {
  5509. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5510. {
  5511. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5512. }
  5513. }// End of for CHAdeMO_QUANTITY
  5514. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5515. }
  5516. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5517. {
  5518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5519. {
  5520. tempIndex = ((gun_index==2) ? 1: 0);
  5521. }
  5522. else
  5523. {
  5524. tempIndex = gun_index;
  5525. }
  5526. for (int index = 0; index < CCS_QUANTITY; index++)
  5527. {
  5528. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5529. {
  5530. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5531. }
  5532. }// End of for CCS_QUANTITY
  5533. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5534. }
  5535. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5536. {
  5537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5538. {
  5539. tempIndex = ((gun_index==2) ? 1: 0);
  5540. }
  5541. else
  5542. {
  5543. tempIndex = gun_index;
  5544. }
  5545. for (int index = 0; index < GB_QUANTITY; index++)
  5546. {
  5547. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5548. {
  5549. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5550. }
  5551. }// End of for GB_QUANTITY
  5552. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5553. }
  5554. else if(gunType[gun_index] == GUN_TYPE_DO)
  5555. {
  5556. tempIndex = gun_index;
  5557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5558. {
  5559. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5560. {
  5561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5562. }
  5563. }
  5564. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5565. }
  5566. else
  5567. {
  5568. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5569. {
  5570. tempIndex = 2;
  5571. }
  5572. else
  5573. {
  5574. tempIndex = gun_index;
  5575. }
  5576. for (int index = 0; index < AC_QUANTITY; index++)
  5577. {
  5578. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5579. {
  5580. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5581. }
  5582. }// End of for AC_QUANTITY
  5583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5584. }
  5585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5587. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5588. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5589. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5590. }
  5591. // ================================= Energy.Active.Import.Interval ==============================================
  5592. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5593. {
  5594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5595. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5596. {
  5597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5598. {
  5599. tempIndex = ((gun_index==2) ? 1: 0);
  5600. }
  5601. else
  5602. {
  5603. tempIndex = gun_index;
  5604. }
  5605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5606. {
  5607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5608. {
  5609. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5610. }
  5611. }// END OF CHAdeMO_QUANTITY
  5612. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5613. }
  5614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5615. {
  5616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5617. {
  5618. tempIndex = ((gun_index==2) ? 1: 0);
  5619. }
  5620. else
  5621. {
  5622. tempIndex = gun_index;
  5623. }
  5624. for (int index = 0; index < CCS_QUANTITY; index++)
  5625. {
  5626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5627. {
  5628. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5629. }
  5630. }// END OF CCS_QUANTITY
  5631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5632. }
  5633. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5634. {
  5635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5636. {
  5637. tempIndex = ((gun_index==2) ? 1: 0);
  5638. }
  5639. else
  5640. {
  5641. tempIndex = gun_index;
  5642. }
  5643. for (int index = 0; index < GB_QUANTITY; index++)
  5644. {
  5645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5646. {
  5647. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5648. }
  5649. }// END OF GB_QUANTITY
  5650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5651. }
  5652. else if(gunType[gun_index] == GUN_TYPE_DO)
  5653. {
  5654. tempIndex = gun_index;
  5655. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5656. {
  5657. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5658. {
  5659. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5660. }
  5661. }
  5662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5663. }
  5664. else
  5665. {
  5666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5667. {
  5668. tempIndex = 2;
  5669. }
  5670. else
  5671. {
  5672. tempIndex = gun_index;
  5673. }
  5674. for (int index = 0; index < AC_QUANTITY; index++)
  5675. {
  5676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5677. {
  5678. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5679. }
  5680. }// END OF AC_QUANTITY
  5681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5682. }
  5683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5688. }
  5689. //=================================== Power.Active.Import ==================================================
  5690. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5691. {
  5692. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5693. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5694. {
  5695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5696. {
  5697. tempIndex = ((gun_index==2) ? 1: 0);
  5698. }
  5699. else
  5700. {
  5701. tempIndex = gun_index;
  5702. }
  5703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5704. {
  5705. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5706. {
  5707. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5708. }
  5709. } // End for CHAdeMO_QUANTITY
  5710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5711. }
  5712. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5713. {
  5714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5715. {
  5716. tempIndex = ((gun_index==2) ? 1: 0);
  5717. }
  5718. else
  5719. {
  5720. tempIndex = gun_index;
  5721. }
  5722. for (int index = 0; index < CCS_QUANTITY; index++)
  5723. {
  5724. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5725. {
  5726. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5727. }
  5728. } // END for CCS_QUANTITY
  5729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5730. }
  5731. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5732. {
  5733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5734. {
  5735. tempIndex = ((gun_index==2) ? 1: 0);
  5736. }
  5737. else
  5738. {
  5739. tempIndex = gun_index;
  5740. }
  5741. for (int index = 0; index < GB_QUANTITY; index++)
  5742. {
  5743. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5744. {
  5745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5746. }
  5747. }// END for GB_QUANTITY
  5748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5749. }
  5750. else if(gunType[gun_index] == GUN_TYPE_DO)
  5751. {
  5752. tempIndex = gun_index;
  5753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5754. {
  5755. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5756. {
  5757. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5758. }
  5759. }
  5760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5761. }
  5762. else
  5763. {
  5764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5765. {
  5766. tempIndex = 2;
  5767. }
  5768. else
  5769. {
  5770. tempIndex = gun_index;
  5771. }
  5772. for (int index = 0; index < AC_QUANTITY; index++)
  5773. {
  5774. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5775. {
  5776. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5777. }
  5778. } // END for AC_QUANTITY
  5779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5780. }
  5781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5786. }
  5787. //============================ Voltage L1 ====================================
  5788. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5789. {
  5790. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5792. {
  5793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5794. {
  5795. tempIndex = ((gun_index==2) ? 1: 0);
  5796. }
  5797. else
  5798. {
  5799. tempIndex = gun_index;
  5800. }
  5801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5802. {
  5803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5804. {
  5805. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5806. }
  5807. } // END OF FOR CHAdeMO_QUANTITY
  5808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5809. }
  5810. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5811. {
  5812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5813. {
  5814. tempIndex = ((gun_index==2) ? 1: 0);
  5815. }
  5816. else
  5817. {
  5818. tempIndex = gun_index;
  5819. }
  5820. for (int index = 0; index < CCS_QUANTITY; index++)
  5821. {
  5822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5823. {
  5824. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5825. }
  5826. } // END OF FOR CCS_QUANTITY
  5827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5828. }
  5829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5830. {
  5831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5832. {
  5833. tempIndex = ((gun_index==2) ? 1: 0);
  5834. }
  5835. else
  5836. {
  5837. tempIndex = gun_index;
  5838. }
  5839. for (int index = 0; index < GB_QUANTITY; index++)
  5840. {
  5841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5842. {
  5843. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5844. }
  5845. } // END OF FOR GB_QUANTITY
  5846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5847. }
  5848. else if(gunType[gun_index] == GUN_TYPE_DO)
  5849. {
  5850. tempIndex = gun_index;
  5851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5852. {
  5853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5854. {
  5855. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5856. }
  5857. }
  5858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5859. }
  5860. else
  5861. {
  5862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5863. {
  5864. tempIndex = 2;
  5865. }
  5866. else
  5867. {
  5868. tempIndex = gun_index;
  5869. }
  5870. for (int index = 0; index < AC_QUANTITY; index++)
  5871. {
  5872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5873. {
  5874. 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
  5875. }
  5876. } // END OF FOR AC_QUANTITY
  5877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5878. }
  5879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5883. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5884. }
  5885. //====================== End SoC ================================
  5886. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5887. {
  5888. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5889. 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))
  5890. {
  5891. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5892. {
  5893. tempIndex = ((gun_index==2) ? 1: 0);
  5894. }
  5895. else
  5896. {
  5897. tempIndex = gun_index;
  5898. }
  5899. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5900. {
  5901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5902. {
  5903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5904. {
  5905. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5906. }
  5907. }
  5908. }
  5909. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5910. {
  5911. for (int index = 0; index < CCS_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5914. {
  5915. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5916. }
  5917. }
  5918. }
  5919. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5920. {
  5921. for (int index = 0; index < GB_QUANTITY; index++)
  5922. {
  5923. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5924. {
  5925. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5926. }
  5927. }
  5928. }
  5929. else if(gunType[gun_index] == GUN_TYPE_DO)
  5930. {
  5931. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5932. {
  5933. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5934. {
  5935. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5936. }
  5937. }
  5938. }
  5939. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5941. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5945. } // END FOR DC CASE
  5946. }
  5947. // ================================= Current.Import L2 ===============================================
  5948. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5949. {
  5950. // AC 3 phse L2 current
  5951. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5952. {
  5953. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5954. {
  5955. tempIndex = 2;
  5956. }
  5957. else
  5958. {
  5959. tempIndex = gun_index;
  5960. }
  5961. for (int index = 0; index < AC_QUANTITY; index++)
  5962. {
  5963. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5964. {
  5965. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5966. }
  5967. }// End of for AC_QUANTITY
  5968. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5969. }
  5970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5971. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5972. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5973. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5974. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5975. }
  5976. // ================================= Current.Import L3 ===============================================
  5977. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5978. {
  5979. // AC 3 phse L3 current
  5980. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5981. {
  5982. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5983. {
  5984. tempIndex = 2;
  5985. }
  5986. else
  5987. {
  5988. tempIndex = gun_index;
  5989. }
  5990. for (int index = 0; index < AC_QUANTITY; index++)
  5991. {
  5992. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5993. {
  5994. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5995. }
  5996. }// End of for AC_QUANTITY
  5997. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5998. }
  5999. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6000. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  6001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  6002. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  6003. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6004. }
  6005. //============================ Voltage L2 ====================================
  6006. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6007. {
  6008. // AC 3 phse L2 voltage
  6009. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6010. {
  6011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6012. {
  6013. tempIndex = 2;
  6014. }
  6015. else
  6016. {
  6017. tempIndex = gun_index;
  6018. }
  6019. for (int index = 0; index < AC_QUANTITY; index++)
  6020. {
  6021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6022. {
  6023. 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
  6024. }
  6025. } // END OF FOR AC_QUANTITY
  6026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  6027. }
  6028. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6029. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  6030. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  6031. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  6032. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6033. }
  6034. //============================ Voltage L3 ====================================
  6035. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  6036. {
  6037. // AC 3 phse L3 voltage
  6038. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6039. {
  6040. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6041. {
  6042. tempIndex = 2;
  6043. }
  6044. else
  6045. {
  6046. tempIndex = gun_index;
  6047. }
  6048. for (int index = 0; index < AC_QUANTITY; index++)
  6049. {
  6050. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6051. {
  6052. 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
  6053. }
  6054. } // END OF FOR AC_QUANTITY
  6055. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  6056. }
  6057. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  6058. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  6059. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  6060. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  6061. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6062. }
  6063. //====================== Start SoC ================================
  6064. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  6065. {
  6066. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6067. 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))
  6068. {
  6069. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6070. {
  6071. tempIndex = ((gun_index==2) ? 1: 0);
  6072. }
  6073. else
  6074. {
  6075. tempIndex = gun_index;
  6076. }
  6077. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6078. {
  6079. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6080. {
  6081. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6082. {
  6083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  6084. }
  6085. }
  6086. }
  6087. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6088. {
  6089. for (int index = 0; index < CCS_QUANTITY; index++)
  6090. {
  6091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6092. {
  6093. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  6094. }
  6095. }
  6096. }
  6097. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6098. {
  6099. for (int index = 0; index < GB_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6102. {
  6103. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  6104. }
  6105. }
  6106. }
  6107. else if(gunType[gun_index] == GUN_TYPE_DO)
  6108. {
  6109. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6112. {
  6113. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  6114. }
  6115. }
  6116. }
  6117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  6118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  6119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  6120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  6121. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  6122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  6123. } // END FOR DC CASE
  6124. }
  6125. //================================================ Message create ====================================================
  6126. json_object *StopTransaction = json_object_new_object();
  6127. json_object *transactionDatas = json_object_new_array();
  6128. json_object *sampledValues = json_object_new_array();
  6129. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  6130. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  6131. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  6132. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  6133. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  6134. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  6135. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  6136. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  6137. {
  6138. json_object *transactionData = json_object_new_object();
  6139. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  6140. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  6141. {
  6142. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  6143. {
  6144. json_object *sampledValue = json_object_new_object();
  6145. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  6146. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  6147. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  6148. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  6149. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  6150. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  6151. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  6152. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  6153. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  6154. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  6155. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  6156. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  6157. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  6158. json_object_array_add(sampledValues, sampledValue);
  6159. }
  6160. }
  6161. json_object_object_add(transactionData, "sampledValue", sampledValues);
  6162. json_object_array_add(transactionDatas, transactionData);
  6163. }
  6164. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  6165. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  6166. ,MESSAGE_TYPE_CALL
  6167. ,guid
  6168. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  6169. json_object_put(StopTransaction);
  6170. #if 1 // for TempStopTransaction
  6171. //Delete TempStopTransaction
  6172. if((access(TempStopTransaction,F_OK))!=-1)
  6173. {
  6174. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6175. }
  6176. #endif
  6177. #if 1
  6178. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6179. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6180. {
  6181. result = PASS;
  6182. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6183. }
  6184. #endif
  6185. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6186. OCPP_insert_transaction_msg(NO, queuedata);
  6187. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6188. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  6189. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  6190. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6191. {
  6192. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  6193. }
  6194. //for test
  6195. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6196. return result;
  6197. }
  6198. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6199. {
  6200. mtrace();
  6201. int result = FAIL;
  6202. char guid[37]={0};
  6203. char tempdata[65]={0};
  6204. int tempIndex = 0;
  6205. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6206. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6207. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6208. //set value
  6209. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6210. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6211. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  6212. -1);
  6213. random_uuid(guid);
  6214. //UTC Date time
  6215. struct timeval tmnow;
  6216. struct tm *tm;
  6217. char buf[28];//, usec_buf[6];
  6218. gettimeofday(&tmnow, NULL);
  6219. time_t t;
  6220. t = time(NULL);
  6221. /*UTC time and date*/
  6222. tm = gmtime(&t);
  6223. if(dataType == ReadingContext_Sample_Clock)
  6224. {
  6225. struct tm *tmTarget;
  6226. struct timeb tbTarget;
  6227. tbTarget.time = mktime(tm);
  6228. tbTarget.time -= (atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData));
  6229. tmTarget = gmtime(&tbTarget.time);
  6230. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  6231. }
  6232. else
  6233. {
  6234. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6235. }
  6236. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6237. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6238. //********************************(1)Current.Import L1************************************************/
  6239. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6240. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6241. (dataType == ReadingContext_Trigger))
  6242. {
  6243. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6244. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6245. {
  6246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6247. {
  6248. tempIndex = ((gun_index==2) ? 1: 0);
  6249. }
  6250. else
  6251. {
  6252. tempIndex = gun_index;
  6253. }
  6254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6255. {
  6256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6257. {
  6258. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6259. }
  6260. }
  6261. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6262. }
  6263. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6264. {
  6265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6266. {
  6267. tempIndex = ((gun_index==2) ? 1: 0);
  6268. }
  6269. else
  6270. {
  6271. tempIndex = gun_index;
  6272. }
  6273. for (int index = 0; index < CCS_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6276. {
  6277. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6278. }
  6279. }
  6280. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6281. }
  6282. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6283. {
  6284. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6285. {
  6286. tempIndex = ((gun_index==2) ? 1: 0);
  6287. }
  6288. else
  6289. {
  6290. tempIndex = gun_index;
  6291. }
  6292. for (int index = 0; index < GB_QUANTITY; index++)
  6293. {
  6294. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6295. {
  6296. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6297. }
  6298. }
  6299. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6300. }
  6301. else if(gunType[gun_index] == GUN_TYPE_DO)
  6302. {
  6303. tempIndex = gun_index;
  6304. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6305. {
  6306. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6307. {
  6308. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6309. }
  6310. }
  6311. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6312. }
  6313. else
  6314. {
  6315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6316. {
  6317. tempIndex = 2;
  6318. }
  6319. else
  6320. {
  6321. tempIndex = gun_index;
  6322. }
  6323. for (int index = 0; index < AC_QUANTITY; index++)
  6324. {
  6325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6326. {
  6327. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6328. }
  6329. }
  6330. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6331. }
  6332. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6333. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6334. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6335. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6336. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6337. }
  6338. //********************************(2)Energy.Active.Import.Register ************************************************/
  6339. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6340. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6341. (dataType == ReadingContext_Trigger))
  6342. {
  6343. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6344. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6345. {
  6346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6347. {
  6348. tempIndex = ((gun_index==2) ? 1: 0);
  6349. }
  6350. else
  6351. {
  6352. tempIndex = gun_index;
  6353. }
  6354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6355. {
  6356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6357. {
  6358. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6359. }
  6360. }
  6361. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6362. }
  6363. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6364. {
  6365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6366. {
  6367. tempIndex = ((gun_index==2) ? 1: 0);
  6368. }
  6369. else
  6370. {
  6371. tempIndex = gun_index;
  6372. }
  6373. for (int index = 0; index < CCS_QUANTITY; index++)
  6374. {
  6375. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6376. {
  6377. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6378. }
  6379. }
  6380. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6381. }
  6382. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6383. {
  6384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6385. {
  6386. tempIndex = ((gun_index==2) ? 1: 0);
  6387. }
  6388. else
  6389. {
  6390. tempIndex = gun_index;
  6391. }
  6392. for (int index = 0; index < GB_QUANTITY; index++)
  6393. {
  6394. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6395. {
  6396. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6397. }
  6398. }
  6399. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6400. }
  6401. else if(gunType[gun_index] == GUN_TYPE_DO)
  6402. {
  6403. tempIndex = gun_index;
  6404. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6405. {
  6406. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6407. {
  6408. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6409. }
  6410. }
  6411. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6412. }
  6413. else
  6414. {
  6415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6416. {
  6417. tempIndex = 2;
  6418. }
  6419. else
  6420. {
  6421. tempIndex = gun_index;
  6422. }
  6423. for (int index = 0; index < AC_QUANTITY; index++)
  6424. {
  6425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6426. {
  6427. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6428. }
  6429. }
  6430. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6431. }
  6432. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6433. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6434. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6435. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6436. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6437. }
  6438. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6439. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6440. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6441. (dataType == ReadingContext_Trigger))
  6442. {
  6443. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6444. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6445. {
  6446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6447. {
  6448. tempIndex = ((gun_index==2) ? 1: 0);
  6449. }
  6450. else
  6451. {
  6452. tempIndex = gun_index;
  6453. }
  6454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6455. {
  6456. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6457. {
  6458. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6459. }
  6460. } // END OF FOR CHAdeMO_QUANTITY
  6461. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6462. }
  6463. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6464. {
  6465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6466. {
  6467. tempIndex = ((gun_index==2) ? 1: 0);
  6468. }
  6469. else
  6470. {
  6471. tempIndex = gun_index;
  6472. }
  6473. for (int index = 0; index < CCS_QUANTITY; index++)
  6474. {
  6475. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6476. {
  6477. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6478. }
  6479. } // END OF CCS_QUANTITY
  6480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6481. }
  6482. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6483. {
  6484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6485. {
  6486. tempIndex = ((gun_index==2) ? 1: 0);
  6487. }
  6488. else
  6489. {
  6490. tempIndex = gun_index;
  6491. }
  6492. for (int index = 0; index < GB_QUANTITY; index++)
  6493. {
  6494. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6495. {
  6496. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6497. }
  6498. } // END OF GB_QUANTITY
  6499. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6500. }
  6501. else if(gunType[gun_index] == GUN_TYPE_DO)
  6502. {
  6503. tempIndex = gun_index;
  6504. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6505. {
  6506. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6507. {
  6508. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6509. }
  6510. }
  6511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6512. }
  6513. else
  6514. {
  6515. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6516. {
  6517. tempIndex = 2;
  6518. }
  6519. else
  6520. {
  6521. tempIndex = gun_index;
  6522. }
  6523. for (int index = 0; index < AC_QUANTITY; index++)
  6524. {
  6525. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6526. {
  6527. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6528. }
  6529. }
  6530. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6531. }
  6532. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6533. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6534. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6535. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6536. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6537. }
  6538. //********************************(4)Power.Active.Import************************************************/
  6539. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6540. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6541. (dataType == ReadingContext_Trigger))
  6542. {
  6543. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6544. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6545. {
  6546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6547. {
  6548. tempIndex = ((gun_index==2) ? 1: 0);
  6549. }
  6550. else
  6551. {
  6552. tempIndex = gun_index;
  6553. }
  6554. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6555. {
  6556. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6557. {
  6558. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6559. }
  6560. } // END OF FOR
  6561. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6562. }
  6563. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6564. {
  6565. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6566. {
  6567. tempIndex = ((gun_index==2) ? 1: 0);
  6568. }
  6569. else
  6570. {
  6571. tempIndex = gun_index;
  6572. }
  6573. for (int index = 0; index < CCS_QUANTITY; index++)
  6574. {
  6575. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6576. {
  6577. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6578. }
  6579. }
  6580. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6581. }
  6582. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6583. {
  6584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6585. {
  6586. tempIndex = ((gun_index==2) ? 1: 0);
  6587. }
  6588. else
  6589. {
  6590. tempIndex = gun_index;
  6591. }
  6592. for (int index = 0; index < GB_QUANTITY; index++)
  6593. {
  6594. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6595. {
  6596. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6597. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6598. }
  6599. }
  6600. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6601. }
  6602. else if(gunType[gun_index] == GUN_TYPE_DO)
  6603. {
  6604. tempIndex = gun_index;
  6605. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6606. {
  6607. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6608. {
  6609. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6610. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6611. }
  6612. }
  6613. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6614. }
  6615. else
  6616. {
  6617. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6618. {
  6619. tempIndex = 2;
  6620. }
  6621. else
  6622. {
  6623. tempIndex = gun_index;
  6624. }
  6625. for (int index = 0; index < AC_QUANTITY; index++)
  6626. {
  6627. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6628. {
  6629. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6630. }
  6631. }
  6632. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6633. }
  6634. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6635. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6636. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6637. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6638. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6639. }
  6640. //***********************************************(5)VOLTAGE L1******************************************************/
  6641. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6642. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6643. (dataType == ReadingContext_Trigger))
  6644. {
  6645. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6646. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6647. {
  6648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6649. {
  6650. tempIndex = ((gun_index==2) ? 1: 0);
  6651. }
  6652. else
  6653. {
  6654. tempIndex = gun_index;
  6655. }
  6656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6657. {
  6658. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6659. {
  6660. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6661. }
  6662. }
  6663. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6664. }
  6665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6666. {
  6667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6668. {
  6669. tempIndex = ((gun_index==2) ? 1: 0);
  6670. }
  6671. else
  6672. {
  6673. tempIndex = gun_index;
  6674. }
  6675. for (int index = 0; index < CCS_QUANTITY; index++)
  6676. {
  6677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6678. {
  6679. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6680. }
  6681. }
  6682. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6683. }
  6684. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6685. {
  6686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6687. {
  6688. tempIndex = ((gun_index==2) ? 1: 0);
  6689. }
  6690. else
  6691. {
  6692. tempIndex = gun_index;
  6693. }
  6694. for (int index = 0; index < GB_QUANTITY; index++)
  6695. {
  6696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6697. {
  6698. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6699. }
  6700. }
  6701. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6702. }
  6703. else if(gunType[gun_index] == GUN_TYPE_DO)
  6704. {
  6705. tempIndex = gun_index;
  6706. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6707. {
  6708. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6709. {
  6710. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6711. }
  6712. }
  6713. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6714. }
  6715. else
  6716. {
  6717. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6718. {
  6719. tempIndex = 2;
  6720. }
  6721. else
  6722. {
  6723. tempIndex = gun_index;
  6724. }
  6725. for (int index = 0; index < AC_QUANTITY; index++)
  6726. {
  6727. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6728. {
  6729. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6730. }
  6731. }
  6732. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6733. }
  6734. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6735. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6736. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6737. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6738. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6739. }
  6740. //***********************************************(6)SOC******************************************************/
  6741. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6742. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6743. (dataType == ReadingContext_Trigger))
  6744. {
  6745. 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))
  6746. {
  6747. //idx_sample=5;
  6748. //sampledValue = NULL;
  6749. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6750. {
  6751. tempIndex = ((gun_index==2) ? 1: 0);
  6752. }
  6753. else
  6754. {
  6755. tempIndex = gun_index;
  6756. }
  6757. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6758. {
  6759. //tempIndex = ((gun_index==2) ? 1: 0);
  6760. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6761. {
  6762. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6763. {
  6764. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6765. }
  6766. }
  6767. }
  6768. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6769. {
  6770. //tempIndex = ((gun_index==2) ? 1: 0);
  6771. for (int index = 0; index < CCS_QUANTITY; index++)
  6772. {
  6773. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6774. {
  6775. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6776. }
  6777. }
  6778. }
  6779. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6780. {
  6781. //tempIndex = ((gun_index==2) ? 1: 0);
  6782. for (int index = 0; index < GB_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6785. {
  6786. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6787. }
  6788. }
  6789. }
  6790. else if(gunType[gun_index] == GUN_TYPE_DO)
  6791. {
  6792. //tempIndex = ((gun_index==2) ? 1: 0);
  6793. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6794. {
  6795. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6796. {
  6797. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6798. }
  6799. }
  6800. }
  6801. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6802. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6803. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6804. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6805. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6806. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6807. }
  6808. }
  6809. //********************************(7)Current.Import L2************************************************/
  6810. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6811. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6812. (dataType == ReadingContext_Trigger))
  6813. {
  6814. // Only for AC 3 phase
  6815. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6816. {
  6817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6818. {
  6819. tempIndex = 2;
  6820. }
  6821. else
  6822. {
  6823. tempIndex = gun_index;
  6824. }
  6825. for (int index = 0; index < AC_QUANTITY; index++)
  6826. {
  6827. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6828. {
  6829. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6830. }
  6831. }
  6832. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6833. }
  6834. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6835. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6836. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6837. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6838. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6839. }
  6840. //********************************(8)Current.Import L3************************************************/
  6841. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6842. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6843. (dataType == ReadingContext_Trigger))
  6844. {
  6845. // Only for AC 3 phase
  6846. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6847. {
  6848. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6849. {
  6850. tempIndex = 2;
  6851. }
  6852. else
  6853. {
  6854. tempIndex = gun_index;
  6855. }
  6856. for (int index = 0; index < AC_QUANTITY; index++)
  6857. {
  6858. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6859. {
  6860. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6861. }
  6862. }
  6863. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6864. }
  6865. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6866. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6867. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6868. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6869. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6870. }
  6871. //***********************************************(9)VOLTAGE L2******************************************************/
  6872. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6873. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6874. (dataType == ReadingContext_Trigger))
  6875. {
  6876. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6877. {
  6878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6879. {
  6880. tempIndex = 2;
  6881. }
  6882. else
  6883. {
  6884. tempIndex = gun_index;
  6885. }
  6886. for (int index = 0; index < AC_QUANTITY; index++)
  6887. {
  6888. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6889. {
  6890. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6891. }
  6892. }
  6893. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6894. }
  6895. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6896. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6897. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6898. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6899. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6900. }
  6901. //***********************************************(10)VOLTAGE L3******************************************************/
  6902. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6903. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6904. (dataType == ReadingContext_Trigger))
  6905. {
  6906. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6907. {
  6908. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6909. {
  6910. tempIndex = 2;
  6911. }
  6912. else
  6913. {
  6914. tempIndex = gun_index;
  6915. }
  6916. for (int index = 0; index < AC_QUANTITY; index++)
  6917. {
  6918. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6919. {
  6920. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6921. }
  6922. }
  6923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6924. }
  6925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6926. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6927. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6928. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6929. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6930. }
  6931. //***********************************************(11)Current.Offered******************************************************/
  6932. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6933. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6934. (dataType == ReadingContext_Trigger))
  6935. {
  6936. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6937. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6938. {
  6939. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6940. {
  6941. tempIndex = ((gun_index==2) ? 1: 0);
  6942. }
  6943. else
  6944. {
  6945. tempIndex = gun_index;
  6946. }
  6947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6948. {
  6949. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6950. {
  6951. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6952. }
  6953. } // END OF FOR CHAdeMO_QUANTITY
  6954. }
  6955. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6956. {
  6957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6958. {
  6959. tempIndex = ((gun_index==2) ? 1: 0);
  6960. }
  6961. else
  6962. {
  6963. tempIndex = gun_index;
  6964. }
  6965. for (int index = 0; index < CCS_QUANTITY; index++)
  6966. {
  6967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6968. {
  6969. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6970. }
  6971. } // END OF CCS_QUANTITY
  6972. }
  6973. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6974. {
  6975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6976. {
  6977. tempIndex = ((gun_index==2) ? 1: 0);
  6978. }
  6979. else
  6980. {
  6981. tempIndex = gun_index;
  6982. }
  6983. for (int index = 0; index < GB_QUANTITY; index++)
  6984. {
  6985. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6986. {
  6987. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6988. }
  6989. } // END OF GB_QUANTITY
  6990. }
  6991. else if(gunType[gun_index] == GUN_TYPE_DO)
  6992. {
  6993. tempIndex = gun_index;
  6994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6995. {
  6996. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6997. {
  6998. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6999. }
  7000. }
  7001. }
  7002. else
  7003. {
  7004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7005. {
  7006. tempIndex = 2;
  7007. }
  7008. else
  7009. {
  7010. tempIndex = gun_index;
  7011. }
  7012. for (int index = 0; index < AC_QUANTITY; index++)
  7013. {
  7014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7015. {
  7016. uint16_t currentOffer;
  7017. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7018. {
  7019. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7020. }
  7021. else
  7022. {
  7023. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7024. }
  7025. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  7026. }
  7027. }
  7028. }
  7029. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  7030. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  7031. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  7032. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  7033. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  7034. }
  7035. //***********************************************(12)Power.Offered******************************************************/
  7036. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7037. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  7038. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  7039. {
  7040. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7041. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7042. {
  7043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7044. {
  7045. tempIndex = ((gun_index==2) ? 1: 0);
  7046. }
  7047. else
  7048. {
  7049. tempIndex = gun_index;
  7050. }
  7051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7052. {
  7053. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7054. {
  7055. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  7056. }
  7057. } // END OF FOR CHAdeMO_QUANTITY
  7058. }
  7059. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7060. {
  7061. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7062. {
  7063. tempIndex = ((gun_index==2) ? 1: 0);
  7064. }
  7065. else
  7066. {
  7067. tempIndex = gun_index;
  7068. }
  7069. for (int index = 0; index < CCS_QUANTITY; index++)
  7070. {
  7071. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7072. {
  7073. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  7074. }
  7075. } // END OF CCS_QUANTITY
  7076. }
  7077. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7078. {
  7079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7080. {
  7081. tempIndex = ((gun_index==2) ? 1: 0);
  7082. }
  7083. else
  7084. {
  7085. tempIndex = gun_index;
  7086. }
  7087. for (int index = 0; index < GB_QUANTITY; index++)
  7088. {
  7089. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7090. {
  7091. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  7092. }
  7093. } // END OF GB_QUANTITY
  7094. }
  7095. else if(gunType[gun_index] == GUN_TYPE_DO)
  7096. {
  7097. tempIndex = gun_index;
  7098. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7099. {
  7100. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7101. {
  7102. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint32_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  7103. }
  7104. }
  7105. }
  7106. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  7107. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  7108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  7109. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  7110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  7111. }
  7112. // Message create ====================================================================================================
  7113. if(TRUE)
  7114. {
  7115. json_object *MeterValueReq = json_object_new_object();
  7116. json_object *MeterValues = json_object_new_array();
  7117. json_object *sampledValues = json_object_new_array();
  7118. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  7119. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  7120. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  7121. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  7122. {
  7123. json_object *MeterValue = json_object_new_object();
  7124. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  7125. {
  7126. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  7127. {
  7128. json_object *sampledValue = json_object_new_object();
  7129. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  7130. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  7131. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  7132. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  7133. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  7134. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  7135. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  7136. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  7137. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  7138. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  7139. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  7140. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  7141. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  7142. json_object_array_add(sampledValues, sampledValue);
  7143. }
  7144. }
  7145. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  7146. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  7147. json_object_array_add(MeterValues, MeterValue);
  7148. }
  7149. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  7150. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7151. ,gun_index + 1
  7152. ,MESSAGE_TYPE_CALL
  7153. ,guid
  7154. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7155. json_object_put(MeterValueReq);
  7156. }
  7157. // Put request guid to hash map
  7158. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7159. 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*/)
  7160. {
  7161. result = PASS;
  7162. //DEBUG_INFO("MeterValues mapitem pass\n");
  7163. }
  7164. if((dataType != ReadingContext_Trigger) &&
  7165. (dataType != ReadingContext_Sample_Clock) &&
  7166. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  7167. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  7168. else
  7169. {
  7170. if(FirstHeartBeat)
  7171. LWS_Send(queuedata +2);
  7172. }
  7173. return result;
  7174. }
  7175. int sendLogStatusNotificationRequest(char *status)
  7176. {
  7177. mtrace();
  7178. int result = PASS;
  7179. char message[4096]={0};
  7180. char guid[37]={0};
  7181. char tempdata[128]={0};
  7182. json_object *LogStatusNotification = json_object_new_object();
  7183. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  7184. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  7185. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  7186. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  7187. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  7188. random_uuid(guid);
  7189. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7190. json_object_put(LogStatusNotification);
  7191. LWS_Send(message);
  7192. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7193. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7194. {
  7195. result = PASS;
  7196. }
  7197. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  7198. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  7199. return result;
  7200. }
  7201. int sendSecurityEventNotificationRequest()
  7202. {
  7203. mtrace();
  7204. int result = PASS;
  7205. char message[4096]={0};
  7206. char guid[37]={0};
  7207. char tempdata[128]={0};
  7208. json_object *SecurityEventNotification = json_object_new_object();
  7209. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7210. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  7211. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  7212. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  7213. random_uuid(guid);
  7214. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7215. json_object_put(SecurityEventNotification);
  7216. LWS_Send(message);
  7217. sprintf(tempdata, "SecurityEventNotification,0");
  7218. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7219. {
  7220. result = PASS;
  7221. }
  7222. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  7223. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  7224. return result;
  7225. }
  7226. int sendSignCertificateRequest()
  7227. {
  7228. mtrace();
  7229. int result = PASS;
  7230. char message[4096]={0};
  7231. char guid[37]={0};
  7232. char tempdata[128]={0};
  7233. json_object *SignCertificate = json_object_new_object();
  7234. DEBUG_INFO("sendSignCertificateRequest...\n");
  7235. // Read csr file content
  7236. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  7237. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  7238. char *line = NULL;
  7239. size_t len = 0;
  7240. while(getline(&line, &len, fp) != -1)
  7241. {
  7242. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7243. {
  7244. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  7245. }
  7246. }
  7247. fclose(fp);
  7248. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  7249. random_uuid(guid);
  7250. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7251. json_object_put(SignCertificate);
  7252. LWS_Send(message);
  7253. sprintf(tempdata, "SignCertificate,0");
  7254. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7255. {
  7256. result = PASS;
  7257. }
  7258. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  7259. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  7260. return result;
  7261. }
  7262. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7263. {
  7264. mtrace();
  7265. int result = PASS;
  7266. char message[110]={0};
  7267. char guid[37]={0};
  7268. char tempdata[65]={0};
  7269. json_object *FirmwareStatusNotification = json_object_new_object();
  7270. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7271. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7272. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  7273. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  7274. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  7275. random_uuid(guid);
  7276. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7277. json_object_put(FirmwareStatusNotification);
  7278. LWS_Send(message);
  7279. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7280. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7281. {
  7282. result = PASS;
  7283. }
  7284. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7285. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7286. return result;
  7287. }
  7288. //==========================================
  7289. // send confirm routine
  7290. //==========================================
  7291. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7292. {
  7293. mtrace();
  7294. int result = FAIL;
  7295. char message[100]={0};
  7296. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7297. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7298. LWS_Send(message);
  7299. result = TRUE;
  7300. return result;
  7301. }
  7302. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7303. {
  7304. mtrace();
  7305. int result = FAIL;
  7306. char message[100]={0};
  7307. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7308. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7309. LWS_Send(message);
  7310. result = TRUE;
  7311. return result;
  7312. }
  7313. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7314. {
  7315. mtrace();
  7316. int result = FAIL;
  7317. char message[100]={0};
  7318. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7319. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7320. LWS_Send(message);
  7321. result = TRUE;
  7322. return result;
  7323. }
  7324. int sendClearCacheConfirmation(char *uuid,char *payload)
  7325. {
  7326. mtrace();
  7327. int result = FAIL;
  7328. char message[500]={0};
  7329. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7330. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7331. LWS_Send(message);
  7332. return result;
  7333. }
  7334. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7335. {
  7336. mtrace();
  7337. int result = FAIL;
  7338. char message[500]={0};
  7339. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7340. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7341. LWS_Send(message);
  7342. return result;
  7343. }
  7344. int sendDataTransferConfirmation(char *uuid,char *payload)
  7345. {
  7346. mtrace();
  7347. char statusStr[20]={0};
  7348. char dataStr[10]={0};
  7349. char sstr[20]={0};
  7350. int c = 0;
  7351. char *loc;
  7352. int result = FAIL;
  7353. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7354. /**********************status**************************/
  7355. loc = strstr(payload, "status");
  7356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7357. c = 0;
  7358. while (loc[3+strlen("status")+c] != '\"')
  7359. {
  7360. sstr[c] = loc[3+strlen("status")+c];
  7361. c++;
  7362. }
  7363. sstr[c] = '\0';
  7364. strcpy(statusStr, sstr);
  7365. /**********************data**************************/
  7366. loc = strstr(payload, "data");
  7367. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7368. c = 0;
  7369. while (loc[3+strlen("data")+c] != '\"')
  7370. {
  7371. sstr[c] = loc[3+strlen("data")+c];
  7372. c++;
  7373. }
  7374. sstr[c] = '\0';
  7375. strcpy(dataStr, sstr);
  7376. return result;
  7377. }
  7378. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7379. {
  7380. mtrace();
  7381. int result = FAIL;
  7382. char message[1000]={0};
  7383. int CompositeScheduleIndex = 0;
  7384. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7385. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7386. if(nPeriod == 0)
  7387. {
  7388. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7389. {
  7390. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7391. ,MESSAGE_TYPE_CALLRESULT
  7392. ,uuid
  7393. ,payload
  7394. ,connectorIdInt);
  7395. }
  7396. else
  7397. {
  7398. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7399. ,MESSAGE_TYPE_CALLRESULT
  7400. ,uuid
  7401. ,payload
  7402. ,connectorIdInt
  7403. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7404. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7405. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7406. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7407. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7408. }
  7409. }
  7410. else
  7411. {
  7412. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7413. ,MESSAGE_TYPE_CALLRESULT
  7414. ,uuid
  7415. ,payload
  7416. ,connectorIdInt
  7417. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7418. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7419. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7420. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7421. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7422. {
  7423. if (idx_sample == 0)
  7424. {
  7425. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7426. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7427. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7428. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7429. }
  7430. else
  7431. {
  7432. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7433. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7434. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7435. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7436. }
  7437. }
  7438. sprintf(message + strlen(message), "]}}]");
  7439. }
  7440. LWS_Send(message);
  7441. result = TRUE;
  7442. return result;
  7443. }
  7444. int sendGetConfigurationConfirmation(char *uuid)
  7445. {
  7446. mtrace();
  7447. int result = FAIL;
  7448. int MaxKeySupported = 0;
  7449. int sentConfigurationNumber= 0;
  7450. int sentunConfigurationNumber= 0;
  7451. char message[1024*10]={0};
  7452. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7453. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7454. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  7455. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7456. ,MESSAGE_TYPE_CALLRESULT
  7457. ,uuid );
  7458. //configuration key
  7459. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7460. {
  7461. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7462. {
  7463. if (sentConfigurationNumber == 0)
  7464. {
  7465. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7466. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7467. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7468. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7469. }
  7470. else
  7471. {
  7472. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7473. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7474. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7475. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7476. }
  7477. sentConfigurationNumber = sentConfigurationNumber + 1;
  7478. }
  7479. }
  7480. sprintf(message + strlen(message), "]");
  7481. if(UnknownKeynum != 0)
  7482. {
  7483. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7484. //unkown key
  7485. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7486. {
  7487. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7488. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7489. if(sentunConfigurationNumber == 0)
  7490. {
  7491. sprintf(message + strlen(message), "\"%s\""
  7492. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7493. }
  7494. else
  7495. {
  7496. sprintf(message + strlen(message), ",\"%s\""
  7497. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7498. }
  7499. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7500. }
  7501. sprintf(message + strlen(message), "]");
  7502. }
  7503. sprintf(message + strlen(message), "}]");
  7504. LWS_Send(message);
  7505. return result;
  7506. }
  7507. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7508. {
  7509. mtrace();
  7510. int result = FAIL;
  7511. char message[400]={0};
  7512. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7513. if(strcmp(payload,"")==0)
  7514. {
  7515. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7516. }
  7517. else
  7518. {
  7519. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7520. }
  7521. LWS_Send(message);
  7522. result = TRUE;
  7523. return result;
  7524. }
  7525. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7526. {
  7527. mtrace();
  7528. int result = FAIL;
  7529. char message[80]={0};
  7530. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7531. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  7532. LWS_Send(message);
  7533. result = TRUE;
  7534. return result;
  7535. }
  7536. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7537. {
  7538. mtrace();
  7539. int result = FAIL;
  7540. char message[80]={0};
  7541. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7542. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7543. LWS_Send(message);
  7544. result = TRUE;
  7545. return result;
  7546. }
  7547. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7548. {
  7549. mtrace();
  7550. int result = FAIL;
  7551. char message[80]={0};
  7552. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7553. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7554. LWS_Send(message);
  7555. result = TRUE;
  7556. return result;
  7557. }
  7558. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7559. {
  7560. mtrace();
  7561. int result = FAIL;
  7562. char message[80]={0};
  7563. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7564. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7565. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7566. LWS_Send(message);
  7567. result = TRUE;
  7568. return result;
  7569. }
  7570. int sendResetConfirmation(char *uuid,char *payload)
  7571. {
  7572. mtrace();
  7573. int result = FAIL;
  7574. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7575. char message[80]={0};
  7576. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  7577. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7578. LWS_Send(message);
  7579. result = TRUE;
  7580. return result;
  7581. }
  7582. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7583. {
  7584. mtrace();
  7585. int result = FAIL;
  7586. char message[500]={0};
  7587. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7588. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7589. LWS_Send(message);
  7590. result = TRUE;
  7591. return result;
  7592. }
  7593. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7594. {
  7595. mtrace();
  7596. int result = FAIL;
  7597. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7598. char message[80]={0};
  7599. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7600. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7601. LWS_Send(message);
  7602. result = TRUE;
  7603. return result;
  7604. }
  7605. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7606. {
  7607. mtrace();
  7608. int result = FAIL;
  7609. char message[80]={0};
  7610. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7611. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7612. LWS_Send(message);
  7613. result = TRUE;
  7614. return result;
  7615. }
  7616. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7617. {
  7618. mtrace();
  7619. int result = FAIL;
  7620. char message[80]={0};
  7621. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7622. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7623. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7624. LWS_Send(message);
  7625. result = TRUE;
  7626. return result;
  7627. }
  7628. int sendUpdateFirmwareConfirmation(char *uuid)
  7629. {
  7630. mtrace();
  7631. int result = FAIL;
  7632. char message[60]={0};
  7633. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7634. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7635. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7636. LWS_Send(message);
  7637. result = TRUE;
  7638. return result;
  7639. }
  7640. int sendCertificateSignedConfirmation(char *uuid)
  7641. {
  7642. mtrace();
  7643. int result = PASS;
  7644. char message[4096]={0};
  7645. json_object *CertificateSigned = json_object_new_object();
  7646. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7647. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  7648. sprintf(message,"[%d,\"%s\",%s]"
  7649. ,MESSAGE_TYPE_CALLRESULT
  7650. ,uuid
  7651. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7652. json_object_put(CertificateSigned);
  7653. LWS_Send(message);
  7654. return result;
  7655. }
  7656. int sendDeleteCertificateConfirmation(char *uuid)
  7657. {
  7658. mtrace();
  7659. int result = PASS;
  7660. char message[4096]={0};
  7661. json_object *DeleteCertificate = json_object_new_object();
  7662. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7663. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  7664. sprintf(message,"[%d,\"%s\",%s]"
  7665. ,MESSAGE_TYPE_CALLRESULT
  7666. ,uuid
  7667. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7668. json_object_put(DeleteCertificate);
  7669. LWS_Send(message);
  7670. return result;
  7671. }
  7672. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7673. {
  7674. mtrace();
  7675. int result = PASS;
  7676. char message[4096]={0};
  7677. json_object *ExtendedTriggerMessage = json_object_new_object();
  7678. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7679. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  7680. sprintf(message,"[%d,\"%s\",%s]"
  7681. ,MESSAGE_TYPE_CALLRESULT
  7682. ,uuid
  7683. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7684. json_object_put(ExtendedTriggerMessage);
  7685. LWS_Send(message);
  7686. return result;
  7687. }
  7688. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7689. {
  7690. mtrace();
  7691. int result = PASS;
  7692. char message[4096]={0};
  7693. json_object *GetInstalledCertificateIds = json_object_new_object();
  7694. json_object *certificateHashDataDatas = json_object_new_array();
  7695. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7696. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  7697. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7698. {
  7699. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7700. {
  7701. json_object *certificateHashData = json_object_new_object();
  7702. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7703. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7704. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7705. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7706. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7707. }
  7708. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7709. }
  7710. else
  7711. {
  7712. json_object_put(certificateHashDataDatas);
  7713. }
  7714. sprintf(message,"[%d,\"%s\",%s]"
  7715. ,MESSAGE_TYPE_CALLRESULT
  7716. ,uuid
  7717. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7718. json_object_put(GetInstalledCertificateIds);
  7719. LWS_Send(message);
  7720. return result;
  7721. }
  7722. int sendGetLogConfirmation(char *uuid)
  7723. {
  7724. mtrace();
  7725. int result = PASS;
  7726. char message[4096]={0};
  7727. json_object *GetLog = json_object_new_object();
  7728. DEBUG_INFO("sendGetLogConfirmation...\n");
  7729. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  7730. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  7731. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  7732. sprintf(message,"[%d,\"%s\",%s]"
  7733. ,MESSAGE_TYPE_CALLRESULT
  7734. ,uuid
  7735. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7736. json_object_put(GetLog);
  7737. LWS_Send(message);
  7738. return result;
  7739. }
  7740. int sendInstallCertificateConfirmation(char *uuid)
  7741. {
  7742. mtrace();
  7743. int result = PASS;
  7744. char message[4096]={0};
  7745. json_object *InstallCertificate = json_object_new_object();
  7746. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7747. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  7748. sprintf(message,"[%d,\"%s\",%s]"
  7749. ,MESSAGE_TYPE_CALLRESULT
  7750. ,uuid
  7751. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7752. json_object_put(InstallCertificate);
  7753. LWS_Send(message);
  7754. return result;
  7755. }
  7756. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7757. {
  7758. mtrace();
  7759. int result = PASS;
  7760. char message[4096]={0};
  7761. json_object *SignedUpdateFirmware = json_object_new_object();
  7762. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7763. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7764. sprintf(message,"[%d,\"%s\",%s]"
  7765. ,MESSAGE_TYPE_CALLRESULT
  7766. ,uuid
  7767. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7768. json_object_put(SignedUpdateFirmware);
  7769. LWS_Send(message);
  7770. return result;
  7771. }
  7772. int sendUnknownConfirmation(char *uuid)
  7773. {
  7774. mtrace();
  7775. int result = PASS;
  7776. char message[256]={0};
  7777. DEBUG_INFO("sendUnknownConfirmation...\n");
  7778. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7779. LWS_Send(message);
  7780. return result;
  7781. }
  7782. //==========================================
  7783. // Handle server request routine Start
  7784. //==========================================
  7785. int handleCancelReservationRequest(char *uuid, char *payload)
  7786. {
  7787. mtrace();
  7788. int result = FAIL;
  7789. int gunNO = 0;
  7790. int reservationIdInt = -1;
  7791. char comfirmstr[20];
  7792. DEBUG_INFO("handleCancelReservationRequest...\n");
  7793. json_object *CancelReservation;
  7794. CancelReservation = json_tokener_parse(payload);
  7795. if(!is_error(CancelReservation))
  7796. {
  7797. // Required data
  7798. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7799. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7800. }
  7801. json_object_put(CancelReservation);
  7802. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7803. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7804. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7805. if(reservationIdInt != -1)
  7806. {
  7807. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7808. //check Transaction active
  7809. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7810. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7811. {
  7812. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7813. {
  7814. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7815. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7816. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7817. {
  7818. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7819. }
  7820. else
  7821. {
  7822. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7823. }
  7824. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7825. goto end;
  7826. }
  7827. }
  7828. for (int index = 0; index < CCS_QUANTITY; index++)
  7829. {
  7830. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7831. {
  7832. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7833. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7834. if(gunType[2] == GUN_TYPE_CCS)
  7835. {
  7836. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7837. }
  7838. else
  7839. {
  7840. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7841. }
  7842. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7843. goto end;
  7844. }
  7845. }
  7846. for (int index = 0; index < GB_QUANTITY; index++)
  7847. {
  7848. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7849. {
  7850. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7851. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7852. if(gunType[2] == GUN_TYPE_GBT)
  7853. {
  7854. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7855. }
  7856. else
  7857. {
  7858. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7859. }
  7860. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7861. goto end;
  7862. }
  7863. }
  7864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7865. {
  7866. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7867. {
  7868. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7869. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7870. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7871. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7872. goto end;
  7873. }
  7874. }
  7875. for (int index = 0; index < AC_QUANTITY; index++)
  7876. {
  7877. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7878. {
  7879. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7880. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7882. {
  7883. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7884. }
  7885. else
  7886. {
  7887. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7888. }
  7889. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7890. goto end;
  7891. }
  7892. }
  7893. }
  7894. //The reservationId does NOT match the reservationId
  7895. sendCancelReservationConfirmation(uuid, comfirmstr);
  7896. end:
  7897. // Fill in ocpp packet uuid
  7898. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7899. return result;
  7900. }
  7901. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7902. {
  7903. mtrace();
  7904. int result = FAIL;
  7905. int gunIndex = -1;
  7906. char typeStr[16]={0};
  7907. char comfirmstr[20];
  7908. int specificId = FALSE;
  7909. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7910. json_object *ChangeAvailability;
  7911. ChangeAvailability = json_tokener_parse(payload);
  7912. if(!is_error(ChangeAvailability))
  7913. {
  7914. // Required data
  7915. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7916. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7917. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7918. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7919. }
  7920. json_object_put(ChangeAvailability);
  7921. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7922. {
  7923. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7924. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7925. }
  7926. else if(gunIndex == 0)
  7927. {
  7928. for(int i=0; i < gunTotalNumber; i++)
  7929. {
  7930. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7931. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7932. }
  7933. }
  7934. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7935. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7936. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7937. {
  7938. specificId = TRUE;
  7939. }
  7940. if(specificId == FALSE)
  7941. goto end;
  7942. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7943. {
  7944. //----------------------gunIndex is 0 ------------------------------------------------//
  7945. if(gunIndex == 0)
  7946. {
  7947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7948. {
  7949. for(int i=0; i < gunTotalNumber; i++)
  7950. {
  7951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7952. {
  7953. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7954. {
  7955. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7956. {
  7957. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7958. goto end;
  7959. }
  7960. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7961. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7962. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7963. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7964. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7965. {
  7966. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7967. goto end;
  7968. }
  7969. }
  7970. }//END FOR CHAdeMO_QUANTITY
  7971. for (int index = 0; index < CCS_QUANTITY; index++)
  7972. {
  7973. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7974. {
  7975. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7976. {
  7977. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7978. goto end;
  7979. }
  7980. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7981. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7982. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7983. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7984. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7985. {
  7986. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7987. goto end;
  7988. }
  7989. }
  7990. }//END FOR CCS_QUANTITY
  7991. for (int index = 0; index < GB_QUANTITY; index++)
  7992. {
  7993. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7994. {
  7995. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7996. {
  7997. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7998. goto end;
  7999. }
  8000. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8001. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8002. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8003. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8004. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8005. {
  8006. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8007. goto end;
  8008. }
  8009. }
  8010. }// END FOR GB_QUANTITY
  8011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8012. {
  8013. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  8014. {
  8015. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8016. {
  8017. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8018. goto end;
  8019. }
  8020. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8021. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8022. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8023. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8024. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8025. {
  8026. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8027. goto end;
  8028. }
  8029. }
  8030. }// END FOR GENERAL_GUN_QUANTITY
  8031. for (int index = 0; index < AC_QUANTITY; index++)
  8032. {
  8033. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  8034. {
  8035. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8036. {
  8037. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8038. goto end;
  8039. }
  8040. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8041. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8042. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8043. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8044. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8045. {
  8046. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8047. goto end;
  8048. }
  8049. }
  8050. }//END FOR AC_QUANTITY
  8051. }// END FOR gunTotalNumber
  8052. }
  8053. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8054. {
  8055. for(int i=0; i < gunTotalNumber; i++)
  8056. {
  8057. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  8058. {
  8059. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8060. goto end;
  8061. }
  8062. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8063. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  8064. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  8065. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  8066. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8067. {
  8068. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8069. goto end;
  8070. }
  8071. }
  8072. }
  8073. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8074. goto end;
  8075. }
  8076. //----------------------gunIndex is not 0 ------------------------------------------------//
  8077. //check Transaction active
  8078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8079. {
  8080. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  8081. {
  8082. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  8083. {
  8084. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8085. goto end;
  8086. }
  8087. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8088. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8089. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8090. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8091. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8092. {
  8093. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8094. goto end;
  8095. }
  8096. else
  8097. {
  8098. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  8099. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8100. goto end;
  8101. }
  8102. }
  8103. }//END FOR CHAdeMO_QUANTITY
  8104. for (int index = 0; index < CCS_QUANTITY; index++)
  8105. {
  8106. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  8107. {
  8108. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  8109. {
  8110. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8111. goto end;
  8112. }
  8113. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8114. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8115. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8116. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8117. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8118. {
  8119. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8120. goto end;
  8121. }
  8122. else
  8123. {
  8124. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  8125. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8126. goto end;
  8127. }
  8128. }
  8129. }//END FOR CCS_QUANTITY
  8130. for (int index = 0; index < GB_QUANTITY; index++)
  8131. {
  8132. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  8133. {
  8134. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8135. {
  8136. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8137. goto end;
  8138. }
  8139. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8140. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8141. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8142. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8143. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8144. {
  8145. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8146. goto end;
  8147. }
  8148. else
  8149. {
  8150. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  8151. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8152. goto end;
  8153. }
  8154. }
  8155. }// END FOR GB_QUANTITY
  8156. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8157. {
  8158. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  8159. {
  8160. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8161. {
  8162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8163. goto end;
  8164. }
  8165. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  8166. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  8167. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  8168. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  8169. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8170. {
  8171. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8172. goto end;
  8173. }
  8174. else
  8175. {
  8176. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  8177. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8178. goto end;
  8179. }
  8180. }
  8181. }// END FOR GENERAL_GUN_QUANTITY
  8182. for (int index = 0; index < AC_QUANTITY; index++)
  8183. {
  8184. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  8185. {
  8186. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8187. {
  8188. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8189. goto end;
  8190. }
  8191. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8192. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8193. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8194. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8195. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8196. {
  8197. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8198. goto end;
  8199. }
  8200. else
  8201. {
  8202. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8203. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8204. goto end;
  8205. }
  8206. }
  8207. }//END FOR AC_QUANTITY
  8208. }//END FOR AvailabilityTypeStr[Inoperative]
  8209. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8210. {
  8211. //----------------------gunIndex is 0 ------------------------------------------------//
  8212. if(gunIndex == 0)
  8213. {
  8214. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8215. {
  8216. for(int i=0; i < gunTotalNumber; i++)
  8217. {
  8218. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8219. {
  8220. 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
  8221. {
  8222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8223. goto end;
  8224. }
  8225. }//END FOR CHAdeMO_QUANTITY
  8226. for (int index = 0; index < CCS_QUANTITY; index++)
  8227. {
  8228. 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
  8229. {
  8230. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8231. goto end;
  8232. }
  8233. }//END FOR CCS_QUANTITY
  8234. for (int index = 0; index < GB_QUANTITY; index++)
  8235. {
  8236. 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
  8237. {
  8238. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8239. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8240. goto end;
  8241. }
  8242. }// END FOR GB_QUANTITY
  8243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8244. {
  8245. 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
  8246. {
  8247. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8248. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8249. goto end;
  8250. }
  8251. }// END FOR GENERAL_GUN_QUANTITY
  8252. for (int index = 0; index < AC_QUANTITY; index++)
  8253. {
  8254. 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
  8255. {
  8256. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8257. goto end;
  8258. }
  8259. }//END FOR CHAdeMO_QUANTITY
  8260. }// END FOR gunTotalNumber
  8261. }
  8262. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8263. {
  8264. for(int i=0; i < gunTotalNumber; i++)
  8265. {
  8266. for (int index = 0; index < AC_QUANTITY; index++)
  8267. {
  8268. 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
  8269. {
  8270. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8271. goto end;
  8272. }
  8273. }//END FOR CHAdeMO_QUANTITY
  8274. } // END FOR gunTotalNumber
  8275. }
  8276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8277. goto end;
  8278. }
  8279. //----------------------gunIndex is not 0 ------------------------------------------------//
  8280. //check Transaction active
  8281. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8282. {
  8283. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8284. {
  8285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8286. goto end;
  8287. }
  8288. }//END FOR CHAdeMO_QUANTITY
  8289. for (int index = 0; index < CCS_QUANTITY; index++)
  8290. {
  8291. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8292. {
  8293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8294. goto end;
  8295. }
  8296. }//END FOR CCS_QUANTITY
  8297. for (int index = 0; index < GB_QUANTITY; index++)
  8298. {
  8299. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8300. {
  8301. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8302. goto end;
  8303. }
  8304. }// END FOR GB_QUANTITY
  8305. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8306. {
  8307. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8308. {
  8309. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8310. goto end;
  8311. }
  8312. }// END FOR GENERAL_GUN_QUANTITY
  8313. for (int index = 0; index < AC_QUANTITY; index++)
  8314. {
  8315. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8316. {
  8317. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8318. goto end;
  8319. }
  8320. }//END FOR AC_QUANTITY
  8321. }//END FOR AvailabilityTypeStr[Operative]
  8322. end:
  8323. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8324. {
  8325. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8326. }
  8327. else
  8328. {
  8329. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8330. }
  8331. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8332. {
  8333. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8334. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8335. }
  8336. else if(gunIndex == 0)
  8337. {
  8338. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8339. {
  8340. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8341. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8342. }
  8343. }
  8344. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8345. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8346. return result;
  8347. }
  8348. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8349. {
  8350. mtrace();
  8351. int valueInvalid = NO;
  8352. int result = FAIL;
  8353. char keystr[40]={0};
  8354. char valuestr[501]={0}; //value should be limited in 500 bytes
  8355. char comfirmstr[20]={0};
  8356. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8357. json_object *ChangeConfiguration;
  8358. ChangeConfiguration = json_tokener_parse(payload);
  8359. if(!is_error(ChangeConfiguration))
  8360. {
  8361. // Required data
  8362. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8363. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8364. if((json_object_object_get(ChangeConfiguration, "value") != NULL) && (strlen(json_object_get_string(json_object_object_get(ChangeConfiguration, "value"))) < ARRAY_SIZE(valuestr)))
  8365. {
  8366. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8367. }
  8368. else
  8369. {
  8370. valueInvalid = YES;
  8371. DEBUG_ERROR("The ChangeConfiguration value is NULL or OVER SIZE.\n");
  8372. }
  8373. }
  8374. json_object_put(ChangeConfiguration);
  8375. if((uuid==NULL) || (payload ==NULL) || (valueInvalid == YES))
  8376. {
  8377. DEBUG_ERROR("Payload is null or not accepted.\n");
  8378. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8379. }
  8380. else
  8381. {
  8382. int status = setKeyValue(keystr, valuestr);
  8383. switch(status)
  8384. {
  8385. case ConfigurationStatus_Accepted:
  8386. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8387. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  8388. StoreConfigurationTable();
  8389. break;
  8390. case RebootRequired:
  8391. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8392. StoreConfigurationTable();
  8393. break;
  8394. case NotSupported:
  8395. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8396. break;
  8397. case ConfigurationStatus_Rejected:
  8398. default:
  8399. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8400. break;
  8401. }
  8402. }
  8403. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8404. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  8405. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0) || (strcmp(keystr,"OcppServer")==0) || (strcmp(keystr,"MaintainServer")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8406. {
  8407. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8408. SetOcppConnStatus(FALSE);
  8409. }
  8410. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8411. {
  8412. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8413. }
  8414. return result;
  8415. }
  8416. int handleClearCacheRequest(char *uuid, char *payload)
  8417. {
  8418. mtrace();
  8419. int result = FAIL;
  8420. char comfirmstr[20];
  8421. char rmFileCmd[100]={0};
  8422. struct stat stats;
  8423. DEBUG_INFO("handleClearCacheRequest...\n");
  8424. stat("/Storage/OCPP_PH", &stats);
  8425. // Check for directory existence
  8426. if (S_ISDIR(stats.st_mode) == 1)
  8427. {}
  8428. else
  8429. {
  8430. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8431. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  8432. system(rmFileCmd);
  8433. }
  8434. if(OCPP_cleanLocalCache())
  8435. {
  8436. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8437. }
  8438. else
  8439. {
  8440. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8441. }
  8442. sendClearCacheConfirmation(uuid, comfirmstr);
  8443. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8444. return result;
  8445. }
  8446. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8447. {
  8448. mtrace();
  8449. int result = FAIL;
  8450. int resultRename;
  8451. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8452. char chargingProfilePurposeStr[26]={0};
  8453. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8454. char tempchargingProfilePurposeStr[26]={0};
  8455. char str[100]={0};
  8456. char fname[200]={0};
  8457. char comfirmstr[20]={0};
  8458. char word[1600]={0};
  8459. int clearflag = FALSE;
  8460. int chargingProfileIdIsNULL = FALSE;
  8461. int connectorIsNULL = FALSE;
  8462. int chargingProfilePurposeIsNULL = FALSE;
  8463. int stackLevelIsNULL = FALSE;
  8464. //int GotoEnd = FALSE;
  8465. FILE *fptr1, *fptr2;
  8466. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  8467. int n_chargingProfile=0;
  8468. int isEmptyFile = FALSE;
  8469. char sLineWord[1600]={0};
  8470. char chargingProfiles[10][100]={0};
  8471. int ChargeProfileCount = 0;
  8472. int ch;
  8473. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8474. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8475. json_object *ClearChargingProfile;
  8476. ClearChargingProfile = json_tokener_parse(payload);
  8477. if(!is_error(ClearChargingProfile))
  8478. {
  8479. // Optional data
  8480. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8481. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8482. else
  8483. chargingProfileIdIsNULL = TRUE;
  8484. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8485. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8486. else
  8487. connectorIsNULL = TRUE;
  8488. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8489. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8490. else
  8491. chargingProfilePurposeIsNULL = TRUE;
  8492. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8493. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8494. else
  8495. stackLevelIsNULL = TRUE;
  8496. }
  8497. json_object_put(ClearChargingProfile);
  8498. if(connectorIsNULL == FALSE)
  8499. {
  8500. switch(connectorIdInt)
  8501. {
  8502. case 0:
  8503. if(chargingProfilePurposeIsNULL == TRUE)
  8504. {
  8505. int l = 0;
  8506. strcpy(fname, ChargePointMaxProfile_JSON);
  8507. if((access(fname,F_OK))!=-1)
  8508. {
  8509. strcpy(chargingProfiles[l], fname);
  8510. l = l + 1;
  8511. }
  8512. strcpy(fname, TxDefaultProfile_0_JSON);
  8513. if((access(fname,F_OK))!=-1)
  8514. {
  8515. strcpy(chargingProfiles[l], fname);
  8516. l = l + 1;
  8517. }
  8518. ChargeProfileCount = l;
  8519. }
  8520. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8521. {
  8522. strcpy(fname, ChargePointMaxProfile_JSON);
  8523. if((access(fname,F_OK))!=-1)
  8524. {
  8525. strcpy(chargingProfiles[0], fname);
  8526. ChargeProfileCount = 1;
  8527. }
  8528. }
  8529. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8530. {
  8531. strcpy(fname, TxDefaultProfile_0_JSON);
  8532. if((access(fname,F_OK))!=-1)
  8533. {
  8534. strcpy(chargingProfiles[0], fname);
  8535. ChargeProfileCount = 1;
  8536. }
  8537. }
  8538. break;
  8539. default:
  8540. if(chargingProfilePurposeIsNULL == TRUE)
  8541. {
  8542. int m = 0;
  8543. memset(fname, 0, ARRAY_SIZE(fname));
  8544. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8545. if((access(fname,F_OK))!=-1)
  8546. {
  8547. strcpy(chargingProfiles[m], fname);
  8548. m = m + 1;
  8549. }
  8550. memset(fname, 0, ARRAY_SIZE(fname));
  8551. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8552. if((access(fname,F_OK))!=-1)
  8553. {
  8554. strcpy(chargingProfiles[m], fname);
  8555. m = m + 1;
  8556. }
  8557. ChargeProfileCount = m;
  8558. }
  8559. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8560. {
  8561. //strcpy(fname, TxDefaultProfile_1_JSON);
  8562. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  8563. if((access(fname,F_OK))!=-1)
  8564. {
  8565. strcpy(chargingProfiles[0], fname);
  8566. ChargeProfileCount = 1;
  8567. }
  8568. }
  8569. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8570. {
  8571. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8572. if((access(fname,F_OK))!=-1)
  8573. {
  8574. strcpy(chargingProfiles[0], fname);
  8575. ChargeProfileCount = 1;
  8576. }
  8577. //strcpy(fname, TxProfile_1_JSON);
  8578. }
  8579. //strcpy(fname, ChargePointMaxProfile_JSON );
  8580. break;
  8581. }
  8582. }
  8583. else // Check all Charging Profiles
  8584. {
  8585. int i = 0;
  8586. char fnametemp[200]={0};
  8587. ChargeProfileCount = 0;
  8588. //Check ChargePointMaxProfile.json exit
  8589. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  8590. {
  8591. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  8592. i = i + 1;
  8593. }
  8594. //Check TxDefaultProfile_0.json exit
  8595. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  8596. {
  8597. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  8598. i = i + 1;
  8599. }
  8600. //Check TxDefaultProfile_%d.json
  8601. for(int j=1; j <= gunTotalNumber; j++)
  8602. {
  8603. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8604. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  8605. if((access(fnametemp,F_OK))!=-1)
  8606. {
  8607. strcpy(chargingProfiles[i], fnametemp);
  8608. i = i + 1;
  8609. }
  8610. }
  8611. //Check TxProfile_%d.json
  8612. for(int j=1; j <= gunTotalNumber; j++)
  8613. {
  8614. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8615. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  8616. if((access(fnametemp,F_OK))!=-1)
  8617. {
  8618. strcpy(chargingProfiles[i], fnametemp);
  8619. i = i + 1;
  8620. }
  8621. }
  8622. ChargeProfileCount = i;
  8623. }// End connectorIsNULL is TRUE
  8624. if(ChargeProfileCount == 0)
  8625. {
  8626. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8627. goto end;
  8628. }
  8629. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8630. {
  8631. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8632. goto end;
  8633. }
  8634. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8635. {
  8636. memset(str, 0, ARRAY_SIZE(str));
  8637. // clear temp file
  8638. sprintf(str,"rm -f %s",temp);
  8639. system(str);
  8640. for(int k=0; k < ChargeProfileCount; k++)
  8641. {
  8642. memset(str, 0, ARRAY_SIZE(str));
  8643. //clear file in C
  8644. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8645. system(str);
  8646. }
  8647. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8648. goto end;
  8649. }
  8650. else if(connectorIsNULL == TRUE)
  8651. {
  8652. for(int k=0; k < ChargeProfileCount; k++)
  8653. {
  8654. fptr1 = fopen(chargingProfiles[k], "r");
  8655. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  8656. //Check Charging Profile Count
  8657. while(fscanf(fptr1, "%s", word) != EOF)
  8658. {
  8659. //DEBUG_INFO("word=%s\n",word);
  8660. if(strstr(word, "chargingProfileId")!= NULL)
  8661. {
  8662. //DEBUG_INFO("test chargingProfileId \n");
  8663. n_chargingProfile = n_chargingProfile + 1;
  8664. //DEBUG_INFO("chargingProfileId Found\n");
  8665. }
  8666. }
  8667. rewind(fptr1);
  8668. //search Charging Profile Element
  8669. //int i= 0;
  8670. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8671. {
  8672. json_object *tmpProfilee;
  8673. tmpProfilee = json_tokener_parse(sLineWord);
  8674. if(!is_error(tmpProfilee))
  8675. {
  8676. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8677. {
  8678. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8679. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8680. }
  8681. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8682. {
  8683. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8684. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8685. }
  8686. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8687. {
  8688. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8689. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8690. }
  8691. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8692. {
  8693. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8694. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8695. }
  8696. }
  8697. json_object_put(tmpProfilee);
  8698. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8699. {
  8700. //------- not write to fptr2-------//
  8701. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8702. //clearflag = TRUE;
  8703. }
  8704. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8705. {
  8706. //------- not write to fptr2-------//
  8707. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8708. }
  8709. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8710. {
  8711. //------- not write to fptr2-------//
  8712. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8713. }
  8714. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8715. {
  8716. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8717. }
  8718. else
  8719. {
  8720. fprintf(fptr2, sLineWord);//writing data into file
  8721. }
  8722. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8723. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8724. if(clearflag == TRUE)
  8725. {
  8726. fclose(fptr1);
  8727. fclose(fptr2);
  8728. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8729. system(str);
  8730. // clear temp file
  8731. sprintf(str,"rm -f %s",temp);
  8732. system(str);
  8733. }
  8734. else
  8735. {
  8736. fclose(fptr1);
  8737. fclose(fptr2);
  8738. memset(str, 0, ARRAY_SIZE(str));
  8739. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8740. system(str);
  8741. resultRename = rename(temp, chargingProfiles[k]);
  8742. if(resultRename == 0)
  8743. {
  8744. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8745. }
  8746. else
  8747. {
  8748. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8749. }
  8750. if(comfirmstr[0]== 0)
  8751. {
  8752. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8753. }
  8754. //Check chargingProfile is empty file
  8755. /*------ Read the file ----------------*/
  8756. fptr1=fopen(chargingProfiles[k],"r");
  8757. ch=fgetc(fptr1);
  8758. rewind(fptr1);
  8759. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8760. if(ch!=EOF)
  8761. {
  8762. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8763. {
  8764. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8765. if(sLineWord[0]=='\0')
  8766. {
  8767. isEmptyFile = TRUE;
  8768. break;
  8769. }
  8770. else
  8771. {
  8772. isEmptyFile = FALSE;
  8773. break;
  8774. }
  8775. }
  8776. }
  8777. else
  8778. isEmptyFile = TRUE;
  8779. fclose(fptr1);
  8780. if(isEmptyFile == TRUE)
  8781. {
  8782. memset(str, 0, ARRAY_SIZE(str));
  8783. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8784. system(str);
  8785. }
  8786. }
  8787. }// End of while(int k=0; k < ChargePointCount; k++)
  8788. }
  8789. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8790. {
  8791. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8792. for(int k=0; k < ChargeProfileCount; k++)
  8793. {
  8794. fptr1 = fopen(chargingProfiles[k], "r");
  8795. fptr2 = fopen(temp, "w+");
  8796. //Check Charging Profile Count
  8797. while(fscanf(fptr1, "%s", word) != EOF)
  8798. {
  8799. //DEBUG_INFO("word=%s\n",word);
  8800. if(strstr(word, "chargingProfileId")!= NULL)
  8801. {
  8802. n_chargingProfile = n_chargingProfile + 1;
  8803. }
  8804. }
  8805. rewind(fptr1);
  8806. //search Charging Profile Element
  8807. //int i= 0;
  8808. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8809. {
  8810. json_object *tmpProfilee;
  8811. tmpProfilee = json_tokener_parse(sLineWord);
  8812. if(!is_error(tmpProfilee))
  8813. {
  8814. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8815. {
  8816. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8817. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8818. }
  8819. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8820. {
  8821. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8822. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8823. }
  8824. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8825. {
  8826. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8827. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8828. }
  8829. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8830. {
  8831. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8832. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8833. }
  8834. }
  8835. json_object_put(tmpProfilee);
  8836. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8837. {
  8838. //------- not write to fptr2-------//
  8839. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8840. //clearflag = TRUE;
  8841. }
  8842. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8843. {
  8844. //------- not write to fptr2-------//
  8845. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8846. }
  8847. else if(stackLevelIsNULL == TRUE)
  8848. {
  8849. //Clear Whole File
  8850. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8851. clearflag = TRUE;
  8852. break;
  8853. }
  8854. else
  8855. {
  8856. fprintf(fptr2, sLineWord);//writing data into file
  8857. }
  8858. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8859. }
  8860. if(clearflag == TRUE)
  8861. {
  8862. fclose(fptr1);
  8863. fclose(fptr2);
  8864. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8865. system(str);
  8866. // clear temp file
  8867. sprintf(str,"rm -f %s",temp);
  8868. system(str);
  8869. }
  8870. else
  8871. {
  8872. fclose(fptr1);
  8873. fclose(fptr2);
  8874. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8875. system(str);
  8876. resultRename = rename(temp, chargingProfiles[k]);
  8877. if(resultRename == 0)
  8878. {
  8879. DEBUG_INFO("File ChargingProfile renamed successfully");
  8880. }
  8881. else
  8882. {
  8883. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8884. }
  8885. if(comfirmstr[0]== 0)
  8886. {
  8887. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8888. }
  8889. //Check chargingProfile is empty file
  8890. /*------ Read the file ----------------*/
  8891. fptr1=fopen(chargingProfiles[k],"r");
  8892. ch=fgetc(fptr1);
  8893. rewind(fptr1);
  8894. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8895. if(ch!=EOF)
  8896. {
  8897. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8898. {
  8899. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8900. if(sLineWord[0]=='\0')
  8901. {
  8902. isEmptyFile = TRUE;
  8903. break;
  8904. }
  8905. else
  8906. {
  8907. isEmptyFile = FALSE;
  8908. break;
  8909. }
  8910. }
  8911. }
  8912. else
  8913. isEmptyFile = TRUE;
  8914. fclose(fptr1);
  8915. if(isEmptyFile == TRUE)
  8916. {
  8917. memset(str, 0, ARRAY_SIZE(str));
  8918. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8919. system(str);
  8920. }
  8921. /*------- End of reading ---------------*/
  8922. }
  8923. } // while(int k=0; k < ChargeProfileCount; k++)
  8924. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8925. end:
  8926. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8927. {
  8928. if(connectorIdInt == 0)
  8929. {
  8930. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8931. {
  8932. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8933. }
  8934. }
  8935. else
  8936. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8937. }
  8938. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8939. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8940. return result;
  8941. }
  8942. void createFirmwareVersionByDataTransfer(void)
  8943. {
  8944. json_object *FirmwareDataTransfer = json_object_new_object();
  8945. // AC & DC model
  8946. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8947. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8948. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8949. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8950. // DC model
  8951. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8952. {
  8953. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8954. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8955. (gunType[3] != GUN_TYPE_UNKNOWN))
  8956. {
  8957. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8958. }
  8959. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8960. {
  8961. // DS DM DW
  8962. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8963. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8964. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8965. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8966. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8967. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8968. }
  8969. else
  8970. {
  8971. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8972. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8973. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8974. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8975. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8976. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8977. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8978. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8979. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8980. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8981. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8982. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8983. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8984. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8985. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8986. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8987. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8988. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8989. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8990. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8991. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8992. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8993. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8994. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8995. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8996. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8997. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8998. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8999. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  9000. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  9001. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  9002. }
  9003. }
  9004. // 4G model
  9005. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  9006. {
  9007. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  9008. }
  9009. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  9010. json_object_put(FirmwareDataTransfer);
  9011. }
  9012. int handleDataTransferRequest(char *uuid, char *payload)
  9013. {
  9014. mtrace();
  9015. json_object *response = json_object_new_object();
  9016. int result = FAIL;
  9017. char tempvendorId[255]={0};
  9018. char tempmessageId[50]={0};
  9019. char tempdata[1024]={0};
  9020. char message[2048]={0};
  9021. DEBUG_INFO("handleDataTransferRequest...\n");
  9022. if((uuid != NULL) && (payload != NULL))
  9023. {
  9024. json_object *DataTransfer;
  9025. DataTransfer = json_tokener_parse(payload);
  9026. if(!is_error(DataTransfer))
  9027. {
  9028. // Required data
  9029. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  9030. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  9031. // Optional data
  9032. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  9033. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  9034. if(json_object_object_get(DataTransfer, "data") != NULL)
  9035. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  9036. result = PASS;
  9037. }
  9038. json_object_put(DataTransfer);
  9039. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  9040. {
  9041. // Send all moudle firmware version on EVSE
  9042. createFirmwareVersionByDataTransfer();
  9043. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9044. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].ResponseData));
  9045. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9046. json_object_put(response);
  9047. }
  9048. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  9049. {
  9050. system("/usr/bin/run_tmate_restart.sh &");
  9051. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9052. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9053. json_object_put(response);
  9054. }
  9055. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  9056. {
  9057. json_object *data;
  9058. data = json_tokener_parse(tempdata);
  9059. if(!is_error(data))
  9060. {
  9061. 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))
  9062. {
  9063. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9064. memset(&ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  9065. if(json_object_object_get(data, "SOC") != NULL)
  9066. {
  9067. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  9068. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  9069. }
  9070. if(json_object_object_get(data, "Energy") != NULL)
  9071. {
  9072. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  9073. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  9074. }
  9075. if(json_object_object_get(data, "Duration") != NULL)
  9076. {
  9077. ShmOCPP16DataPH->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  9078. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  9079. }
  9080. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9081. }
  9082. else
  9083. {
  9084. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9085. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  9086. }
  9087. }
  9088. else
  9089. {
  9090. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9091. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9092. }
  9093. json_object_put(data);
  9094. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9095. json_object_put(response);
  9096. }
  9097. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  9098. {
  9099. json_object *data;
  9100. data = json_tokener_parse(tempdata);
  9101. if(!is_error(data))
  9102. {
  9103. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  9104. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  9105. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  9106. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  9107. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  9108. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  9109. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  9110. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  9111. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  9112. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  9113. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9114. }
  9115. else
  9116. {
  9117. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9118. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9119. }
  9120. json_object_put(data);
  9121. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9122. json_object_put(response);
  9123. }
  9124. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  9125. {
  9126. json_object *data;
  9127. data = json_tokener_parse(tempdata);
  9128. if(!is_error(data))
  9129. {
  9130. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  9131. if(json_object_object_get(data, "idToken") != NULL)
  9132. {
  9133. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  9134. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  9135. }
  9136. if(json_object_object_get(data, "price") != NULL)
  9137. {
  9138. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  9139. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  9140. }
  9141. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9142. }
  9143. else
  9144. {
  9145. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9146. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9147. }
  9148. json_object_put(data);
  9149. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9150. json_object_put(response);
  9151. }
  9152. else if(strstr(tempmessageId, "RunningCost") != NULL)
  9153. {
  9154. json_object *data;
  9155. data = json_tokener_parse(tempdata);
  9156. if(!is_error(data))
  9157. {
  9158. if(json_object_object_get(data, "txId") != NULL)
  9159. {
  9160. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9161. for(int idx = 0;idx<gunTotalNumber;idx++)
  9162. {
  9163. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9164. {
  9165. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  9166. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9167. if(json_object_object_get(data, "description") != NULL)
  9168. {
  9169. // California pricing V1.0
  9170. DEBUG_INFO("California pricing V1.0\n");
  9171. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9172. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9173. }
  9174. else
  9175. {
  9176. // California pricing V1.1
  9177. DEBUG_INFO("California pricing V1.1\n");
  9178. if(json_object_object_get(data, "timestamp") != NULL)
  9179. {
  9180. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  9181. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  9182. }
  9183. if(json_object_object_get(data, "meterValue") != NULL)
  9184. {
  9185. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  9186. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  9187. }
  9188. if(json_object_object_get(data, "cost") != NULL)
  9189. {
  9190. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9191. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9192. }
  9193. if(json_object_object_get(data, "state") != NULL)
  9194. {
  9195. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9196. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9197. }
  9198. if(json_object_object_get(data, "chargingPrice") != NULL)
  9199. {
  9200. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9201. {
  9202. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9203. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9204. }
  9205. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9206. {
  9207. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9208. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9209. }
  9210. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9211. {
  9212. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9213. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9214. }
  9215. }
  9216. if(json_object_object_get(data, "idlePrice") != NULL)
  9217. {
  9218. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9219. {
  9220. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9221. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9222. }
  9223. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9224. {
  9225. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9226. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9227. }
  9228. }
  9229. if(json_object_object_get(data, "nextPeriod") != NULL)
  9230. {
  9231. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9232. {
  9233. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9234. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9235. }
  9236. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9237. {
  9238. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9239. {
  9240. 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")));
  9241. 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"));
  9242. }
  9243. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9244. {
  9245. 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")));
  9246. 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"));
  9247. }
  9248. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9249. {
  9250. 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")));
  9251. 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"));
  9252. }
  9253. }
  9254. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9255. {
  9256. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9257. {
  9258. 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")));
  9259. 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"));
  9260. }
  9261. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9262. {
  9263. 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")));
  9264. 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"));
  9265. }
  9266. }
  9267. }
  9268. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9269. {
  9270. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9271. {
  9272. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9273. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9274. }
  9275. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9276. {
  9277. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9278. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9279. }
  9280. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9281. {
  9282. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9283. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9284. }
  9285. }
  9286. }
  9287. }
  9288. }
  9289. }
  9290. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9291. }
  9292. else
  9293. {
  9294. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9295. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9296. }
  9297. json_object_put(data);
  9298. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9299. json_object_put(response);
  9300. }
  9301. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9302. {
  9303. json_object *data;
  9304. data = json_tokener_parse(tempdata);
  9305. if(!is_error(data))
  9306. {
  9307. if(json_object_object_get(data, "txId") != NULL)
  9308. {
  9309. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9310. for(int idx = 0;idx<gunTotalNumber;idx++)
  9311. {
  9312. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9313. {
  9314. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9315. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9316. if(json_object_object_get(data, "description") != NULL)
  9317. {
  9318. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9319. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9320. }
  9321. }
  9322. }
  9323. }
  9324. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9325. }
  9326. else
  9327. {
  9328. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9329. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9330. }
  9331. json_object_put(data);
  9332. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9333. json_object_put(response);
  9334. }
  9335. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9336. {
  9337. json_object *data;
  9338. data = json_tokener_parse(tempdata);
  9339. if(!is_error(data))
  9340. {
  9341. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9342. if(json_object_object_get(data, "Content_Type") != NULL)
  9343. {
  9344. 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))
  9345. {
  9346. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9347. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9348. {
  9349. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9350. }
  9351. }
  9352. else
  9353. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9354. }
  9355. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9356. }
  9357. else
  9358. {
  9359. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9360. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9361. }
  9362. json_object_put(data);
  9363. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9364. json_object_put(response);
  9365. }
  9366. else if(strstr(tempmessageId, "ID_LineStatusPage") != NULL)
  9367. {
  9368. json_object *data;
  9369. data = json_tokener_parse(tempdata);
  9370. if(!is_error(data))
  9371. {
  9372. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9373. if(json_object_object_get(data, "ConnectorId") != NULL)
  9374. {
  9375. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  9376. }
  9377. if(json_object_object_get(data, "SerialNo") != NULL)
  9378. {
  9379. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.SerialNo[(ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId-1)], "%s", json_object_get_string(json_object_object_get(data,"SerialNo")));
  9380. }
  9381. if(json_object_object_get(data, "Page_Index") != NULL)
  9382. {
  9383. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9384. }
  9385. if(json_object_object_get(data, "Duration") != NULL)
  9386. {
  9387. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9388. }
  9389. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = 1;
  9390. }
  9391. else
  9392. {
  9393. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9394. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9395. }
  9396. json_object_put(data);
  9397. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9398. json_object_put(response);
  9399. }
  9400. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9401. {
  9402. json_object *data;
  9403. data = json_tokener_parse(tempdata);
  9404. if(!is_error(data))
  9405. {
  9406. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9407. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9408. {
  9409. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9410. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9411. else
  9412. {
  9413. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9414. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9415. }
  9416. }
  9417. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9418. {
  9419. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9420. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9421. else
  9422. {
  9423. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9424. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9425. }
  9426. }
  9427. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9428. {
  9429. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9430. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9431. else
  9432. {
  9433. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9434. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9435. }
  9436. }
  9437. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9438. {
  9439. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9440. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9441. else
  9442. {
  9443. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9444. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9445. }
  9446. }
  9447. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9448. {
  9449. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9450. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9451. else
  9452. {
  9453. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9454. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9455. }
  9456. }
  9457. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9458. {
  9459. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9460. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9461. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9462. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9463. else
  9464. {
  9465. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9466. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9467. }
  9468. }
  9469. if(json_object_object_get(data, "isAuthentication") != NULL)
  9470. {
  9471. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9472. {
  9473. case 0:
  9474. case 1:
  9475. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9476. break;
  9477. default:
  9478. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9479. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9480. break;
  9481. }
  9482. }
  9483. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9484. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9485. }
  9486. else
  9487. {
  9488. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9489. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9490. }
  9491. json_object_put(data);
  9492. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9493. json_object_put(response);
  9494. }
  9495. else if(strstr(tempmessageId, "ID_Station_Location") != NULL)
  9496. {
  9497. json_object *data;
  9498. data = json_tokener_parse(tempdata);
  9499. if(!is_error(data))
  9500. {
  9501. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9502. if(json_object_object_get(data, "stationName") != NULL)
  9503. {
  9504. sprintf((char *)ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name, "%s", json_object_get_string(json_object_object_get(data,"stationName")));
  9505. }
  9506. else
  9507. {
  9508. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9509. json_object_object_add(response, "data", json_object_new_string("station_name data can not get."));
  9510. }
  9511. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9512. {
  9513. ShmOCPP16DataPH->TcciCustomData.ChargerInfoReq = 1;
  9514. DEBUG_INFO("<<< ID_Station_Location:{station_name:%s}\n",
  9515. ShmOCPP16DataPH->TcciCustomData.ChargerInfo.station_name);
  9516. }
  9517. }
  9518. else
  9519. {
  9520. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9521. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9522. }
  9523. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9524. json_object_put(response);
  9525. }
  9526. else if(strstr(tempmessageId, "ID_Weather_Info") != NULL)
  9527. {
  9528. json_object *data;
  9529. data = json_tokener_parse(tempdata);
  9530. if(!is_error(data))
  9531. {
  9532. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9533. if(json_object_object_get(data, "weatherId") != NULL)
  9534. {
  9535. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId = json_object_get_int(json_object_object_get(data, "weatherId"));
  9536. }
  9537. else
  9538. {
  9539. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9540. json_object_object_add(response, "data", json_object_new_string("weather data can not get."));
  9541. }
  9542. if(json_object_object_get(data, "Temperature") != NULL)
  9543. {
  9544. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature = json_object_get_double(json_object_object_get(data,"Temperature"));
  9545. }
  9546. else
  9547. {
  9548. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9549. json_object_object_add(response, "data", json_object_new_string("temperature data can not get."));
  9550. }
  9551. if(strcmp(json_object_get_string(json_object_object_get(response,"status")),"Accepted")==0)
  9552. {
  9553. ShmOCPP16DataPH->TcciCustomData.WeatherInfoReq = 1;
  9554. DEBUG_INFO("<<< ID_Weather_Info:{weather:%d, temperature:%.1f}\n",
  9555. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.weatherId,
  9556. ShmOCPP16DataPH->TcciCustomData.WeatherInfo.temperature);
  9557. }
  9558. }
  9559. else if(strstr(tempmessageId, "ID_TriggerCreditReader") != NULL)
  9560. {
  9561. json_object *data;
  9562. data = json_tokener_parse(tempdata);
  9563. if(!is_error(data))
  9564. {
  9565. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9566. if(json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0)
  9567. {
  9568. ShmOCPP16DataPH->TcciCustomData.TriggerReaderReq[json_object_get_int(json_object_object_get(data, "ConnectorId")) -1] = TRUE;
  9569. DEBUG_INFO("<<< ID_TriggerCreditReader:{ConnectorId: %d}\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  9570. }
  9571. else
  9572. {
  9573. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9574. json_object_object_add(response, "data", json_object_new_string("ConnectorId does not valid."));
  9575. }
  9576. }
  9577. else
  9578. {
  9579. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9580. json_object_object_add(response, "data", json_object_new_string("charger_info content got something wrong."));
  9581. }
  9582. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9583. json_object_put(response);
  9584. }
  9585. else if(strstr(tempmessageId, "ID_GetTxUserInfo") != NULL)
  9586. {
  9587. json_object *data;
  9588. data = json_tokener_parse(tempdata);
  9589. if(!is_error(data))
  9590. {
  9591. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_object_get(data, "txId") != NULL))
  9592. {
  9593. int gun_index = json_object_get_int(json_object_object_get(data, "ConnectorId"))-1;
  9594. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9595. if(gun_index < gunTotalNumber)
  9596. {
  9597. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9598. {
  9599. json_object *responsedata = json_object_new_object();
  9600. json_object_object_add(responsedata, "txId", json_object_new_int(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId));
  9601. json_object_object_add(responsedata, "ConnectorId", json_object_new_int(gun_index+1));
  9602. json_object_object_add(responsedata, "SerialNo", json_object_new_string((char*)ShmOCPP16DataPH->TcciCustomData.SerialNo[gun_index]));
  9603. json_object_object_add(responsedata, "StartTime", json_object_new_string((char*)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp));
  9604. json_object_object_add(responsedata, "VEMData", json_object_new_string((char*)ShmOCPP16Data->TcciCustomData.VEMData[gun_index]));
  9605. json_object_object_add(response, "data", json_object_new_string(json_object_to_json_string_ext(responsedata, JSON_C_TO_STRING_PLAIN)));
  9606. }
  9607. else
  9608. {
  9609. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9610. json_object_object_add(response, "data", json_object_new_string("txId doesn't match the current transactionId."));
  9611. }
  9612. }
  9613. else
  9614. {
  9615. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9616. json_object_object_add(response, "data", json_object_new_string("ConnectorId is invalid."));
  9617. }
  9618. }
  9619. else
  9620. {
  9621. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9622. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9623. }
  9624. }
  9625. else
  9626. {
  9627. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9628. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9629. }
  9630. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9631. json_object_put(response);
  9632. }
  9633. else
  9634. {
  9635. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9636. json_object_object_add(response, "data", json_object_new_string("weather_info content got something wrong."));
  9637. }
  9638. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9639. json_object_put(response);
  9640. }
  9641. else
  9642. {
  9643. // Can not find valid message id
  9644. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9645. }
  9646. }
  9647. else
  9648. {
  9649. // Payload is null
  9650. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9651. }
  9652. LWS_Send(message);
  9653. return result;
  9654. }
  9655. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9656. {
  9657. mtrace();
  9658. int result = FAIL;
  9659. int connectorIdInt, durationInt;
  9660. char chargingRateUnitStr[4]={0};
  9661. char comfirmstr[20];
  9662. int confirmPeriods = 0;
  9663. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9664. json_object *GetCompositeSchedule;
  9665. GetCompositeSchedule = json_tokener_parse(payload);
  9666. if(!is_error(GetCompositeSchedule))
  9667. {
  9668. // Required data
  9669. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9670. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9671. else
  9672. connectorIdInt = -1;
  9673. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9674. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9675. else
  9676. durationInt = 86400;
  9677. // Optional data
  9678. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9679. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9680. }
  9681. json_object_put(GetCompositeSchedule);
  9682. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9683. if((connectorIdInt == 0) ||
  9684. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9685. {
  9686. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9687. struct StructChargingProfile tmpProfile[1];
  9688. if(strstr(chargingRateUnitStr, "W") != NULL)
  9689. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9690. else
  9691. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9692. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9693. {
  9694. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9695. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9696. }
  9697. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9698. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9699. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9700. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9701. {
  9702. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9703. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9704. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9705. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9706. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9707. {
  9708. confirmPeriods = idx;
  9709. break;
  9710. }
  9711. }
  9712. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9713. {
  9714. confirmPeriods += 1;
  9715. }
  9716. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9717. }
  9718. else
  9719. {
  9720. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9721. }
  9722. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9723. return result;
  9724. }
  9725. int handleGetConfigurationRequest(char *uuid, char *payload)
  9726. {
  9727. mtrace();
  9728. int result = FAIL;
  9729. int MaxKeySupported = 0;
  9730. int n_keys = 0;
  9731. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9732. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9733. json_object *GetConfiguration;
  9734. GetConfiguration = json_tokener_parse(payload);
  9735. if(!is_error(GetConfiguration))
  9736. {
  9737. // Optional data
  9738. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9739. {
  9740. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9741. {
  9742. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9743. n_keys = idx + 1;
  9744. }
  9745. }
  9746. }
  9747. json_object_put(GetConfiguration);
  9748. UnknownKeynum = 0;
  9749. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9750. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9751. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9752. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9753. if(n_keys != 0)
  9754. {
  9755. for(int i=0;i<n_keys;i++)
  9756. {
  9757. getKeyValue(requestKey[i]);
  9758. }
  9759. }
  9760. else
  9761. {
  9762. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9763. getKeyValue("");
  9764. }
  9765. processUnkownKey();
  9766. sendGetConfigurationConfirmation(uuid);
  9767. return result;
  9768. }
  9769. static char fnamePlusPath[100]={0};
  9770. static char fnamePWithNoPath[60]={0};
  9771. void checkUploadLog(void)
  9772. {
  9773. FILE *fp;
  9774. /* Open the command for reading. */
  9775. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9776. if (fp == NULL) {
  9777. DEBUG_WARN("Failed to run command\n" );
  9778. exit(1);
  9779. }
  9780. int ftppathlen = 0;
  9781. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9782. int i = 0;
  9783. /* Read the output a line at a time - output it. */
  9784. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9785. if(i==0)
  9786. {
  9787. ftppathlen = strlen(fnamePlusPath);
  9788. DEBUG_INFO("%s\n", fnamePlusPath);
  9789. fnamePlusPath[ftppathlen]='\0';
  9790. break;
  9791. }
  9792. i= i+1;
  9793. }
  9794. /* close */
  9795. pclose(fp);
  9796. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9797. {
  9798. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9799. {
  9800. fnamePlusPath[k]='\0';
  9801. }
  9802. }
  9803. i=1;
  9804. //char fname[60]={0};
  9805. while(i < ftppathlen)
  9806. {
  9807. int len=ftppathlen-i;
  9808. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9809. {
  9810. DEBUG_INFO("compare '/' all right\n");
  9811. break;
  9812. }
  9813. i=i+1;
  9814. }
  9815. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9816. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9817. fnamePWithNoPath[i+1] = '\0';
  9818. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9819. {
  9820. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9821. {
  9822. fnamePWithNoPath[j]='\0';
  9823. }
  9824. }
  9825. FILE* fp1 = fopen(fnamePlusPath, "r");
  9826. if (fp1)
  9827. {
  9828. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9829. // file exists
  9830. fclose(fp1);
  9831. }
  9832. else
  9833. {
  9834. // file doesn't exist
  9835. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9836. }
  9837. }
  9838. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9839. {
  9840. mtrace();
  9841. int result = FAIL;
  9842. time_t CurrentTime;
  9843. struct tm *tm;
  9844. pthread_t th_Status;
  9845. CurrentTime = time(NULL);
  9846. tm = localtime(&CurrentTime);
  9847. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  9848. 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);
  9849. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9850. if(!interLock.isGetDiagnosticGoing)
  9851. {
  9852. interLock.isGetDiagnosticGoing = 1;
  9853. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9854. sleep(1);
  9855. }
  9856. else
  9857. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9858. return result;
  9859. }
  9860. void* GetDiagnosticsProcess(void* data)
  9861. {
  9862. pthread_detach(pthread_self());
  9863. mtrace();
  9864. int retriesInt=0, retryIntervalInt=0;
  9865. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9866. 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};
  9867. int port=0;
  9868. int isSuccess = FALSE;
  9869. char ftpbuf[200]={0};
  9870. char cmdBuf[2048];
  9871. struct tm *tmNow;
  9872. time_t CurrentTime;
  9873. struct tm tmStart;
  9874. struct tm tmStop;
  9875. CurrentTime = time(NULL);
  9876. tmNow=localtime(&CurrentTime);
  9877. uint16_t targetYear, targetMonth;
  9878. json_object *GetDiagnostics;
  9879. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9880. GetDiagnostics = json_tokener_parse(data);
  9881. if(!is_error(GetDiagnostics))
  9882. {
  9883. // Required data
  9884. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9885. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9886. // Optional data
  9887. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9888. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9889. else
  9890. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9891. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9892. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9893. else
  9894. retryIntervalInt = 30;
  9895. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9896. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9897. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9898. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9899. }
  9900. json_object_put(GetDiagnostics);
  9901. // Pack log to compress file
  9902. 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) &&
  9903. (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))
  9904. {
  9905. // Pack system log
  9906. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9907. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9908. targetYear = tmStart.tm_year;
  9909. targetMonth = tmStart.tm_mon;
  9910. do
  9911. {
  9912. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9913. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9914. if(targetMonth+1>=13)
  9915. {
  9916. targetYear += 1;
  9917. targetMonth = 1;
  9918. }
  9919. else
  9920. {
  9921. targetMonth += 1;
  9922. }
  9923. }while((targetYear < (tmNow->tm_year+1900)) ||
  9924. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9925. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9926. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9927. system(cmdBuf);
  9928. // Pack charging & event log
  9929. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9930. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9931. targetYear = tmStart.tm_year;
  9932. targetMonth = tmStart.tm_mon;
  9933. do
  9934. {
  9935. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9936. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9937. if(targetMonth+1>=13)
  9938. {
  9939. targetYear += 1;
  9940. targetMonth = 1;
  9941. }
  9942. else
  9943. {
  9944. targetMonth += 1;
  9945. }
  9946. }while((targetYear < (tmNow->tm_year+1900)) ||
  9947. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9948. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9949. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9950. system(cmdBuf);
  9951. // Combine log file
  9952. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9953. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9954. }
  9955. else
  9956. {
  9957. system("exec /root/logPackTools 'log' 6");
  9958. }
  9959. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9960. system(cmdBuf);
  9961. checkUploadLog();
  9962. //****************location*******************/
  9963. if(strcmp(locationstr,"")==0)
  9964. {
  9965. DEBUG_INFO("location is <Empty>!\n");
  9966. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9967. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9968. goto end;
  9969. }
  9970. memset(protocol, 0, ARRAY_SIZE(protocol));
  9971. memset(user, 0, ARRAY_SIZE(user) );
  9972. memset(password, 0, ARRAY_SIZE(password));
  9973. memset(host, 0, ARRAY_SIZE(host));
  9974. memset(path, 0, ARRAY_SIZE(path));
  9975. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9976. memset(host1, 0, ARRAY_SIZE(host1));
  9977. memset(path1, 0, ARRAY_SIZE(path1));
  9978. /*location: ftp://user:password@host:port/path*/
  9979. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9980. if((access(fnamePlusPath,F_OK))!=-1)
  9981. {
  9982. DEBUG_INFO("fnamePlusPath exist.\n");
  9983. }
  9984. else
  9985. {
  9986. DEBUG_INFO("fnamePlusPath not exist!\n");
  9987. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9988. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9989. goto end;
  9990. }
  9991. if(strchr(locationstr,'@')==NULL)
  9992. {
  9993. sscanf(locationstr,
  9994. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9995. protocol, host, &port, path);
  9996. strcpy(user,"anonymous");
  9997. strcpy(password,"");
  9998. }
  9999. else
  10000. {
  10001. //DEBUG_INFO("pch=%s\n", pch);
  10002. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10003. protocol, user, password, host, &port, path);
  10004. }
  10005. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  10006. {
  10007. DEBUG_INFO("protocol is not ftp/http ! \n");
  10008. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10009. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10010. goto end;
  10011. }
  10012. if(strncmp(locationstr,"http", 4) == 0)
  10013. {
  10014. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10015. sprintf(ftppath,"/%s", path);
  10016. do
  10017. {
  10018. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10019. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10020. sleep(3);
  10021. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  10022. if(!isSuccess)
  10023. {
  10024. DEBUG_INFO("Diagnostics fail.\n");
  10025. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10026. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10027. sleep(retryIntervalInt);
  10028. }
  10029. else
  10030. {
  10031. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10032. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10033. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10034. }
  10035. retriesInt--;
  10036. }while((isSuccess == 0)&&(retriesInt >= 0));
  10037. }
  10038. else
  10039. {
  10040. sscanf(host,"%[^/]%s",host1, path1);
  10041. if(strlen(path) > 0)
  10042. sprintf(ftppath,"/%s", path);
  10043. else
  10044. sprintf(ftppath,"/%s", path1);
  10045. int ftppathlen=strlen(ftppath);
  10046. int i=1;
  10047. char filenametemp[50];
  10048. while(i < ftppathlen)
  10049. {
  10050. int len=ftppathlen-i;
  10051. if(ftppath[len]== 47) // '/' ascll code: 47
  10052. {
  10053. DEBUG_INFO("find '/' all right\n");
  10054. break;
  10055. }
  10056. i=i+1;
  10057. }
  10058. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10059. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10060. filenametemp[i+1] = 0;
  10061. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10062. if(port == 0)
  10063. port = 21;
  10064. do
  10065. {
  10066. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  10067. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10068. sleep(3);
  10069. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10070. if(!isSuccess)
  10071. {
  10072. DEBUG_INFO("Diagnostics fail.\n");
  10073. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  10074. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10075. sleep(retryIntervalInt);
  10076. }
  10077. else
  10078. {
  10079. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  10080. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  10081. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10082. }
  10083. retriesInt--;
  10084. }while((!isSuccess)&&(retriesInt >= 0));
  10085. }
  10086. end:
  10087. system("rm -f /mnt/*");
  10088. sleep(5);
  10089. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10090. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10091. interLock.isGetDiagnosticGoing = 0;
  10092. pthread_exit(NULL);
  10093. }
  10094. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10095. {
  10096. mtrace();
  10097. int result = FAIL;
  10098. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10099. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  10100. {
  10101. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10102. locallistVersion = -1;
  10103. }
  10104. else
  10105. {
  10106. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10107. OCPP_getListVerion();
  10108. }
  10109. //from db.OCPP_getListVerion
  10110. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  10111. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  10112. sendGetLocalListVersionConfirmation(uuid,"");
  10113. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  10114. return result;
  10115. }
  10116. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  10117. {
  10118. mtrace();
  10119. int result = FAIL;
  10120. int connectorIdInt=-1;
  10121. int tempIndex = 0;
  10122. int connectorIdIsNULL, chargingProfileIsNULL;
  10123. char comfirmstr[20]={0};
  10124. char cmdBuf[512];
  10125. json_object *RemoteStartTransaction;
  10126. FILE *fp;
  10127. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10128. if(server_pending == TRUE)
  10129. {
  10130. return 0;
  10131. }
  10132. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  10133. RemoteStartTransaction = json_tokener_parse(payload);
  10134. if(!is_error(RemoteStartTransaction))
  10135. {
  10136. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10137. {
  10138. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10139. }
  10140. else
  10141. {
  10142. connectorIdIsNULL = TRUE;
  10143. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10144. {
  10145. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10146. {
  10147. connectorIdIsNULL = FALSE;
  10148. connectorIdInt = (gun_index+1);
  10149. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10150. break;
  10151. }
  10152. }
  10153. }
  10154. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  10155. {
  10156. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10157. // Required data
  10158. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10159. // Optional data
  10160. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10161. {
  10162. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10163. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10164. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10165. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10166. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10167. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10168. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10169. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10170. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10171. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10172. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10173. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10174. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10175. {
  10176. 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")));
  10177. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10178. 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"));
  10179. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10180. 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"));
  10181. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10182. 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")));
  10183. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10184. {
  10185. 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++)
  10186. {
  10187. 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"));
  10188. 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"));
  10189. 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)
  10190. 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"));
  10191. }
  10192. }
  10193. }
  10194. }
  10195. else
  10196. {
  10197. chargingProfileIsNULL = TRUE;
  10198. }
  10199. }
  10200. }
  10201. else
  10202. {
  10203. connectorIdIsNULL = TRUE;
  10204. }
  10205. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  10206. {
  10207. DEBUG_WARN("Connector id is NULL\n.");
  10208. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10209. goto end;
  10210. }
  10211. /*
  10212. enum _SYSTEM_STATUS
  10213. {
  10214. S_BOOTING = 0,
  10215. S_IDLE, = 1
  10216. S_AUTHORIZING, = 2
  10217. S_REASSIGN_CHECK, = 3
  10218. S_REASSIGN, = 4
  10219. S_PRECHARGE, = 5
  10220. S_PREPARING_FOR_EV, = 6
  10221. S_PREPARING_FOR_EVSE, = 7
  10222. S_CHARGING, = 8
  10223. S_TERMINATING, = 9
  10224. S_COMPLETE, = 10
  10225. S_ALARM, = 11
  10226. S_FAULT = 12
  10227. }
  10228. */
  10229. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  10230. {
  10231. //check Transaction active
  10232. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10233. {
  10234. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10235. {
  10236. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10237. }
  10238. else
  10239. {
  10240. tempIndex = connectorIdInt -1;
  10241. }
  10242. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10243. {
  10244. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  10245. {
  10246. 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))
  10247. {
  10248. //Reserved
  10249. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10250. }
  10251. 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))
  10252. {
  10253. //Reserved
  10254. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10255. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10256. goto end;
  10257. }
  10258. else
  10259. {
  10260. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10261. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10262. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10263. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10264. {
  10265. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  10266. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10267. goto end;
  10268. }
  10269. }//END FOR ELSE
  10270. }
  10271. }// END FOR CHAdeMO_QUANTITY
  10272. }
  10273. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10274. {
  10275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10276. {
  10277. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10278. }
  10279. else
  10280. {
  10281. tempIndex = connectorIdInt -1;
  10282. }
  10283. for (int index = 0; index < CCS_QUANTITY; index++)
  10284. {
  10285. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10286. {
  10287. 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))
  10288. {
  10289. //Reserved
  10290. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10291. }
  10292. 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))
  10293. {
  10294. //Reserved
  10295. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10296. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10297. goto end;
  10298. }
  10299. else
  10300. {
  10301. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10302. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10303. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10304. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10305. {
  10306. DEBUG_WARN("CCS connector not allow start\n.");
  10307. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10308. goto end;
  10309. }
  10310. }// END FOR ELSE
  10311. }
  10312. }// END FOR CCS_QUANTITY
  10313. }
  10314. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10315. {
  10316. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10317. {
  10318. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10319. }
  10320. else
  10321. {
  10322. tempIndex = connectorIdInt -1;
  10323. }
  10324. for (int index = 0; index < GB_QUANTITY; index++)
  10325. {
  10326. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10327. {
  10328. 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))
  10329. {
  10330. //Reserved
  10331. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10332. }
  10333. 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))
  10334. {
  10335. //Reserved
  10336. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10337. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10338. goto end;
  10339. }
  10340. else
  10341. {
  10342. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10343. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10344. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10345. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10346. {
  10347. DEBUG_WARN("GB connector not allow start\n.");
  10348. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10349. goto end;
  10350. }
  10351. }// END FOR ELSE
  10352. }
  10353. } // END FOR GB_QUANTITY
  10354. }
  10355. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10356. {
  10357. tempIndex = connectorIdInt -1;
  10358. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10359. {
  10360. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10361. {
  10362. 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))
  10363. {
  10364. //Reserved
  10365. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10366. }
  10367. 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))
  10368. {
  10369. //Reserved
  10370. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10371. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10372. goto end;
  10373. }
  10374. else
  10375. {
  10376. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10377. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10378. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10379. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10380. {
  10381. DEBUG_WARN("GB connector not allow start\n.");
  10382. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10383. goto end;
  10384. }
  10385. }// END FOR ELSE
  10386. }
  10387. } // END FOR GB_QUANTITY
  10388. }
  10389. else
  10390. {
  10391. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10392. {
  10393. tempIndex = 2;
  10394. }
  10395. else
  10396. {
  10397. tempIndex = connectorIdInt -1;
  10398. }
  10399. for (int index = 0; index < AC_QUANTITY; index++)
  10400. {
  10401. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10402. {
  10403. 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))
  10404. {
  10405. //Reserved
  10406. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10407. }
  10408. 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))
  10409. {
  10410. //Reserved
  10411. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10413. goto end;
  10414. }
  10415. else
  10416. {
  10417. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10418. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10419. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10420. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10421. {
  10422. DEBUG_WARN("AC connector not allow start\n.");
  10423. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10424. goto end;
  10425. }
  10426. }//END FOR ELSE
  10427. }
  10428. }// END FOR AC_QUANTITY
  10429. }
  10430. if(chargingProfileIsNULL == FALSE)
  10431. {
  10432. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10433. {
  10434. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10435. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10436. //memset idTag
  10437. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10438. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10439. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10440. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10441. // Save profile to file
  10442. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10443. system(cmdBuf);
  10444. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10445. fp = fopen(cmdBuf, "w");
  10446. 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));
  10447. fclose(fp);
  10448. }
  10449. else
  10450. {
  10451. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10452. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10453. }
  10454. }
  10455. else
  10456. {
  10457. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10458. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10459. //memset idTag
  10460. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10461. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10462. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10463. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10464. }
  10465. }
  10466. else
  10467. {
  10468. DEBUG_WARN("Connector id over\n.");
  10469. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10470. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10471. }
  10472. end:
  10473. json_object_put(RemoteStartTransaction);
  10474. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10475. {
  10476. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10477. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10478. }
  10479. //OCPP send RemoteStartConfirmation by first.
  10480. sendRemoteStartConfirmation(uuid, comfirmstr);
  10481. return result;
  10482. }
  10483. int handleRemoteStartRequest(char *uuid, char *payload)
  10484. {
  10485. mtrace();
  10486. int result = PASS;
  10487. int connectorIdInt=-1;
  10488. int tempIndex = 0;
  10489. char comfirmstr[20]={0};
  10490. char cmdBuf[512];
  10491. json_object *RemoteStartTransaction;
  10492. FILE *fp;
  10493. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10494. if(server_pending == TRUE)
  10495. {
  10496. result = FAIL;
  10497. }
  10498. RemoteStartTransaction = json_tokener_parse(payload);
  10499. if(!is_error(RemoteStartTransaction))
  10500. {
  10501. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10502. {
  10503. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10504. }
  10505. else
  10506. {
  10507. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10508. {
  10509. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10510. {
  10511. connectorIdInt = (gun_index+1);
  10512. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10513. break;
  10514. }
  10515. }
  10516. }
  10517. if(connectorIdInt == 0)
  10518. {
  10519. DEBUG_WARN("Connector id shall not equal 0.\n");
  10520. result = FAIL;
  10521. }
  10522. else if(connectorIdInt == -1)
  10523. {
  10524. DEBUG_INFO("Connector id does not specific.\n");
  10525. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10526. {
  10527. memset(&ShmOCPP16DataPH->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10528. // Required data
  10529. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10530. // Optional data
  10531. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10532. {
  10533. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10534. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10535. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10536. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10537. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10538. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10539. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10540. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10541. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10542. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10543. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10544. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10545. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10546. {
  10547. 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")));
  10548. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10549. 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"));
  10550. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10551. 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"));
  10552. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10553. 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")));
  10554. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10555. {
  10556. 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++)
  10557. {
  10558. 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"));
  10559. 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"));
  10560. 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)
  10561. 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"));
  10562. }
  10563. }
  10564. }
  10565. }
  10566. else
  10567. {
  10568. ShmOCPP16DataPH->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10569. }
  10570. }
  10571. }
  10572. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10573. {
  10574. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10575. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10576. // Required data
  10577. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10578. // Optional data
  10579. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10580. {
  10581. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10582. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10583. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10584. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10585. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10586. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10587. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10588. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10589. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10590. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10591. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10592. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10593. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10594. {
  10595. 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")));
  10596. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10597. 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"));
  10598. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10599. 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"));
  10600. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10601. 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")));
  10602. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10603. {
  10604. 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++)
  10605. {
  10606. 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"));
  10607. 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"));
  10608. 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)
  10609. 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"));
  10610. }
  10611. }
  10612. }
  10613. }
  10614. else
  10615. {
  10616. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10617. }
  10618. }
  10619. else
  10620. {
  10621. DEBUG_WARN("Connector id is over maximun value.\n");
  10622. result = FAIL;
  10623. }
  10624. }
  10625. if(result == PASS)
  10626. {
  10627. if(connectorIdInt > 0)
  10628. {
  10629. //check Transaction active
  10630. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10631. {
  10632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10633. {
  10634. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10635. }
  10636. else
  10637. {
  10638. tempIndex = connectorIdInt -1;
  10639. }
  10640. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10641. {
  10642. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10643. {
  10644. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10645. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10646. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10647. {
  10648. //Reserved
  10649. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10650. }
  10651. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10652. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10653. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10654. {
  10655. //Reserved
  10656. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10657. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10658. goto end;
  10659. }
  10660. else
  10661. {
  10662. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10663. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10664. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10665. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10666. {
  10667. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10668. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10669. goto end;
  10670. }
  10671. }//END FOR ELSE
  10672. }
  10673. }// END FOR CHAdeMO_QUANTITY
  10674. }
  10675. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10676. {
  10677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10678. {
  10679. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10680. }
  10681. else
  10682. {
  10683. tempIndex = connectorIdInt -1;
  10684. }
  10685. for (int index = 0; index < CCS_QUANTITY; index++)
  10686. {
  10687. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10688. {
  10689. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10690. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10691. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10692. {
  10693. //Reserved
  10694. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10695. }
  10696. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10697. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10698. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10699. {
  10700. //Reserved
  10701. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10702. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10703. goto end;
  10704. }
  10705. else
  10706. {
  10707. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10708. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10709. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10710. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10711. {
  10712. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10713. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10714. goto end;
  10715. }
  10716. }// END FOR ELSE
  10717. }
  10718. }// END FOR CCS_QUANTITY
  10719. }
  10720. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10721. {
  10722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10723. {
  10724. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10725. }
  10726. else
  10727. {
  10728. tempIndex = connectorIdInt -1;
  10729. }
  10730. for (int index = 0; index < GB_QUANTITY; index++)
  10731. {
  10732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10733. {
  10734. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10736. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10737. {
  10738. //Reserved
  10739. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10740. }
  10741. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10742. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10743. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10744. {
  10745. //Reserved
  10746. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10747. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10748. goto end;
  10749. }
  10750. else
  10751. {
  10752. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10753. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10754. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10755. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10756. {
  10757. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10758. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10759. goto end;
  10760. }
  10761. }// END FOR ELSE
  10762. }
  10763. } // END FOR GB_QUANTITY
  10764. }
  10765. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10766. {
  10767. tempIndex = connectorIdInt -1;
  10768. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10769. {
  10770. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10771. {
  10772. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10773. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10774. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10775. {
  10776. //Reserved
  10777. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10778. }
  10779. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10780. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10781. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10782. {
  10783. //Reserved
  10784. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10785. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10786. goto end;
  10787. }
  10788. else
  10789. {
  10790. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10791. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10792. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10793. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10794. {
  10795. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10796. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10797. goto end;
  10798. }
  10799. }// END FOR ELSE
  10800. }
  10801. } // END FOR GB_QUANTITY
  10802. }
  10803. else
  10804. {
  10805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10806. {
  10807. tempIndex = 2;
  10808. }
  10809. else
  10810. {
  10811. tempIndex = connectorIdInt -1;
  10812. }
  10813. for (int index = 0; index < AC_QUANTITY; index++)
  10814. {
  10815. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10816. {
  10817. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10818. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10819. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10820. {
  10821. //Reserved
  10822. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10823. }
  10824. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10825. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10826. (strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10827. {
  10828. //Reserved
  10829. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10830. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10831. goto end;
  10832. }
  10833. else
  10834. {
  10835. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10836. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10837. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10838. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10839. {
  10840. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10841. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10842. goto end;
  10843. }
  10844. }//END FOR ELSE
  10845. }
  10846. }// END FOR AC_QUANTITY
  10847. }
  10848. if(ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10849. {
  10850. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10851. {
  10852. // Save profile to file
  10853. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10854. system(cmdBuf);
  10855. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10856. fp = fopen(cmdBuf, "w");
  10857. 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));
  10858. fclose(fp);
  10859. }
  10860. else
  10861. {
  10862. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10863. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10864. goto end;
  10865. }
  10866. }
  10867. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10868. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10869. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10870. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10871. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10873. }
  10874. else
  10875. {
  10876. uint8_t isHasIdleConnector = FALSE;
  10877. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10878. {
  10879. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10880. {
  10881. isHasIdleConnector = TRUE;
  10882. break;
  10883. }
  10884. }
  10885. if(isHasIdleConnector == TRUE)
  10886. {
  10887. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10888. if(ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10889. {
  10890. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10891. {
  10892. // Save profile to file
  10893. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_Tmp.json");
  10894. system(cmdBuf);
  10895. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_Tmp.json");
  10896. fp = fopen(cmdBuf, "w");
  10897. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10898. fclose(fp);
  10899. refreshStartTimer(&clientTime.RemoteStartWait);
  10900. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10901. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10902. }
  10903. else
  10904. {
  10905. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10906. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10907. }
  10908. }
  10909. else
  10910. {
  10911. refreshStartTimer(&clientTime.RemoteStartWait);
  10912. ShmOCPP16DataPH->MsMsg.bits.isRemoteStartWaitReq = 1;
  10913. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10914. }
  10915. }
  10916. else
  10917. {
  10918. DEBUG_INFO("There is not any connector is idle.\n");
  10919. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10920. }
  10921. }
  10922. }
  10923. else
  10924. {
  10925. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10926. }
  10927. end:
  10928. json_object_put(RemoteStartTransaction);
  10929. sendRemoteStartConfirmation(uuid, comfirmstr);
  10930. return result;
  10931. }
  10932. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10933. {
  10934. mtrace();
  10935. int result = FAIL;
  10936. int match = FALSE;
  10937. int GunNO = 0;
  10938. int tempIndex = 0;
  10939. int transactionIdInt=0;
  10940. int transactionIdIsNULL= TRUE;
  10941. char comfirmstr[20];
  10942. json_object *RemoteStopTransaction;
  10943. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10944. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10945. if(server_pending == TRUE)
  10946. {
  10947. return 0;
  10948. }
  10949. RemoteStopTransaction = json_tokener_parse(payload);
  10950. if(!is_error(RemoteStopTransaction))
  10951. {
  10952. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10953. {
  10954. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10955. transactionIdIsNULL = FALSE;
  10956. }
  10957. }
  10958. json_object_put(RemoteStopTransaction);
  10959. if(transactionIdIsNULL == FALSE)
  10960. {
  10961. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10962. {
  10963. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10964. {
  10965. //check Transaction active
  10966. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10967. {
  10968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10969. {
  10970. tempIndex = ((gun_index==2) ? 1: 0);
  10971. }
  10972. else
  10973. {
  10974. tempIndex = gun_index;
  10975. }
  10976. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10977. {
  10978. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10979. {
  10980. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10981. {
  10982. match = TRUE;
  10983. GunNO = gun_index;
  10984. }
  10985. }
  10986. }// END FOR CHAdeMO_QUANTITY
  10987. }
  10988. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10989. {
  10990. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10991. {
  10992. tempIndex = ((gun_index==2) ? 1: 0);
  10993. }
  10994. else
  10995. {
  10996. tempIndex = gun_index;
  10997. }
  10998. for (int index = 0; index < CCS_QUANTITY; index++)
  10999. {
  11000. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11001. {
  11002. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11003. {
  11004. match = TRUE;
  11005. GunNO = gun_index;
  11006. }
  11007. }
  11008. }// END FOR CCS_QUANTITY
  11009. }
  11010. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11011. {
  11012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11013. {
  11014. tempIndex = ((gun_index==2) ? 1: 0);
  11015. }
  11016. else
  11017. {
  11018. tempIndex = gun_index;
  11019. }
  11020. for (int index = 0; index < GB_QUANTITY; index++)
  11021. {
  11022. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11023. {
  11024. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11025. {
  11026. match = TRUE;
  11027. GunNO = gun_index;
  11028. }
  11029. }
  11030. }// END FOR GB_QUANTITY
  11031. }
  11032. else if(gunType[gun_index] == GUN_TYPE_DO)
  11033. {
  11034. tempIndex = gun_index;
  11035. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11036. {
  11037. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11038. {
  11039. 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
  11040. {
  11041. match = TRUE;
  11042. GunNO = gun_index;
  11043. }
  11044. }
  11045. }// END FOR GB_QUANTITY
  11046. }
  11047. else
  11048. {
  11049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11050. {
  11051. tempIndex = 2;
  11052. }
  11053. else
  11054. {
  11055. tempIndex = gun_index;
  11056. }
  11057. for (int index = 0; index < AC_QUANTITY; index++)
  11058. {
  11059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11060. {
  11061. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11062. {
  11063. match = TRUE;
  11064. GunNO = gun_index;
  11065. }
  11066. }
  11067. }// END FOR CHAdeMO_QUANTITY
  11068. } // END FOR AC ELSE
  11069. }// CHECK IF ResponseTransactionId == transactionIdInt
  11070. }//END FOR
  11071. if( match == TRUE)
  11072. {
  11073. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  11074. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  11075. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  11076. }
  11077. else
  11078. {
  11079. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11080. }
  11081. }
  11082. else
  11083. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  11084. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  11085. return result;
  11086. }
  11087. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  11088. {
  11089. mtrace();
  11090. int result = FAIL;
  11091. int connectorIdInt=0, reservationIdInt=0;
  11092. int tempIndex = 0;
  11093. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  11094. char comfirmstr[20]={0};
  11095. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  11096. int c = 0;
  11097. char *loc;
  11098. //char *ptr;
  11099. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  11100. strcpy(sstrtemp, stringtrimspace(payload));
  11101. //***(1)connectorId ****/
  11102. c=0;
  11103. loc = strstr(sstrtemp, "connectorId");
  11104. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11105. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  11106. {
  11107. sstr[c] = loc[strlen("connectorId")+2+c];
  11108. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11109. c++;
  11110. }
  11111. sstr[c] = '\0';
  11112. connectorIdInt = atoi(sstr);
  11113. //***(2)expiryDate ****/
  11114. loc = strstr(sstrtemp, "expiryDate");
  11115. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11116. c = 0;
  11117. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  11118. {
  11119. sstr[c] = loc[3+strlen("expiryDate")+c];
  11120. c++;
  11121. }
  11122. sstr[c] = '\0';
  11123. strcpy(expiryDatestr, sstr);
  11124. //***(3)idTag ****/
  11125. loc = strstr(sstrtemp, "idTag");
  11126. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11127. c = 0;
  11128. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  11129. {
  11130. sstr[c] = loc[3+strlen("idTag")+c];
  11131. c++;
  11132. }
  11133. sstr[c] = '\0';
  11134. strcpy(idTagstr, sstr);
  11135. //***(4)parentIdTag ****/
  11136. loc = strstr(sstrtemp, "parentIdTag");
  11137. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11138. c = 0;
  11139. if(loc == NULL)
  11140. {
  11141. strcpy(parentIdTagstr, "");
  11142. }
  11143. else
  11144. {
  11145. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  11146. {
  11147. sstr[c] = loc[3+strlen("parentIdTag")+c];
  11148. c++;
  11149. }
  11150. sstr[c] = '\0';
  11151. strcpy(parentIdTagstr, sstr);
  11152. }
  11153. //***(5)reservationId ****/
  11154. c=0;
  11155. loc = strstr(sstrtemp, "reservationId");
  11156. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11157. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  11158. {
  11159. sstr[c] = loc[strlen("reservationId")+2+c];
  11160. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11161. c++;
  11162. }
  11163. sstr[c] = '\0';
  11164. reservationIdInt = atoi(sstr);
  11165. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11166. /*
  11167. enum SYSTEM_STATUS
  11168. {
  11169. SYS_MODE_BOOTING = 0,
  11170. SYS_MODE_IDLE = 1,
  11171. SYS_MODE_AUTHORIZING = 2,
  11172. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  11173. SYS_MODE_REASSIGN = 4,
  11174. SYS_MODE_PREPARING = 5,
  11175. SYS_MODE_PREPARE_FOR_EV = 6,
  11176. SYS_MODE_PREPARE_FOR_EVSE = 7,
  11177. SYS_MODE_CHARGING = 8,
  11178. SYS_MODE_TERMINATING = 9,
  11179. SYS_MODE_COMPLETE = 10,
  11180. SYS_MODE_ALARM = 11,
  11181. SYS_MODE_FAULT = 12,
  11182. SYS_MODE_RESERVATION = 13,
  11183. SYS_MODE_BOOKING = 14,
  11184. SYS_MODE_MAINTAIN = 15,
  11185. SYS_MODE_DEBUG = 16,
  11186. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  11187. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  11188. SYS_MODE_UPDATE = 19
  11189. };
  11190. */
  11191. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  11192. {
  11193. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11194. goto end;
  11195. }
  11196. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11197. {
  11198. //check Transaction active
  11199. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11200. {
  11201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11202. {
  11203. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11204. }
  11205. else
  11206. {
  11207. tempIndex = connectorIdInt -1;
  11208. }
  11209. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11210. {
  11211. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11212. {
  11213. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11214. {
  11215. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11216. {
  11217. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11218. {
  11219. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11221. }
  11222. 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'))
  11223. {
  11224. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11225. }
  11226. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11227. {
  11228. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11229. }
  11230. else
  11231. {
  11232. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11233. }
  11234. }
  11235. 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
  11236. {
  11237. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11238. }
  11239. }
  11240. else
  11241. {
  11242. //replace reservation
  11243. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11244. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11245. }
  11246. }
  11247. } // END FOR CHAdeMO_QUANTITY
  11248. }
  11249. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11250. {
  11251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11252. {
  11253. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11254. }
  11255. else
  11256. {
  11257. tempIndex = connectorIdInt -1;
  11258. }
  11259. for (int index = 0; index < CCS_QUANTITY; index++)
  11260. {
  11261. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11262. {
  11263. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11264. {
  11265. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11266. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11267. {
  11268. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11269. {
  11270. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11272. }
  11273. 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'))
  11274. {
  11275. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11276. }
  11277. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11278. {
  11279. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11280. }
  11281. else
  11282. {
  11283. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11284. }
  11285. }
  11286. 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
  11287. {
  11288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11289. }
  11290. }
  11291. else
  11292. {
  11293. //replace reservation
  11294. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11295. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11296. }
  11297. }
  11298. } // END FOR CCS_QUANTITY
  11299. }
  11300. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11301. {
  11302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11303. {
  11304. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11305. }
  11306. else
  11307. {
  11308. tempIndex = connectorIdInt -1;
  11309. }
  11310. for (int index = 0; index < GB_QUANTITY; index++)
  11311. {
  11312. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11313. {
  11314. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11315. {
  11316. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11317. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11318. {
  11319. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11320. {
  11321. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11322. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11323. }
  11324. 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'))
  11325. {
  11326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11327. }
  11328. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11329. {
  11330. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11331. }
  11332. else
  11333. {
  11334. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11335. }
  11336. }
  11337. 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
  11338. {
  11339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11340. }
  11341. }
  11342. else
  11343. {
  11344. //replace reservation
  11345. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11346. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11347. }
  11348. }
  11349. }// END FOR GB_QUANTITY
  11350. }
  11351. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11352. {
  11353. tempIndex = connectorIdInt -1;
  11354. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11355. {
  11356. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11357. {
  11358. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11359. {
  11360. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11361. 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
  11362. {
  11363. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11364. {
  11365. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11366. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11367. }
  11368. 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'))
  11369. {
  11370. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11371. }
  11372. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11373. {
  11374. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11375. }
  11376. else
  11377. {
  11378. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11379. }
  11380. }
  11381. 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
  11382. {
  11383. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11384. }
  11385. }
  11386. else
  11387. {
  11388. //replace reservation
  11389. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11390. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11391. }
  11392. }
  11393. }// END FOR GB_QUANTITY
  11394. }
  11395. else
  11396. {
  11397. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11398. {
  11399. tempIndex = 2;
  11400. }
  11401. else
  11402. {
  11403. tempIndex = (connectorIdInt -1);
  11404. }
  11405. for (int index = 0; index < AC_QUANTITY; index++)
  11406. {
  11407. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11408. {
  11409. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11410. {
  11411. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11412. {
  11413. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11414. {
  11415. 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))
  11416. {
  11417. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11418. }
  11419. else
  11420. {
  11421. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11422. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11423. }
  11424. }
  11425. 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'))
  11426. {
  11427. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11428. }
  11429. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11430. {
  11431. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11432. }
  11433. else
  11434. {
  11435. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11436. }
  11437. }
  11438. 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
  11439. {
  11440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11441. }
  11442. }
  11443. else
  11444. {
  11445. //replace reservation
  11446. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11448. }
  11449. }
  11450. } // END FOR AC_QUANTITY
  11451. }
  11452. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11453. }
  11454. else if(connectorIdInt == 0)
  11455. {
  11456. //check Transaction active
  11457. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11458. {
  11459. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11460. {
  11461. 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'))
  11462. {
  11463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11464. goto end;
  11465. }
  11466. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11467. {
  11468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11469. goto end;
  11470. }
  11471. 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
  11472. {
  11473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11474. goto end;
  11475. }
  11476. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11477. {
  11478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11479. goto end;
  11480. }
  11481. }
  11482. }// END FOR CHAdeMO_QUANTITY
  11483. for (int index = 0; index < CCS_QUANTITY; index++)
  11484. {
  11485. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11486. {
  11487. 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'))
  11488. {
  11489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11490. goto end;
  11491. }
  11492. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11493. {
  11494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11495. goto end;
  11496. }
  11497. 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
  11498. {
  11499. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11500. goto end;
  11501. }
  11502. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11503. {
  11504. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11505. goto end;
  11506. }
  11507. }
  11508. } // END FOR CCS_QUANTITY
  11509. for (int index = 0; index < GB_QUANTITY; index++)
  11510. {
  11511. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11512. {
  11513. 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'))
  11514. {
  11515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11516. goto end;
  11517. }
  11518. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11519. {
  11520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11521. goto end;
  11522. }
  11523. 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
  11524. {
  11525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11526. goto end;
  11527. }
  11528. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11529. {
  11530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11531. goto end;
  11532. }
  11533. }
  11534. } // END FOR GB_QUANTITY
  11535. for (int index = 0; index < AC_QUANTITY; index++)
  11536. {
  11537. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11538. {
  11539. 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'))
  11540. {
  11541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11542. goto end;
  11543. }
  11544. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11545. {
  11546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11547. goto end;
  11548. }
  11549. 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
  11550. {
  11551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11552. goto end;
  11553. }
  11554. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11555. {
  11556. 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))
  11557. {
  11558. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11559. goto end;
  11560. }
  11561. }
  11562. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11563. {
  11564. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11565. goto end;
  11566. }
  11567. }
  11568. }// END FOR AC_QUANTITY
  11569. //The connectorId is 0
  11570. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  11571. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11572. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11573. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  11574. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11575. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  11576. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11577. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  11578. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  11579. result = TRUE;
  11580. return result;
  11581. }
  11582. else
  11583. {
  11584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11585. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11586. }
  11587. if(strcmp(comfirmstr,"Accepted") == 0)
  11588. {
  11589. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11590. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11591. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11592. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11593. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11594. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  11595. result = TRUE;
  11596. return result;
  11597. }
  11598. end:
  11599. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11600. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11601. return result;
  11602. }
  11603. int handleResetRequest(char *uuid, char *payload)
  11604. {
  11605. mtrace();
  11606. int result = FAIL;
  11607. char sstr[10]={0},sstrtemp[30]={ 0 };
  11608. char typestr[10]={0};
  11609. char comfirmstr[20]={0};
  11610. int c = 0;
  11611. char *loc;
  11612. DEBUG_INFO("handleResetRequest...\n");
  11613. strcpy(sstrtemp, stringtrimspace(payload));
  11614. loc = strstr(sstrtemp, "type");
  11615. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11616. c = 0;
  11617. while (loc[3+strlen("type")+c] != '\"')
  11618. {
  11619. sstr[c] = loc[3+strlen("type")+c];
  11620. c++;
  11621. }
  11622. sstr[c] = '\0';
  11623. strcpy(typestr,sstr);
  11624. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11625. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11626. {
  11627. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11628. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  11629. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11630. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11631. }
  11632. else
  11633. {
  11634. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11635. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  11636. result = PASS;
  11637. }
  11638. sendResetConfirmation(uuid, comfirmstr);
  11639. return result;
  11640. }
  11641. int handleSendLocalListRequest(char *uuid, char *payload)
  11642. {
  11643. mtrace();
  11644. int result = FAIL;
  11645. char comfirmstr[20];
  11646. int checkState_Faulted = FALSE;
  11647. json_object *SendLocalList;
  11648. DEBUG_INFO("handleSendLocalListRequest...\n");
  11649. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11650. {
  11651. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11652. goto end;
  11653. }
  11654. //check Charge Point state
  11655. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11656. {
  11657. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11658. {
  11659. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11660. }
  11661. }
  11662. for (int index = 0; index < CCS_QUANTITY; index++)
  11663. {
  11664. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11665. {
  11666. checkState_Faulted = TRUE; //OCPP Status
  11667. }
  11668. }
  11669. for (int index = 0; index < GB_QUANTITY; index++)
  11670. {
  11671. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11672. {
  11673. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11674. }
  11675. }
  11676. //check Charge Point state
  11677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11678. {
  11679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11680. {
  11681. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11682. }
  11683. }
  11684. //check Charge Point state
  11685. for (int index = 0; index < AC_QUANTITY; index++)
  11686. {
  11687. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11688. {
  11689. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11690. }
  11691. }
  11692. if(checkState_Faulted == TRUE)
  11693. {
  11694. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11695. goto end;
  11696. }
  11697. // Parsing payload
  11698. SendLocalList = json_tokener_parse(payload);
  11699. if(!is_error(SendLocalList))
  11700. {
  11701. // Required data
  11702. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11703. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11704. // Optional data
  11705. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11706. {
  11707. //Check UpdateType
  11708. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11709. {
  11710. //Local list full update
  11711. DEBUG_INFO("Local list full update.\n");
  11712. OCPP_getListVerion();
  11713. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11714. {
  11715. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11716. goto end;
  11717. }
  11718. OCPP_cleanLocalList();
  11719. }
  11720. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11721. {
  11722. //Local list different update
  11723. DEBUG_INFO("Local list different update.\n");
  11724. OCPP_getListVerion();
  11725. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  11726. {
  11727. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11728. goto end;
  11729. }
  11730. }
  11731. else
  11732. {
  11733. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11734. goto end;
  11735. }
  11736. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11737. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11738. {
  11739. 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")));
  11740. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11741. {
  11742. 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")));
  11743. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11744. 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")));
  11745. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11746. 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")));
  11747. }
  11748. // Add to db
  11749. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11750. {
  11751. //Local list full update
  11752. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11753. idx,
  11754. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11755. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11756. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11757. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11758. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11759. // update list
  11760. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11761. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11762. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11763. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11764. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11765. }
  11766. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11767. {
  11768. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11769. idx,
  11770. ShmOCPP16DataPH->SendLocalList.ListVersion,
  11771. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11772. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11773. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11774. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11775. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  11776. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  11777. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11778. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11779. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11780. }
  11781. }
  11782. }
  11783. else
  11784. {
  11785. //Check UpdateType
  11786. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11787. {
  11788. //Local list full update
  11789. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11790. OCPP_cleanLocalList();
  11791. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11792. goto end;
  11793. }
  11794. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11795. {
  11796. //Local list different update
  11797. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11798. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11799. goto end;
  11800. }
  11801. }
  11802. result = PASS;
  11803. }
  11804. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11805. end:
  11806. json_object_put(SendLocalList);
  11807. sendSendLocalListConfirmation(uuid, comfirmstr);
  11808. return result;
  11809. }
  11810. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11811. {
  11812. mtrace();
  11813. int result = FAIL;
  11814. struct StructSetChargingProfile SetProfileReq = {0};
  11815. int tempchargingProfileIdInt;
  11816. int tempstackLevelInt;
  11817. int chargingSchedulePeriodCount = 0;
  11818. char comfirmstr[20]={0};
  11819. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  11820. char rmFileCmd[128]={0};
  11821. int profileQuantity = 0;
  11822. int isReplaceable = FALSE;
  11823. json_object *SetChargingProfile;
  11824. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11825. SetChargingProfile = json_tokener_parse(payload);
  11826. if(!is_error(SetChargingProfile))
  11827. {
  11828. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11829. {
  11830. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11831. }
  11832. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11833. {
  11834. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11835. {
  11836. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11837. }
  11838. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11839. {
  11840. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11841. }
  11842. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11843. {
  11844. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11845. }
  11846. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11847. {
  11848. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11849. }
  11850. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11851. {
  11852. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11853. }
  11854. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11855. {
  11856. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11857. }
  11858. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11859. {
  11860. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11861. }
  11862. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11863. {
  11864. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11865. }
  11866. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11867. {
  11868. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11869. {
  11870. 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")));
  11871. }
  11872. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11873. {
  11874. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11875. }
  11876. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11877. {
  11878. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11879. }
  11880. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11881. {
  11882. 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")));
  11883. }
  11884. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11885. {
  11886. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11887. if(chargingSchedulePeriodCount <= 10)
  11888. {
  11889. 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++)
  11890. {
  11891. 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)
  11892. {
  11893. 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"));
  11894. }
  11895. 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)
  11896. {
  11897. 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"));
  11898. }
  11899. 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)
  11900. {
  11901. 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"));
  11902. }
  11903. }
  11904. }
  11905. }
  11906. }
  11907. }
  11908. }
  11909. // Profile periods quantity check
  11910. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11911. {
  11912. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11913. goto end;
  11914. }
  11915. // Check invalid limit
  11916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11917. {
  11918. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11919. {
  11920. 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)))) ||
  11921. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11922. {
  11923. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11924. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11925. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11926. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11927. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11928. goto end;
  11929. }
  11930. }
  11931. }
  11932. else
  11933. {
  11934. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11935. {
  11936. 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))
  11937. {
  11938. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11939. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11940. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11941. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11942. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11943. goto end;
  11944. }
  11945. }
  11946. }
  11947. // Profile purpose info check
  11948. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11949. {
  11950. FILE *fp;
  11951. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11952. if(SetProfileReq.ConnectorId != 0)
  11953. {
  11954. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11955. goto end;
  11956. }
  11957. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11958. if (!fp)
  11959. {
  11960. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11961. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11962. }
  11963. else
  11964. {
  11965. char *line = NULL;
  11966. size_t len = 0;
  11967. while(getline(&line, &len, fp) != -1)
  11968. {
  11969. json_object *obj = NULL;
  11970. obj = json_tokener_parse(line);
  11971. if(is_error(obj))
  11972. {
  11973. DEBUG_ERROR("Parse txProfile from file error.\n");
  11974. }
  11975. else
  11976. {
  11977. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  11978. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  11979. {
  11980. profileQuantity += 1;
  11981. }
  11982. else
  11983. isReplaceable = TRUE;
  11984. }
  11985. }
  11986. }
  11987. fclose(fp);
  11988. }
  11989. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11990. {
  11991. FILE *fp;
  11992. char filename[128]={0};
  11993. int tmpProfileQuantity;
  11994. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11995. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11996. {
  11997. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11998. goto end;
  11999. }
  12000. if(SetProfileReq.ConnectorId == 0)
  12001. {
  12002. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  12003. {
  12004. tmpProfileQuantity = 0;
  12005. memset(filename, 0, ARRAY_SIZE(filename));
  12006. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12007. fp = fopen(filename, "r");
  12008. if (!fp)
  12009. {
  12010. DEBUG_INFO("%s does not create.\n", filename);
  12011. fp = fopen(filename, "w+");
  12012. }
  12013. else
  12014. {
  12015. char *line = NULL;
  12016. size_t len = 0;
  12017. while(getline(&line, &len, fp) != -1)
  12018. {
  12019. json_object *obj = NULL;
  12020. obj = json_tokener_parse(line);
  12021. if(is_error(obj))
  12022. {
  12023. DEBUG_ERROR("Parse txProfile from file error.\n");
  12024. }
  12025. else
  12026. {
  12027. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12028. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12029. {
  12030. tmpProfileQuantity += 1;
  12031. }
  12032. else
  12033. isReplaceable = TRUE;
  12034. }
  12035. }
  12036. }
  12037. fclose(fp);
  12038. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  12039. }
  12040. }
  12041. else
  12042. {
  12043. memset(filename, 0, ARRAY_SIZE(filename));
  12044. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12045. fp = fopen(filename, "r");
  12046. if (!fp)
  12047. {
  12048. DEBUG_INFO("%s does not create.\n", filename);
  12049. fp = fopen(filename, "w+");
  12050. }
  12051. else
  12052. {
  12053. char *line = NULL;
  12054. size_t len = 0;
  12055. while(getline(&line, &len, fp) != -1)
  12056. {
  12057. json_object *obj = NULL;
  12058. obj = json_tokener_parse(line);
  12059. if(is_error(obj))
  12060. {
  12061. DEBUG_ERROR("Parse txProfile from file error.\n");
  12062. }
  12063. else
  12064. {
  12065. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12066. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12067. {
  12068. profileQuantity += 1;
  12069. }
  12070. else
  12071. isReplaceable = TRUE;
  12072. }
  12073. }
  12074. }
  12075. fclose(fp);
  12076. }
  12077. }
  12078. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  12079. {
  12080. int isMatchTransactiodId= FALSE;
  12081. FILE *fp;
  12082. char filename[128]={0};
  12083. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  12084. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  12085. if(SetProfileReq.ConnectorId == 0)
  12086. {
  12087. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12088. goto end;
  12089. }
  12090. int tempIndex = 0;
  12091. //check Transaction active
  12092. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  12093. {
  12094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12095. {
  12096. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12097. }
  12098. else
  12099. {
  12100. tempIndex = SetProfileReq.ConnectorId -1;
  12101. }
  12102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12103. {
  12104. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12105. {
  12106. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12107. {
  12108. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12109. {
  12110. isMatchTransactiodId = TRUE;
  12111. break;
  12112. }
  12113. }
  12114. }
  12115. }
  12116. }
  12117. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  12118. {
  12119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12120. {
  12121. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12122. }
  12123. else
  12124. {
  12125. tempIndex = SetProfileReq.ConnectorId -1;
  12126. }
  12127. for (int index = 0; index < CCS_QUANTITY; index++)
  12128. {
  12129. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12130. {
  12131. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  12132. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12133. {
  12134. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12135. {
  12136. isMatchTransactiodId = TRUE;
  12137. break;
  12138. }
  12139. }
  12140. }
  12141. }
  12142. }
  12143. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  12144. {
  12145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12146. {
  12147. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  12148. }
  12149. else
  12150. {
  12151. tempIndex = SetProfileReq.ConnectorId -1;
  12152. }
  12153. for (int index = 0; index < GB_QUANTITY; index++)
  12154. {
  12155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12156. {
  12157. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  12158. {
  12159. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12160. {
  12161. isMatchTransactiodId = TRUE;
  12162. break;
  12163. }
  12164. }
  12165. }
  12166. }
  12167. }
  12168. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  12169. {
  12170. tempIndex = SetProfileReq.ConnectorId -1;
  12171. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12172. {
  12173. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12174. {
  12175. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  12176. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  12177. {
  12178. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12179. {
  12180. isMatchTransactiodId = TRUE;
  12181. break;
  12182. }
  12183. }
  12184. }
  12185. }
  12186. }
  12187. else
  12188. {
  12189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12190. {
  12191. tempIndex = 2;
  12192. }
  12193. else
  12194. {
  12195. tempIndex = (SetProfileReq.ConnectorId -1);
  12196. }
  12197. for (int index = 0; index < AC_QUANTITY; index++)
  12198. {
  12199. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12200. {
  12201. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  12202. {
  12203. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  12204. {
  12205. isMatchTransactiodId = TRUE;
  12206. break;
  12207. }
  12208. }
  12209. }
  12210. }
  12211. }
  12212. //check Transaction active
  12213. if(isMatchTransactiodId == FALSE)
  12214. {
  12215. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12216. goto end;
  12217. }
  12218. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  12219. {
  12220. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12221. goto end;
  12222. }
  12223. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12224. fp = fopen(filename, "r");
  12225. if (!fp)
  12226. {
  12227. DEBUG_INFO("%s does not create.\n", filename);
  12228. fp = fopen(filename, "w+");
  12229. }
  12230. else
  12231. {
  12232. char *line = NULL;
  12233. size_t len = 0;
  12234. while(getline(&line, &len, fp) != -1)
  12235. {
  12236. json_object *obj = NULL;
  12237. obj = json_tokener_parse(line);
  12238. if(is_error(obj))
  12239. {
  12240. DEBUG_ERROR("Parse txProfile from file error.\n");
  12241. }
  12242. else
  12243. {
  12244. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != SetProfileReq.ChargingProfile.ChargingProfileId) &&
  12245. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) != SetProfileReq.ChargingProfile.StackLevel))
  12246. {
  12247. profileQuantity += 1;
  12248. }
  12249. else
  12250. isReplaceable = TRUE;
  12251. }
  12252. }
  12253. }
  12254. fclose(fp);
  12255. }
  12256. // Check ChargeProfileMaxStackLevel
  12257. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  12258. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  12259. {
  12260. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12261. goto end;
  12262. }
  12263. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12264. {
  12265. FILE *fp;
  12266. char dataLine[4096]={0};
  12267. char fnametemp[128]={0};
  12268. int tmpProfileQuantity;
  12269. //Check ChargePointMaxProfile.json exit
  12270. profileQuantity = 0;
  12271. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  12272. {
  12273. fp = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  12274. //Check Charging Profile Count
  12275. tmpProfileQuantity = 0;
  12276. while(fscanf(fp, "%s", dataLine) != EOF)
  12277. {
  12278. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12279. {
  12280. profileQuantity += 1;
  12281. tmpProfileQuantity += 1;
  12282. }
  12283. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12284. }
  12285. fclose(fp);
  12286. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  12287. }
  12288. //Check TxDefaultProfile_%d.json
  12289. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12290. {
  12291. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12292. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12293. if((access(fnametemp,F_OK))!=-1)
  12294. {
  12295. fp = fopen(fnametemp, "r");
  12296. //Check Charging Profile Count
  12297. tmpProfileQuantity = 0;
  12298. while(fscanf(fp, "%s", dataLine) != EOF)
  12299. {
  12300. //DEBUG_INFO("word=%s\n",word);
  12301. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12302. {
  12303. profileQuantity += 1;
  12304. tmpProfileQuantity += 1;
  12305. }
  12306. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12307. }
  12308. fclose(fp);
  12309. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12310. }
  12311. }
  12312. //Check TxProfile_%d.json
  12313. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  12314. {
  12315. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12316. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", idxCon);
  12317. if((access(fnametemp,F_OK))!=-1)
  12318. {
  12319. fp = fopen(fnametemp, "r");
  12320. //Check Charging Profile Count
  12321. tmpProfileQuantity = 0;
  12322. while(fscanf(fp, "%s", dataLine) != EOF)
  12323. {
  12324. if(strstr(dataLine, "chargingProfileId")!= NULL)
  12325. {
  12326. profileQuantity += 1;
  12327. tmpProfileQuantity += 1;
  12328. }
  12329. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  12330. }
  12331. fclose(fp);
  12332. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  12333. }
  12334. }
  12335. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  12336. if((profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData)) && (isReplaceable != TRUE))
  12337. {
  12338. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  12339. goto end;
  12340. }
  12341. }
  12342. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  12343. //**********************************Write to File********************************************************/
  12344. {
  12345. FILE *infile;
  12346. FILE *outfile;
  12347. char dataLine[4096]={0};
  12348. char filename[128]={0};
  12349. int chkChar=0;
  12350. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  12351. {
  12352. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  12353. {
  12354. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  12355. }
  12356. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  12357. {
  12358. if(SetProfileReq.ConnectorId==0)
  12359. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", idxCon);
  12360. else
  12361. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  12362. }
  12363. else
  12364. {
  12365. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", SetProfileReq.ConnectorId);
  12366. }
  12367. infile = fopen (filename, "r");
  12368. outfile = fopen (tempfile, "w");
  12369. chkChar = fgetc(infile);
  12370. rewind(infile);
  12371. if(chkChar == EOF)
  12372. {
  12373. // Profile is empty
  12374. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12375. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12376. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12377. fclose(infile);
  12378. fclose(outfile);
  12379. sprintf(rmFileCmd,"rm -f %s",filename);
  12380. system(rmFileCmd);
  12381. rename(tempfile, filename);
  12382. }
  12383. else
  12384. {
  12385. // Profile is not empty
  12386. int ChargingProfileAdded = FALSE;
  12387. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  12388. {
  12389. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  12390. json_object *tmpChargingProfile;
  12391. tmpChargingProfile = json_tokener_parse(dataLine);
  12392. if(!is_error(SetChargingProfile))
  12393. {
  12394. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12395. {
  12396. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12397. {
  12398. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12399. }
  12400. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12401. {
  12402. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12403. }
  12404. }
  12405. }
  12406. json_object_put(tmpChargingProfile);
  12407. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12408. {
  12409. if(ChargingProfileAdded == FALSE)
  12410. {
  12411. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12412. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12413. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12414. ChargingProfileAdded = TRUE;
  12415. }
  12416. }
  12417. else if(tempstackLevelInt == SetProfileReq.ChargingProfile.StackLevel)
  12418. {
  12419. if(ChargingProfileAdded == FALSE)
  12420. {
  12421. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12422. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12423. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12424. ChargingProfileAdded = TRUE;
  12425. }
  12426. }
  12427. else
  12428. {
  12429. fprintf(outfile,"%s\n",dataLine);
  12430. if(ChargingProfileAdded == FALSE)
  12431. {
  12432. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12433. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12434. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12435. ChargingProfileAdded = TRUE;
  12436. }
  12437. }
  12438. } // end of while loop
  12439. fclose(infile);
  12440. fclose(outfile);
  12441. sprintf(rmFileCmd,"rm -f %s",filename);
  12442. system(rmFileCmd);
  12443. rename(tempfile, filename);
  12444. }
  12445. }
  12446. sleep(1);
  12447. result = TRUE;
  12448. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12449. }
  12450. end:
  12451. json_object_put(SetChargingProfile);
  12452. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12453. {
  12454. if(SetProfileReq.ConnectorId == 0)
  12455. {
  12456. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12457. {
  12458. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  12459. }
  12460. }
  12461. else
  12462. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12463. }
  12464. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12465. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12466. return result;
  12467. }
  12468. int handleTriggerMessageRequest(char *uuid, char *payload)
  12469. {
  12470. mtrace();
  12471. int result = FAIL;
  12472. int connectorIdIsNULL = FALSE;
  12473. int connectorIdInt =0;
  12474. char sstr[40]={0},sstrtemp[100]={ 0 };
  12475. char requestedMessagestr[40]={0};
  12476. char comfirmstr[20]={0};
  12477. int c = 0;
  12478. char *loc;
  12479. DEBUG_INFO("handleTriggerMessageRequest\n");
  12480. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12481. strcpy(sstrtemp, stringtrimspace(payload));
  12482. c = 0;
  12483. loc = strstr(sstrtemp, "requestedMessage");
  12484. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12485. {
  12486. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12487. c++;
  12488. }
  12489. sstr[c] = '\0';
  12490. strcpy(requestedMessagestr, sstr);
  12491. c = 0;
  12492. loc = strstr(sstrtemp, "connectorId");
  12493. if(loc == NULL)
  12494. {
  12495. connectorIdIsNULL = TRUE;
  12496. }
  12497. else
  12498. {
  12499. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12500. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12501. {
  12502. sstr[c] = loc[strlen("connectorId")+2+c];
  12503. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12504. c++;
  12505. }
  12506. sstr[c] = '\0';
  12507. connectorIdInt = atoi(sstr);
  12508. }
  12509. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12510. {
  12511. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12512. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12513. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12514. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12515. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12516. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12517. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12518. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12519. {
  12520. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12521. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12522. return TRUE;
  12523. }
  12524. else
  12525. {
  12526. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12527. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12528. }
  12529. }
  12530. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12531. {
  12532. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12533. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12534. return TRUE;
  12535. }
  12536. //==========================
  12537. // Trigger message
  12538. //==========================
  12539. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12540. {
  12541. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  12542. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12543. {
  12544. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12545. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12546. }
  12547. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12548. }
  12549. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12550. {
  12551. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  12552. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12553. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12554. }
  12555. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12556. {
  12557. //sendBootNotificationRequest();
  12558. server_sign = FALSE;
  12559. }
  12560. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12561. {
  12562. refreshStartTimer(&clientTime.Heartbeat);
  12563. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  12564. }
  12565. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12566. {
  12567. if(connectorIdIsNULL == FALSE)
  12568. {
  12569. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12570. {
  12571. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12572. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12573. }
  12574. }
  12575. else
  12576. {
  12577. for(int idx=0;idx< gunTotalNumber;idx++)
  12578. {
  12579. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12580. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12581. }
  12582. }
  12583. }
  12584. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12585. {
  12586. if(connectorIdIsNULL == FALSE)
  12587. {
  12588. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12589. {
  12590. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12591. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  12592. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12593. }
  12594. }
  12595. else
  12596. {
  12597. for(int idx=0;idx< gunTotalNumber;idx++)
  12598. {
  12599. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  12600. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12601. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12602. }
  12603. }
  12604. }
  12605. return result;
  12606. }
  12607. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12608. {
  12609. mtrace();
  12610. int result = FAIL;
  12611. int connectorIdInt =0;
  12612. char comfirmstr[20]={0};
  12613. int tempIndex = 0;
  12614. json_object *UnlockConnector;
  12615. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12616. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12617. UnlockConnector = json_tokener_parse(payload);
  12618. if(!is_error(UnlockConnector))
  12619. {
  12620. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12621. {
  12622. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12623. }
  12624. }
  12625. json_object_put(UnlockConnector);
  12626. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12627. if(gunTotalNumber == 0)
  12628. {
  12629. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12630. goto end;
  12631. }
  12632. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12633. {
  12634. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12635. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12636. goto end;
  12637. }
  12638. else
  12639. {
  12640. //check Transaction active
  12641. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12642. {
  12643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12644. {
  12645. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12646. }
  12647. else
  12648. {
  12649. tempIndex = connectorIdInt -1;
  12650. }
  12651. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12652. {
  12653. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12654. {
  12655. //stop Transaction
  12656. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12657. }
  12658. }
  12659. }
  12660. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12661. {
  12662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12663. {
  12664. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12665. }
  12666. else
  12667. {
  12668. tempIndex = connectorIdInt -1;
  12669. }
  12670. for (int index = 0; index < CCS_QUANTITY; index++)
  12671. {
  12672. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12673. {
  12674. //stop Transaction
  12675. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12676. }
  12677. }
  12678. }
  12679. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12680. {
  12681. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12682. {
  12683. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12684. }
  12685. else
  12686. {
  12687. tempIndex = connectorIdInt -1;
  12688. }
  12689. for (int index = 0; index < GB_QUANTITY; index++)
  12690. {
  12691. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12692. {
  12693. //stop Transaction
  12694. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12695. }
  12696. }
  12697. }
  12698. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12699. {
  12700. tempIndex = connectorIdInt -1;
  12701. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12702. {
  12703. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12704. {
  12705. //stop Transaction
  12706. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12707. }
  12708. }
  12709. }
  12710. else
  12711. {
  12712. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12713. {
  12714. tempIndex = 2;
  12715. }
  12716. else
  12717. {
  12718. tempIndex = connectorIdInt-1;
  12719. }
  12720. for (int index = 0; index < AC_QUANTITY; index++)
  12721. {
  12722. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12723. {
  12724. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12725. }
  12726. }
  12727. }
  12728. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12729. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  12730. result = TRUE;
  12731. return result;
  12732. }
  12733. end:
  12734. //json_object_put(obj); --- remove temporally
  12735. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12736. return result;
  12737. }
  12738. static char UpdateFirmwarepayloadData[300]={0};
  12739. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12740. {
  12741. mtrace();
  12742. int result = FAIL;
  12743. pthread_t t;
  12744. sendUpdateFirmwareConfirmation(uuid);
  12745. memset(UpdateFirmwarepayloadData, 0, 300);
  12746. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12747. if(!interLock.isUpdateFirmwareGoing)
  12748. {
  12749. interLock.isUpdateFirmwareGoing = 1;
  12750. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12751. sleep(1);
  12752. }
  12753. else
  12754. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12755. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  12756. return result;
  12757. }
  12758. void *UpdateFirmwareProcess(void *data)
  12759. {
  12760. pthread_detach(pthread_self());
  12761. mtrace();
  12762. int retriesInt =0, retryIntervalInt=0;
  12763. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  12764. int port=0;
  12765. char locationstr[512]={0}, retrieveDatestr[36]={0};
  12766. int isSuccess = 0;
  12767. char ftpbuf[512];
  12768. char temp[100];
  12769. char * pch;
  12770. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12771. json_object *UpdateFirmware;
  12772. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12773. if(!is_error(UpdateFirmware))
  12774. {
  12775. // Required data
  12776. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12777. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12778. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12779. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12780. // Optional data
  12781. if(json_object_object_get(UpdateFirmware, "retries"))
  12782. {
  12783. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12784. }
  12785. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12786. {
  12787. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12788. }
  12789. }
  12790. json_object_put(UpdateFirmware);
  12791. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12792. memset(path, 0, ARRAY_SIZE(path));
  12793. // Wait retrieveData
  12794. if(strlen(retrieveDatestr) > 10)
  12795. {
  12796. do
  12797. {
  12798. sleep(1);
  12799. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12800. }
  12801. // Ready to download
  12802. system("rm -f /mnt/*");
  12803. if(strncmp(locationstr,"http", 4) == 0)
  12804. {
  12805. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12806. sprintf(ftppath,"/%s", path);
  12807. DEBUG_INFO("locationstr: %s\n", locationstr);
  12808. DEBUG_INFO("protocol: %s\n",protocol);
  12809. DEBUG_INFO("host: %s\n",host);
  12810. DEBUG_INFO("path: %s\n",path);
  12811. DEBUG_INFO("ftppath: %s\n",ftppath);
  12812. int ftppathlen=strlen(ftppath);
  12813. int i=1;
  12814. char filenametemp[50];
  12815. while(i < ftppathlen)
  12816. {
  12817. int len=ftppathlen-i;
  12818. if(ftppath[len]== 47) // '/' ascll code: 47
  12819. {
  12820. DEBUG_INFO("compare '/' all right\n");
  12821. break;
  12822. }
  12823. i=i+1;
  12824. }
  12825. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12826. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12827. filenametemp[i+1] = 0;
  12828. do
  12829. {
  12830. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12831. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12832. sleep(1);
  12833. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12834. if(!isSuccess)
  12835. {
  12836. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12837. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12838. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12839. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12840. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12841. }
  12842. else
  12843. {
  12844. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12845. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12846. }
  12847. retriesInt--;
  12848. }while((isSuccess == 0)&&(retriesInt >= 0));
  12849. }
  12850. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12851. {
  12852. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12853. memset(temp, 0, ARRAY_SIZE(temp));
  12854. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12855. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12856. int ftppathlen=strlen(ftpbuf);
  12857. int i=1;
  12858. char filenametemp[50];
  12859. while(i < ftppathlen)
  12860. {
  12861. int len=ftppathlen-i;
  12862. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12863. {
  12864. DEBUG_INFO(" compare '/' all right\n");
  12865. break;
  12866. }
  12867. i=i+1;
  12868. }
  12869. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12870. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12871. filenametemp[i+1] = 0;
  12872. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12873. pch=strchr(temp,'@');
  12874. if(pch==NULL)
  12875. {
  12876. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12877. protocol, host, &port, path);
  12878. strcpy(user,"anonymous");
  12879. strcpy(password,"");
  12880. }
  12881. else
  12882. {
  12883. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12884. protocol, user, password, host, &port, path);
  12885. }
  12886. sscanf(host,"%[^/]%s",host1, path1);
  12887. sprintf(ftppath,"%s", path1);
  12888. //DEBUG_INFO("protocol =%s\n",protocol);
  12889. //DEBUG_INFO("user =%s\n",user);
  12890. //DEBUG_INFO("password =%s\n",password);
  12891. //DEBUG_INFO("host1 =%s\n",host1);
  12892. //DEBUG_INFO("port =%d\n",port);
  12893. //DEBUG_INFO("path1 =%s\n",path1);
  12894. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12895. //ftpFile(host, user, password, port, ftppath, fname);
  12896. //download firmware pthred
  12897. if(port == 0)
  12898. {
  12899. port = 21;
  12900. }
  12901. do
  12902. {
  12903. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12904. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12905. sleep(1);
  12906. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12907. if(!isSuccess)
  12908. {
  12909. //BulldogUtil.sleepMs(interval*1000);
  12910. DEBUG_INFO("Update firmware request and download file fail.\n");
  12911. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12912. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12913. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12914. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12915. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12916. }
  12917. else
  12918. {
  12919. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12920. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12921. }
  12922. retriesInt--;
  12923. }while((!isSuccess)&&(retriesInt >= 0));
  12924. }
  12925. else
  12926. {
  12927. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12928. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12929. sleep(1);
  12930. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12931. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12932. }
  12933. // OCPPPH only, must announce CSU upgrade firmware
  12934. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12935. interLock.isUpdateFirmwareGoing = 0;
  12936. pthread_exit(NULL);
  12937. }
  12938. int handleCertificateSignedRequest(char *uuid, char *payload)
  12939. {
  12940. mtrace();
  12941. int result = PASS;
  12942. json_object *CertificateSigned;
  12943. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12944. CertificateSigned = json_tokener_parse(payload);
  12945. if(!is_error(CertificateSigned))
  12946. {
  12947. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  12948. }
  12949. json_object_put(CertificateSigned);
  12950. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  12951. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  12952. fclose(fp);
  12953. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12954. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  12955. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  12956. sendCertificateSignedConfirmation(uuid);
  12957. return result;
  12958. }
  12959. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12960. {
  12961. mtrace();
  12962. int result = PASS;
  12963. json_object *DeleteCertificate;
  12964. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12965. DeleteCertificate = json_tokener_parse(payload);
  12966. if(!is_error(DeleteCertificate))
  12967. {
  12968. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12969. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12970. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12971. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12972. }
  12973. json_object_put(DeleteCertificate);
  12974. /*
  12975. * TODO: Delete certificateSigned process
  12976. */
  12977. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  12978. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  12979. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  12980. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  12981. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  12982. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  12983. sendDeleteCertificateConfirmation(uuid);
  12984. return result;
  12985. }
  12986. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12987. {
  12988. mtrace();
  12989. int result = PASS;
  12990. json_object *ExtendedTriggerMessage;
  12991. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12992. ExtendedTriggerMessage = json_tokener_parse(payload);
  12993. if(!is_error(ExtendedTriggerMessage))
  12994. {
  12995. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12996. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12997. {
  12998. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12999. }
  13000. else
  13001. {
  13002. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  13003. }
  13004. }
  13005. json_object_put(ExtendedTriggerMessage);
  13006. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  13007. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  13008. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  13009. {
  13010. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  13011. }
  13012. else
  13013. {
  13014. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  13015. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  13016. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  13017. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  13018. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  13019. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  13020. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  13021. {
  13022. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  13023. }
  13024. else
  13025. {
  13026. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  13027. }
  13028. }
  13029. sendExtendedTriggerMessageConfirmation(uuid);
  13030. //==========================
  13031. // Trigger message
  13032. //==========================
  13033. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  13034. {
  13035. //sendBootNotificationRequest();
  13036. server_sign = FALSE;
  13037. }
  13038. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  13039. {
  13040. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  13041. }
  13042. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  13043. {
  13044. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  13045. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  13046. {
  13047. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  13048. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  13049. }
  13050. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  13051. }
  13052. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  13053. {
  13054. refreshStartTimer(&clientTime.Heartbeat);
  13055. clientTime.Heartbeat.tv_sec -= ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  13056. }
  13057. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  13058. {
  13059. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13060. {
  13061. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  13062. }
  13063. else
  13064. {
  13065. for(int idx=0;idx< gunTotalNumber;idx++)
  13066. {
  13067. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13068. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  13069. }
  13070. }
  13071. }
  13072. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  13073. {
  13074. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  13075. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  13076. {
  13077. 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\" &");
  13078. }
  13079. }
  13080. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  13081. {
  13082. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  13083. {
  13084. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  13085. }
  13086. else
  13087. {
  13088. for(int idx=0;idx< gunTotalNumber;idx++)
  13089. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  13090. }
  13091. }
  13092. return result;
  13093. }
  13094. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13095. {
  13096. mtrace();
  13097. int result = PASS;
  13098. json_object *GetInstalledCertificateIds;
  13099. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13100. GetInstalledCertificateIds = json_tokener_parse(payload);
  13101. if(!is_error(GetInstalledCertificateIds))
  13102. {
  13103. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  13104. }
  13105. json_object_put(GetInstalledCertificateIds);
  13106. /*
  13107. * TODO: Return installed certificate process
  13108. */
  13109. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  13110. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  13111. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  13112. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  13113. sendGetInstalledCertificateIdsConfirmation(uuid);
  13114. return result;
  13115. }
  13116. int handleGetLogRequest(char *uuid, char *payload)
  13117. {
  13118. mtrace();
  13119. int result = PASS;
  13120. json_object *GetLog;
  13121. DEBUG_INFO("handleGetLogRequest...\n");
  13122. GetLog = json_tokener_parse(payload);
  13123. if(!is_error(GetLog))
  13124. {
  13125. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13126. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13127. if(json_object_object_get(GetLog, "retries") != NULL)
  13128. {
  13129. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13130. }
  13131. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13132. {
  13133. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13134. }
  13135. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13136. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13137. {
  13138. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13139. }
  13140. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13141. {
  13142. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13143. }
  13144. }
  13145. json_object_put(GetLog);
  13146. /*
  13147. * TODO: Upload log process
  13148. */
  13149. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  13150. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  13151. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  13152. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  13153. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  13154. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  13155. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  13156. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  13157. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  13158. sendGetLogConfirmation(uuid);
  13159. return result;
  13160. }
  13161. int handleInstallCertificateRequest(char *uuid, char *payload)
  13162. {
  13163. mtrace();
  13164. int result = PASS;
  13165. json_object *InstallCertificate;
  13166. DEBUG_INFO("handleInstallCertificateRequest...\n");
  13167. InstallCertificate = json_tokener_parse(payload);
  13168. if(!is_error(InstallCertificate))
  13169. {
  13170. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  13171. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  13172. /*
  13173. * TODO: Install certificate process
  13174. */
  13175. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  13176. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  13177. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  13178. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  13179. sendInstallCertificateConfirmation(uuid);
  13180. }
  13181. json_object_put(InstallCertificate);
  13182. return result;
  13183. }
  13184. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  13185. {
  13186. mtrace();
  13187. int result = PASS;
  13188. json_object *SignedUpdateFirmware;
  13189. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  13190. SignedUpdateFirmware = json_tokener_parse(payload);
  13191. if(!is_error(SignedUpdateFirmware))
  13192. {
  13193. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  13194. {
  13195. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  13196. }
  13197. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  13198. {
  13199. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  13200. }
  13201. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  13202. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  13203. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  13204. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  13205. {
  13206. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  13207. }
  13208. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  13209. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  13210. }
  13211. json_object_put(SignedUpdateFirmware);
  13212. /*
  13213. * TODO: Upgrade firmware process
  13214. */
  13215. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  13216. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  13217. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  13218. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  13219. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  13220. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  13221. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  13222. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  13223. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  13224. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  13225. sendInstallCertificateConfirmation(uuid);
  13226. return result;
  13227. }
  13228. int handleUnknownRequest(char *uuid, char *payload)
  13229. {
  13230. mtrace();
  13231. int result = PASS;
  13232. DEBUG_INFO("handleUnknownRequest...\n");
  13233. sendUnknownConfirmation(uuid);
  13234. result = PASS;
  13235. return result;
  13236. }
  13237. //==========================================
  13238. // Handle server response routine
  13239. //==========================================
  13240. void handleAuthorizeResponse(char *payload, int gun_index)
  13241. {
  13242. mtrace();
  13243. char expiryDatestr[30]={0};
  13244. char parentIdTagstr[20]={0};
  13245. char statusstr[20]={0};
  13246. int expiryDateISNULL=FALSE;
  13247. int parentIdTagISNULL=FALSE;
  13248. DEBUG_INFO("handleAuthorizeResponse...\n");
  13249. json_object *Authorize;
  13250. Authorize = json_tokener_parse(payload);
  13251. if(!is_error(Authorize))
  13252. {
  13253. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  13254. {
  13255. // Required data
  13256. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  13257. // Optional data
  13258. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  13259. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  13260. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  13261. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  13262. }
  13263. }
  13264. json_object_put(Authorize);
  13265. if(expiryDateISNULL == FALSE)
  13266. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  13267. if(parentIdTagISNULL == FALSE)
  13268. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  13269. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  13270. //Update idTag information to authorization cache if supproted
  13271. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  13272. {
  13273. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  13274. }
  13275. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  13276. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  13277. authorizeRetryTimes = 0;
  13278. }
  13279. void handleBootNotificationResponse(char *payload, int gun_index)
  13280. {
  13281. mtrace();
  13282. char statusStr[12]={0};
  13283. char currentTimeStr[30]={0};
  13284. int intervalInt = 0;
  13285. DEBUG_INFO("handleBootNotificationResponse...\n");
  13286. json_object *BootNotification;
  13287. BootNotification = json_tokener_parse(payload);
  13288. if(!is_error(BootNotification))
  13289. {
  13290. // Required data
  13291. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13292. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13293. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13294. }
  13295. json_object_put(BootNotification);
  13296. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13297. BootNotificationInterval = intervalInt;
  13298. //write back to ShmOCPP16DataPH->BootNotification
  13299. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  13300. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  13301. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  13302. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  13303. {
  13304. BootNotificationInterval = 0;
  13305. if((intervalInt == 0) || (intervalInt >= 10))
  13306. {
  13307. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", intervalInt);
  13308. HeartBeatWaitTime = intervalInt;
  13309. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  13310. }
  13311. server_sign = TRUE;
  13312. server_pending =FALSE;
  13313. }
  13314. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  13315. {
  13316. server_pending = TRUE;
  13317. }
  13318. //syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  13319. srand(time(NULL));
  13320. refreshStartTimer(&clientTime.Heartbeat);
  13321. clientTime.Heartbeat.tv_sec -= (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  13322. SetOcppConnStatus(TRUE);
  13323. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  13324. }
  13325. void handleDataTransferResponse(char *payload, int gun_index)
  13326. {
  13327. json_object *DataTransfer = json_tokener_parse(payload);
  13328. if(!is_error(DataTransfer))
  13329. {
  13330. // Required data
  13331. DEBUG_INFO("Status: %s.\n", json_object_get_string(json_object_object_get(DataTransfer, "status")));
  13332. // Optional data
  13333. if(json_object_object_get(DataTransfer, "data") != NULL)
  13334. {
  13335. DEBUG_INFO("Data: %s\n", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13336. json_object *Data = json_tokener_parse(json_object_get_string(json_object_object_get(DataTransfer, "data")));
  13337. if(!is_error(Data))
  13338. {
  13339. if(json_object_object_get(Data, "msgId") != NULL)
  13340. {
  13341. if(strstr(json_object_get_string(json_object_object_get(Data, "msgId")), "ID_CreditDeductResult") != NULL)
  13342. {
  13343. 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")));
  13344. }
  13345. }
  13346. }
  13347. json_object_put(Data);
  13348. }
  13349. }
  13350. json_object_put(DataTransfer);
  13351. }
  13352. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  13353. {
  13354. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  13355. //struct json_object *obj;
  13356. // obj = json_tokener_parse(payload);
  13357. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  13358. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  13359. //No fields are defined.
  13360. }
  13361. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13362. {
  13363. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13364. //struct json_object *obj;
  13365. // obj = json_tokener_parse(payload);
  13366. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  13367. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  13368. //No fields are defined.
  13369. }
  13370. void handleHeartbeatResponse(char *payload, int gun_index)
  13371. {
  13372. mtrace();
  13373. DEBUG_INFO("handleHeartbeatResponse...\n");
  13374. json_object *Heartbeat;
  13375. Heartbeat = json_tokener_parse(payload);
  13376. if(!is_error(Heartbeat))
  13377. {
  13378. // Required data
  13379. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13380. }
  13381. json_object_put(Heartbeat);
  13382. if(FirstHeartBeat == 0)
  13383. {
  13384. FirstHeartBeat = 1;
  13385. DEBUG_INFO("FirstHeartBeat \n");
  13386. }
  13387. HeartBeatWithNOResponse = 0;
  13388. refreshStartTimer(&clientTime.Heartbeat);
  13389. //syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  13390. }
  13391. void handleMeterValuesResponse(char *payload, int gun_index)
  13392. {
  13393. mtrace();
  13394. DEBUG_INFO("handleMeterValuesResponse...\n");
  13395. isQueueSendable = 1;
  13396. }
  13397. void handleStartTransactionResponse(char *payload, int gun_index)
  13398. {
  13399. mtrace();
  13400. //int transactionIdInt = 0;
  13401. FILE *outfile;
  13402. char data[100]={0};
  13403. DEBUG_INFO("handleStartTransactionResponse...\n");
  13404. json_object *StartTransaction;
  13405. StartTransaction = json_tokener_parse(payload);
  13406. if(!is_error(StartTransaction))
  13407. {
  13408. // Required data
  13409. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  13410. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  13411. // Optional data
  13412. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  13413. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  13414. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13415. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  13416. }
  13417. json_object_put(StartTransaction);
  13418. isQueueSendable = 1;
  13419. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  13420. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  13421. //-----------Start : write to the Queue TransactionId file -----------------//
  13422. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  13423. {}
  13424. else
  13425. {
  13426. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  13427. if(log == NULL)
  13428. {
  13429. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13430. return ;
  13431. }
  13432. else
  13433. {
  13434. fclose(log);
  13435. }
  13436. }
  13437. // open file for writing
  13438. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13439. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  13440. {
  13441. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  13442. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13443. fputs(data, outfile);
  13444. fclose (outfile);
  13445. }
  13446. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13447. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13448. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13449. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  13450. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13451. }
  13452. void handleStatusNotificationResponse(char *payload, int gun_index)
  13453. {
  13454. mtrace();
  13455. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13456. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13457. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13458. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13459. }
  13460. void handleStopTransactionnResponse(char *payload, int gun_index)
  13461. {
  13462. mtrace();
  13463. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13464. json_object *StopTransaction;
  13465. StopTransaction = json_tokener_parse(payload);
  13466. if(!is_error(StopTransaction))
  13467. {
  13468. // Optional data
  13469. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13470. {
  13471. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13472. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13473. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13474. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13475. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13476. }
  13477. }
  13478. json_object_put(StopTransaction);
  13479. isQueueSendable = 1;
  13480. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13481. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13482. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13483. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13484. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13485. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13486. }
  13487. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13488. {
  13489. mtrace();
  13490. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13491. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  13492. }
  13493. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13494. {
  13495. mtrace();
  13496. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13497. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  13498. }
  13499. void handleSignCertificateResponse(char *payload, int gun_index)
  13500. {
  13501. mtrace();
  13502. DEBUG_INFO("handleSignCertificateResponse...\n");
  13503. json_object *SignCertificate;
  13504. SignCertificate = json_tokener_parse(payload);
  13505. if(!is_error(SignCertificate))
  13506. {
  13507. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13508. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  13509. }
  13510. json_object_put(SignCertificate);
  13511. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  13512. }
  13513. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13514. {
  13515. mtrace();
  13516. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13517. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13518. }
  13519. //==========================================
  13520. // Handle Error routine
  13521. //==========================================
  13522. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13523. {
  13524. mtrace();
  13525. #ifdef SystemLogMessage
  13526. DEBUG_INFO("errorCode: %s\n", errorCode);
  13527. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13528. DEBUG_INFO("errorDetails: %s\n", payload);
  13529. #endif
  13530. }
  13531. //===============================================
  13532. // Common routine
  13533. //===============================================
  13534. int initialConfigurationTable(void)
  13535. {
  13536. //clock_t start_t, end_t, total_t;
  13537. FILE *fp;
  13538. FILE *outfile;
  13539. char str[512]={0};
  13540. char sstr[256]={0};
  13541. int c = 0;
  13542. char *loc;
  13543. int confVersion = 13;
  13544. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13545. //start_t = clock();
  13546. //printf("Starting of the program, start_t = %ld\n", start_t);
  13547. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13548. // Check configuration file size is correct
  13549. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  13550. {
  13551. struct stat st;
  13552. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  13553. if(st.st_size < 3100)
  13554. {
  13555. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  13556. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13557. }
  13558. }
  13559. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  13560. {
  13561. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  13562. if(outfile == NULL)
  13563. {
  13564. DEBUG_INFO("Error opening file\n");
  13565. return FALSE;
  13566. }
  13567. /*Core Profile*/
  13568. //AllowOfflineTxForUnknownId
  13569. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13573. //AuthorizationCacheEnabled
  13574. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13575. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13576. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13578. //AuthorizeRemoteTxRequests
  13579. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13580. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13582. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13583. //BlinkRepeat
  13584. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13586. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13588. //ClockAlignedDataInterval
  13589. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13590. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13591. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13593. //ConnectionTimeOut
  13594. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13595. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13596. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13598. //GetConfigurationMaxKeys
  13599. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13600. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13601. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13603. // HeartbeatInterval
  13604. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13605. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13608. // LightIntensity
  13609. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13610. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13611. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13613. // LocalAuthorizeOffline
  13614. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13615. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13616. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13618. // LocalPreAuthorize
  13619. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13620. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13621. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13623. // MaxEnergyOnInvalidId
  13624. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13625. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13626. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13628. // MeterValuesAlignedData
  13629. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13632. 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" );
  13633. else
  13634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13636. // MeterValuesAlignedDataMaxLength
  13637. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13638. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13640. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13641. else
  13642. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13644. // MeterValuesSampledData
  13645. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13646. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13648. 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" );
  13649. else
  13650. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13652. // MeterValuesSampledDataMaxLength
  13653. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13654. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13657. else
  13658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13660. // MeterValueSampleInterval
  13661. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13662. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13663. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13665. // MinimumStatusDuration
  13666. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13667. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13668. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13669. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13671. // NumberOfConnectors
  13672. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13673. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13674. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13675. {
  13676. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13677. }
  13678. else
  13679. {
  13680. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13681. }
  13682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13683. // ResetRetries
  13684. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13688. // ConnectorPhaseRotation
  13689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13691. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13693. // ConnectorPhaseRotationMaxLength
  13694. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13695. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13696. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13698. // StopTransactionOnEVSideDisconnect
  13699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13701. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13703. // StopTransactionOnInvalidId
  13704. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13706. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13708. // StopTxnAlignedData
  13709. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13711. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13713. // StopTxnAlignedDataMaxLength
  13714. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13716. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13718. // StopTxnSampledData
  13719. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13720. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13723. else
  13724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13726. // StopTxnSampledDataMaxLength
  13727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13729. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13730. {
  13731. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13732. }
  13733. else
  13734. {
  13735. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13736. }
  13737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13738. // SupportedFeatureProfiles
  13739. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13741. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13743. // SupportedFeatureProfilesMaxLength
  13744. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13745. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13746. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13748. // TransactionMessageAttempts
  13749. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13750. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13751. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13752. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13754. // TransactionMessageRetryInterval
  13755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13756. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13758. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13760. // UnlockConnectorOnEVSideDisconnect
  13761. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13762. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13763. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13765. // WebSocketPingInterval
  13766. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13767. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13768. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13770. // QueueOffLineMeterValues
  13771. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13772. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13773. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13775. // AuthorizationKey
  13776. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13777. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13778. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword );
  13779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13780. // SecurityProfile
  13781. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13782. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13783. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  13784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13785. // DefaultPrice
  13786. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13787. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13788. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13790. // CustomDisplayCostAndPrice
  13791. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13792. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13793. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13795. // CustomIdleFeeAfterStop
  13796. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13797. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13798. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13800. // SystemUptimeSec
  13801. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13802. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13803. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13805. // FreeVend
  13806. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13807. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  13808. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13810. // FreeVendIdtag
  13811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  13812. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  13813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  13814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  13815. // OcppServer
  13816. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  13817. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  13818. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  13819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  13820. // MaintainServer
  13821. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  13822. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  13823. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, 500);
  13824. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  13825. // StatusNotificationPeriodically
  13826. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = 1;
  13827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  13828. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  13829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  13830. // StatusNotificationInterval
  13831. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  13832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  13833. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  13834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  13835. // Configuration Version
  13836. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13840. //* Local Auth List Management Profile*/
  13841. #if 0
  13842. //For OCTT Test Case
  13843. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13846. #endif
  13847. #if 1
  13848. //LocalAuthListEnabled
  13849. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13850. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13852. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13853. #endif
  13854. //LocalAuthListMaxLength
  13855. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13856. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13857. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13859. //SendLocalListMaxLength
  13860. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  13863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13864. //ReserveConnectorZeroSupported
  13865. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13869. //* Smart Charging Profile */
  13870. //ChargeProfileMaxStackLevel
  13871. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13875. // ChargingScheduleAllowedChargingRateUnit
  13876. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13878. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13880. // ChargingScheduleMaxPeriods
  13881. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13885. // ConnectorSwitch3to1PhaseSupported
  13886. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13888. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13890. // MaxChargingProfilesInstalled
  13891. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13892. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13895. fclose(outfile);
  13896. }
  13897. else
  13898. {
  13899. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  13900. char keystr[60]={0};
  13901. char readonlystr[10]={0};
  13902. char valuestr[256]={0};
  13903. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  13904. if(fp == NULL) {
  13905. DEBUG_INFO("Error opening file");
  13906. return FALSE;
  13907. }
  13908. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13909. {
  13910. //DEBUG_INFO("Get Configuration \n");
  13911. if(strlen(str) > 0)
  13912. {
  13913. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13914. //*************************key*********************************/
  13915. if(strstr(str, "key") != NULL)
  13916. {
  13917. loc = strstr(str, "key");
  13918. c = 0;
  13919. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13920. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13921. {
  13922. sstr[c] = loc[strlen("key")+3+c];
  13923. c++;
  13924. }
  13925. sstr[c] = '\0';
  13926. strcpy(keystr,sstr);
  13927. }
  13928. //*************************readonly*********************************/
  13929. if(strstr(str, "readonly") != NULL)
  13930. {
  13931. loc = strstr(str, "readonly");
  13932. c = 0;
  13933. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13934. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13935. {
  13936. sstr[c] = loc[strlen("readonly")+2+c];
  13937. c++;
  13938. }
  13939. sstr[c] = '\0';
  13940. strcpy(readonlystr,sstr);
  13941. }
  13942. //*************************value*********************************/
  13943. if(strstr(str, "value") != NULL)
  13944. {
  13945. loc = strstr(str, "value");
  13946. c = 0;
  13947. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13948. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13949. {
  13950. sstr[c] = loc[strlen("value")+3+c];
  13951. c++;
  13952. }
  13953. sstr[c] = '\0';
  13954. strcpy(valuestr,sstr);
  13955. }
  13956. // DEBUG_INFO("keystr=%s\n",keystr);
  13957. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13958. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13959. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13960. {
  13961. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13963. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13964. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13965. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13966. }
  13967. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13968. {
  13969. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13970. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13971. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13972. }
  13973. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13974. {
  13975. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13976. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13977. }
  13978. if(strcmp(keystr, "BlinkRepeat") == 0)
  13979. {
  13980. //Charger.BlinkRepeat = Integer.parseInt(value);
  13981. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13982. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13983. }
  13984. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13985. {
  13986. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13987. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13988. }
  13989. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13990. {
  13991. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13992. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13993. }
  13994. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13995. {
  13996. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13997. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13998. }
  13999. if(strcmp(keystr, "HeartbeatInterval") == 0)
  14000. {
  14001. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14002. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  14003. HeartBeatWaitTime = atoi(valuestr);
  14004. }
  14005. if(strcmp(keystr, "LightIntensity") == 0)
  14006. {
  14007. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14008. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  14009. }
  14010. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  14011. {
  14012. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14013. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  14014. }
  14015. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  14016. {
  14017. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14018. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  14019. }
  14020. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  14021. {
  14022. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14023. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  14024. }
  14025. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  14026. {
  14027. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14028. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  14029. }
  14030. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  14031. {
  14032. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  14034. }
  14035. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  14036. {
  14037. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14038. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  14039. }
  14040. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  14041. {
  14042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14043. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  14044. }
  14045. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  14046. {
  14047. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14048. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  14049. }
  14050. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  14051. {
  14052. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14053. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  14054. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  14055. }
  14056. if(strcmp(keystr, "NumberOfConnectors") == 0)
  14057. {
  14058. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14059. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  14060. }
  14061. if(strcmp(keystr, "ResetRetries") == 0)
  14062. {
  14063. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14064. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  14065. }
  14066. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  14067. {
  14068. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14069. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  14070. }
  14071. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  14072. {
  14073. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14074. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  14075. }
  14076. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  14077. {
  14078. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14079. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  14080. }
  14081. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  14082. {
  14083. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14084. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  14085. }
  14086. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  14087. {
  14088. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14089. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  14090. }
  14091. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  14092. {
  14093. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14094. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14095. }
  14096. if(strcmp(keystr, "StopTxnSampledData") == 0)
  14097. {
  14098. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14099. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  14100. }
  14101. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  14102. {
  14103. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14104. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  14105. }
  14106. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  14107. {
  14108. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14109. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  14110. }
  14111. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  14112. {
  14113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14114. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  14115. }
  14116. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  14117. {
  14118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14119. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  14120. TransactionMessageAttemptsValue = atoi(valuestr);
  14121. }
  14122. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  14123. {
  14124. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14125. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  14126. TransactionMessageRetryIntervalValue = atoi(valuestr);
  14127. }
  14128. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  14129. {
  14130. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14131. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  14132. }
  14133. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  14134. {
  14135. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14136. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  14137. }
  14138. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  14139. {
  14140. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14141. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  14142. }
  14143. if(strcmp(keystr, "AuthorizationKey") == 0)
  14144. {
  14145. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14146. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  14147. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword);
  14148. }
  14149. if(strcmp(keystr, "SecurityProfile") == 0)
  14150. {
  14151. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14152. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  14153. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile );
  14154. }
  14155. if(strcmp(keystr, "DefaultPrice") == 0)
  14156. {
  14157. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14158. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  14159. }
  14160. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  14161. {
  14162. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14163. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  14164. }
  14165. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  14166. {
  14167. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14168. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  14169. }
  14170. if(strcmp(keystr, "SystemUptimeSec") == 0)
  14171. {
  14172. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14173. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%d", atoi(valuestr));
  14174. }
  14175. if(strcmp(keystr, "FreeVend") == 0)
  14176. {
  14177. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14178. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  14179. }
  14180. if(strcmp(keystr, "FreeVendIdtag") == 0)
  14181. {
  14182. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14183. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", valuestr);
  14184. }
  14185. if(strcmp(keystr, "OcppServer") == 0)
  14186. {
  14187. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14188. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, 500);
  14189. }
  14190. if(strcmp(keystr, "MaintainServer") == 0)
  14191. {
  14192. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14193. memcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, (char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,500);
  14194. }
  14195. if(strcmp(keystr, "StatusNotificationPeriodically") == 0)
  14196. {
  14197. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14198. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", valuestr);
  14199. }
  14200. if(strcmp(keystr, "StatusNotificationInterval") == 0)
  14201. {
  14202. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14203. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(valuestr));
  14204. }
  14205. if(strcmp(keystr, "ConfigurationVersion") == 0)
  14206. {
  14207. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14208. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  14209. }
  14210. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  14211. {
  14212. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14213. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  14214. }
  14215. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  14216. {
  14217. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14218. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  14219. }
  14220. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  14221. {
  14222. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14223. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  14224. }
  14225. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  14226. {
  14227. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  14229. }
  14230. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  14231. {
  14232. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14233. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  14234. }
  14235. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14236. {
  14237. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14238. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  14239. }
  14240. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  14241. {
  14242. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14243. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  14244. }
  14245. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  14246. {
  14247. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14248. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  14249. }
  14250. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  14251. {
  14252. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  14253. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  14254. }
  14255. }
  14256. }
  14257. fclose(fp);
  14258. }
  14259. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  14260. {
  14261. return PASS;
  14262. }
  14263. else
  14264. {
  14265. return FAIL;
  14266. }
  14267. }
  14268. void StoreConfigurationTable(void)
  14269. {
  14270. FILE *outfile;
  14271. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  14272. if(outfile == NULL)
  14273. {
  14274. DEBUG_INFO("Error opening file");
  14275. return ;
  14276. }
  14277. /*Core Profile*/
  14278. //AllowOfflineTxForUnknownId
  14279. /*
  14280. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  14281. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  14282. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  14283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  14284. */
  14285. //DEBUG_INFO("data=%s\n",data);
  14286. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  14287. //AuthorizationCacheEnabled
  14288. /*
  14289. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  14290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  14291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  14292. */
  14293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  14294. //AuthorizeRemoteTxRequests
  14295. /*
  14296. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  14297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  14298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  14299. */
  14300. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  14301. //BlinkRepeat
  14302. /*
  14303. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  14304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  14305. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  14306. */
  14307. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  14308. //ClockAlignedDataInterval
  14309. /*
  14310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  14311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  14312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  14313. */
  14314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  14315. //ConnectionTimeOut
  14316. /*
  14317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  14318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  14319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  14320. */
  14321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  14322. //GetConfigurationMaxKeys
  14323. /*
  14324. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  14325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  14326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  14327. */
  14328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  14329. // HeartbeatInterval
  14330. /*
  14331. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  14332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  14333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  14334. */
  14335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  14336. // LightIntensity
  14337. /*
  14338. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  14339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  14340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  14341. */
  14342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  14343. // LocalAuthorizeOffline
  14344. /*
  14345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  14346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  14347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  14348. */
  14349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14350. // LocalPreAuthorize
  14351. /*
  14352. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  14353. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  14354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  14355. */
  14356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  14357. // MaxEnergyOnInvalidId
  14358. /*
  14359. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  14360. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  14361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  14362. */
  14363. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  14364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  14365. // MeterValuesAlignedData
  14366. /*
  14367. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  14368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  14369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14370. */
  14371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  14372. // MeterValuesAlignedDataMaxLength
  14373. /*
  14374. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  14375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  14376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  14377. */
  14378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  14379. // MeterValuesSampledData
  14380. /*
  14381. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  14382. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  14383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  14384. */
  14385. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  14386. // MeterValuesSampledDataMaxLength
  14387. /*
  14388. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  14389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  14390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  14391. */
  14392. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  14393. // MeterValueSampleInterval
  14394. /*
  14395. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  14396. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  14397. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  14398. */
  14399. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  14400. // MinimumStatusDuration
  14401. /*
  14402. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  14403. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  14404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  14405. */
  14406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14407. // NumberOfConnectors
  14408. /*
  14409. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  14410. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  14411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14412. {
  14413. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  14414. }
  14415. else
  14416. {
  14417. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  14418. }
  14419. */
  14420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  14421. // ResetRetries
  14422. /*
  14423. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  14424. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  14425. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  14426. */
  14427. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  14428. // ConnectorPhaseRotation
  14429. /*
  14430. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  14431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  14432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  14433. */
  14434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  14435. // ConnectorPhaseRotationMaxLength
  14436. /*
  14437. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  14438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  14439. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  14440. */
  14441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  14442. // StopTransactionOnEVSideDisconnect
  14443. /*
  14444. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  14445. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  14446. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  14447. */
  14448. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14449. // StopTransactionOnInvalidId
  14450. /*
  14451. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14452. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14453. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14454. */
  14455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14456. // StopTxnAlignedData
  14457. /*
  14458. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14459. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14460. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14461. */
  14462. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14463. // StopTxnAlignedDataMaxLength
  14464. /*
  14465. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14466. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14468. */
  14469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14470. // StopTxnSampledData
  14471. /*
  14472. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14473. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14474. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14475. */
  14476. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14477. // StopTxnSampledDataMaxLength
  14478. /*
  14479. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14480. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14481. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14482. */
  14483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14484. // SupportedFeatureProfiles
  14485. /*
  14486. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14487. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14488. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14489. */
  14490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14491. // SupportedFeatureProfilesMaxLength
  14492. /*
  14493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14495. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14496. */
  14497. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14498. // TransactionMessageAttempts
  14499. /*
  14500. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14501. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14502. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14503. */
  14504. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14505. // TransactionMessageRetryInterval
  14506. /*
  14507. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14508. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14509. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14510. */
  14511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14512. // UnlockConnectorOnEVSideDisconnect
  14513. /*
  14514. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14515. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14516. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14517. */
  14518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14519. // WebSocketPingInterval
  14520. /*
  14521. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14522. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14523. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14524. */
  14525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14526. // QueueOffLineMeterValues
  14527. /*
  14528. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14529. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14530. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14531. */
  14532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14533. // AuthorizationKey
  14534. /*
  14535. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14536. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14537. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14538. */
  14539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14540. // SecurityProfile
  14541. /*
  14542. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14543. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14544. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14545. */
  14546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14547. // DefaultPrice
  14548. /*
  14549. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14550. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14551. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14552. */
  14553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14554. // CustomDisplayCostAndPrice
  14555. /*
  14556. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14557. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14558. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14559. */
  14560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14561. // CustomIdleFeeAfterStop
  14562. /*
  14563. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14565. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14566. */
  14567. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14568. // SystemUptimeSec
  14569. /*
  14570. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14572. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14573. */
  14574. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14575. // FreeVend
  14576. /*
  14577. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14578. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14579. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14580. */
  14581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14582. // FreeVendIdtag
  14583. /*
  14584. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility = 1;
  14585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemName, "FreeVendIdtag");
  14586. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "FreeVendIdtag" );
  14587. */
  14588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVendIdtag", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  14589. // OcppServer
  14590. /*
  14591. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility = 1;
  14592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemName, "OcppServer");
  14593. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "FALSE" );
  14594. */
  14595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","OcppServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  14596. // MaintainServer
  14597. /*
  14598. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility = 1;
  14599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemName, "MaintainServer");
  14600. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "FALSE" );
  14601. */
  14602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaintainServer", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  14603. // StatusNotificationPeriodically
  14604. /*
  14605. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility =0;
  14606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemName, "StatusNotificationPeriodically");
  14607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "FALSE" );
  14608. */
  14609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationPeriodically", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData);
  14610. // StatusNotificationInterval
  14611. /*
  14612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility = 1;
  14613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemName, "StatusNotificationInterval");
  14614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "120" );
  14615. */
  14616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StatusNotificationInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData);
  14617. // ConfigurationVersion
  14618. /*
  14619. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14620. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14621. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14622. */
  14623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14624. //* Local Auth List Management Profile*/
  14625. //LocalAuthListEnabled
  14626. /*
  14627. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14629. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14630. */
  14631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14632. //LocalAuthListMaxLength
  14633. /*
  14634. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14635. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14637. */
  14638. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14639. //SendLocalListMaxLength
  14640. /*
  14641. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14642. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14643. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14644. */
  14645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14646. //ReserveConnectorZeroSupported
  14647. /*
  14648. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14649. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14650. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14651. */
  14652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14653. //* Smart Charging Profile */
  14654. //ChargeProfileMaxStackLevel
  14655. /*
  14656. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14659. */
  14660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14661. // ChargingScheduleAllowedChargingRateUnit
  14662. /*
  14663. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14664. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14666. */
  14667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14668. // ChargingScheduleMaxPeriods
  14669. /*
  14670. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14671. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14673. */
  14674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14675. // ConnectorSwitch3to1PhaseSupported
  14676. /*
  14677. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14678. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14680. */
  14681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14682. // MaxChargingProfilesInstalled
  14683. /*
  14684. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14685. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14687. */
  14688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14689. fclose(outfile);
  14690. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14691. }
  14692. void getKeyValue(char *keyReq)
  14693. {
  14694. int isEmpty = FALSE;
  14695. int isKnowKey = FALSE;
  14696. DEBUG_INFO("keyReq = %s\n", keyReq);
  14697. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14698. isEmpty = TRUE;
  14699. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14700. {
  14701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14703. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14704. {
  14705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14706. }
  14707. else
  14708. {
  14709. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14710. }
  14711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14712. isKnowKey = TRUE;
  14713. }
  14714. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14715. {
  14716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14718. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14719. {
  14720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14721. }
  14722. else
  14723. {
  14724. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14725. }
  14726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14727. isKnowKey = TRUE;
  14728. }
  14729. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14730. {
  14731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14733. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14734. {
  14735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14736. }
  14737. else
  14738. {
  14739. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14740. }
  14741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14742. isKnowKey = TRUE;
  14743. }
  14744. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14745. {
  14746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14748. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14749. {
  14750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14751. }
  14752. else
  14753. {
  14754. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14755. }
  14756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14757. isKnowKey = TRUE;
  14758. }
  14759. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14760. {
  14761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14763. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14764. {
  14765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14766. }
  14767. else
  14768. {
  14769. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14770. }
  14771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14772. isKnowKey = TRUE;
  14773. }
  14774. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14775. {
  14776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14778. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14779. {
  14780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14781. }
  14782. else
  14783. {
  14784. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14785. }
  14786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14787. isKnowKey = TRUE;
  14788. }
  14789. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14790. {
  14791. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14793. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14794. {
  14795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14796. }
  14797. else
  14798. {
  14799. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14800. }
  14801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14802. isKnowKey = TRUE;
  14803. }
  14804. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14805. {
  14806. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14808. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14809. {
  14810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14811. }
  14812. else
  14813. {
  14814. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14815. }
  14816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14817. isKnowKey = TRUE;
  14818. }
  14819. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14820. {
  14821. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14823. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14824. {
  14825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14826. }
  14827. else
  14828. {
  14829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14830. }
  14831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14832. isKnowKey = TRUE;
  14833. }
  14834. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14835. {
  14836. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14838. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14839. {
  14840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14841. }
  14842. else
  14843. {
  14844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14845. }
  14846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14847. isKnowKey = TRUE;
  14848. }
  14849. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14850. {
  14851. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14853. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14854. {
  14855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14856. }
  14857. else
  14858. {
  14859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14860. }
  14861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14862. isKnowKey = TRUE;
  14863. }
  14864. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14865. {
  14866. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14868. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14869. {
  14870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14871. }
  14872. else
  14873. {
  14874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14875. }
  14876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14877. isKnowKey = TRUE;
  14878. }
  14879. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14880. {
  14881. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14883. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14884. {
  14885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14886. }
  14887. else
  14888. {
  14889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14890. }
  14891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14892. isKnowKey = TRUE;
  14893. }
  14894. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14895. {
  14896. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14898. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14899. {
  14900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14901. }
  14902. else
  14903. {
  14904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14905. }
  14906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14907. isKnowKey = TRUE;
  14908. }
  14909. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14910. {
  14911. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14913. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14914. {
  14915. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14916. }
  14917. else
  14918. {
  14919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14920. }
  14921. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14922. isKnowKey = TRUE;
  14923. }
  14924. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14925. {
  14926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14928. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14929. {
  14930. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14931. }
  14932. else
  14933. {
  14934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14935. }
  14936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14937. isKnowKey = TRUE;
  14938. }
  14939. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14940. {
  14941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14943. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14944. {
  14945. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14946. }
  14947. else
  14948. {
  14949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14950. }
  14951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14952. isKnowKey = TRUE;
  14953. }
  14954. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14955. {
  14956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14958. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14959. {
  14960. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14961. }
  14962. else
  14963. {
  14964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14965. }
  14966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  14967. isKnowKey = TRUE;
  14968. }
  14969. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14970. {
  14971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14973. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14974. {
  14975. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14976. }
  14977. else
  14978. {
  14979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14980. }
  14981. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14982. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14983. isKnowKey = TRUE;
  14984. }
  14985. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14986. {
  14987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14989. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14990. {
  14991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14992. }
  14993. else
  14994. {
  14995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14996. }
  14997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14998. isKnowKey = TRUE;
  14999. }
  15000. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  15001. {
  15002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  15003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  15004. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15005. {
  15006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  15007. }
  15008. else
  15009. {
  15010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  15011. }
  15012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  15013. isKnowKey = TRUE;
  15014. }
  15015. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  15016. {
  15017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  15018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  15019. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15020. {
  15021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15022. }
  15023. else
  15024. {
  15025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15026. }
  15027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  15028. isKnowKey = TRUE;
  15029. }
  15030. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  15031. {
  15032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  15033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  15034. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15035. {
  15036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15037. }
  15038. else
  15039. {
  15040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15041. }
  15042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  15043. isKnowKey = TRUE;
  15044. }
  15045. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  15046. {
  15047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  15048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  15049. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15050. {
  15051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  15052. }
  15053. else
  15054. {
  15055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  15056. }
  15057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  15058. isKnowKey = TRUE;
  15059. }
  15060. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  15061. {
  15062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  15063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  15064. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15065. {
  15066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  15067. }
  15068. else
  15069. {
  15070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  15071. }
  15072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  15073. isKnowKey = TRUE;
  15074. }
  15075. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  15076. {
  15077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  15078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  15079. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15080. {
  15081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15082. }
  15083. else
  15084. {
  15085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15086. }
  15087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  15088. isKnowKey = TRUE;
  15089. }
  15090. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  15091. {
  15092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  15093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  15094. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15095. {
  15096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  15097. }
  15098. else
  15099. {
  15100. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  15101. }
  15102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  15103. isKnowKey = TRUE;
  15104. }
  15105. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  15106. {
  15107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  15108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  15109. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15110. {
  15111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15112. }
  15113. else
  15114. {
  15115. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15116. }
  15117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  15118. isKnowKey = TRUE;
  15119. }
  15120. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  15121. {
  15122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  15123. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  15124. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15125. {
  15126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  15127. }
  15128. else
  15129. {
  15130. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  15131. }
  15132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  15133. isKnowKey = TRUE;
  15134. }
  15135. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  15136. {
  15137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  15138. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  15139. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15140. {
  15141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15142. }
  15143. else
  15144. {
  15145. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15146. }
  15147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  15148. isKnowKey = TRUE;
  15149. }
  15150. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  15151. {
  15152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  15153. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  15154. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15155. {
  15156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  15157. }
  15158. else
  15159. {
  15160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  15161. }
  15162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  15163. isKnowKey = TRUE;
  15164. }
  15165. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  15166. {
  15167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  15168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  15169. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15170. {
  15171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  15172. }
  15173. else
  15174. {
  15175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  15176. }
  15177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  15178. isKnowKey = TRUE;
  15179. }
  15180. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  15181. {
  15182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  15183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  15184. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15185. {
  15186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  15187. }
  15188. else
  15189. {
  15190. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  15191. }
  15192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  15193. isKnowKey = TRUE;
  15194. }
  15195. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  15196. {
  15197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  15198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  15199. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15200. {
  15201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  15202. }
  15203. else
  15204. {
  15205. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  15206. }
  15207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  15208. isKnowKey = TRUE;
  15209. }
  15210. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  15211. {
  15212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  15213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  15214. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15215. {
  15216. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  15217. }
  15218. else
  15219. {
  15220. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  15221. }
  15222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  15223. isKnowKey = TRUE;
  15224. }
  15225. /*
  15226. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  15227. {
  15228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  15229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  15230. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  15231. {
  15232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  15233. }
  15234. else
  15235. {
  15236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  15237. }
  15238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  15239. isKnowKey = TRUE;
  15240. }*/
  15241. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  15242. {
  15243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  15244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  15245. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15246. {
  15247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  15248. }
  15249. else
  15250. {
  15251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  15252. }
  15253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  15254. isKnowKey = TRUE;
  15255. }
  15256. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  15257. {
  15258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  15259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  15260. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  15261. {
  15262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  15263. }
  15264. else
  15265. {
  15266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  15267. }
  15268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  15269. isKnowKey = TRUE;
  15270. }
  15271. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  15272. {
  15273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  15274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  15275. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15276. {
  15277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  15278. }
  15279. else
  15280. {
  15281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  15282. }
  15283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  15284. isKnowKey = TRUE;
  15285. }
  15286. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  15287. {
  15288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  15289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  15290. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15291. {
  15292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  15293. }
  15294. else
  15295. {
  15296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  15297. }
  15298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  15299. isKnowKey = TRUE;
  15300. }
  15301. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  15302. {
  15303. struct sysinfo s_info;
  15304. int error = sysinfo(&s_info);
  15305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  15306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  15307. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  15308. {
  15309. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  15310. }
  15311. else
  15312. {
  15313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  15314. }
  15315. if(error != 0)
  15316. {
  15317. DEBUG_WARN("System uptime get error: %d\n", error);
  15318. }
  15319. else
  15320. {
  15321. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  15322. sprintf((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  15323. }
  15324. isKnowKey = TRUE;
  15325. }
  15326. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  15327. {
  15328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  15329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  15330. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15331. {
  15332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  15333. }
  15334. else
  15335. {
  15336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  15337. }
  15338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  15339. isKnowKey = TRUE;
  15340. }
  15341. if(isEmpty || strcmp(keyReq, "FreeVendIdtag") == 0 )
  15342. {
  15343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_FreeVendIdtag].Item, "FreeVendIdtag");
  15344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Key, "FreeVendIdtag");
  15345. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  15346. {
  15347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "0"/*"FALSE"*/);
  15348. }
  15349. else
  15350. {
  15351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].ReadOnly, "1"/*"TRUE"*/);
  15352. }
  15353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVendIdtag].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData);
  15354. isKnowKey = TRUE;
  15355. }
  15356. if(isEmpty || strcmp(keyReq, "OcppServer") == 0 )
  15357. {
  15358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_OcppServer].Item, "OcppServer");
  15359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Key, "OcppServer");
  15360. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  15361. {
  15362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "0"/*"FALSE"*/);
  15363. }
  15364. else
  15365. {
  15366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].ReadOnly, "1"/*"TRUE"*/);
  15367. }
  15368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_OcppServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData);
  15369. isKnowKey = TRUE;
  15370. }
  15371. if(isEmpty || strcmp(keyReq, "MaintainServer") == 0 )
  15372. {
  15373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaintainServer].Item, "MaintainServer");
  15374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Key, "MaintainServer");
  15375. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  15376. {
  15377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "0"/*"FALSE"*/);
  15378. }
  15379. else
  15380. {
  15381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].ReadOnly, "1"/*"TRUE"*/);
  15382. }
  15383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaintainServer].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData);
  15384. isKnowKey = TRUE;
  15385. }
  15386. if(isEmpty || strcmp(keyReq, "StatusNotificationPeriodically") == 0 )
  15387. {
  15388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationPeriodically].Item, "StatusNotificationPeriodically");
  15389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Key, "StatusNotificationPeriodically");
  15390. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  15391. {
  15392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "0"/*"FALSE"*/);
  15393. }
  15394. else
  15395. {
  15396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].ReadOnly, "1"/*"TRUE"*/);
  15397. }
  15398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationPeriodically].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData );
  15399. isKnowKey = TRUE;
  15400. }
  15401. if(isEmpty || strcmp(keyReq, "StatusNotificationInterval") == 0 )
  15402. {
  15403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StatusNotificationInterval].Item, "StatusNotificationInterval");
  15404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Key, "StatusNotificationInterval");
  15405. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  15406. {
  15407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "0"/*"FALSE"*/);
  15408. }
  15409. else
  15410. {
  15411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].ReadOnly, "1"/*"TRUE"*/);
  15412. }
  15413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StatusNotificationInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData );
  15414. isKnowKey = TRUE;
  15415. }
  15416. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  15417. {
  15418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  15419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  15420. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  15421. {
  15422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  15423. }
  15424. else
  15425. {
  15426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  15427. }
  15428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  15429. isKnowKey = TRUE;
  15430. }
  15431. #if 1
  15432. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  15433. {
  15434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  15435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  15436. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15437. {
  15438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  15439. }
  15440. else
  15441. {
  15442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  15443. }
  15444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  15445. isKnowKey = TRUE;
  15446. }
  15447. #endif
  15448. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  15449. {
  15450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  15451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  15452. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15453. {
  15454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15455. }
  15456. else
  15457. {
  15458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15459. }
  15460. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  15461. isKnowKey = TRUE;
  15462. }
  15463. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  15464. {
  15465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  15466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  15467. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15468. {
  15469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  15470. }
  15471. else
  15472. {
  15473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  15474. }
  15475. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  15476. isKnowKey = TRUE;
  15477. }
  15478. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  15479. {
  15480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  15481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  15482. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15483. {
  15484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  15485. }
  15486. else
  15487. {
  15488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  15489. }
  15490. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  15491. isKnowKey = TRUE;
  15492. }
  15493. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15494. {
  15495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15497. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15498. {
  15499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15500. }
  15501. else
  15502. {
  15503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15504. }
  15505. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15506. isKnowKey = TRUE;
  15507. }
  15508. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15509. {
  15510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15512. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15513. {
  15514. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15515. }
  15516. else
  15517. {
  15518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15519. }
  15520. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15521. isKnowKey = TRUE;
  15522. }
  15523. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15524. {
  15525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15527. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15528. {
  15529. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15530. }
  15531. else
  15532. {
  15533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15534. }
  15535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15536. isKnowKey = TRUE;
  15537. }
  15538. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15539. {
  15540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15542. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15543. {
  15544. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15545. }
  15546. else
  15547. {
  15548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15549. }
  15550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15551. isKnowKey = TRUE;
  15552. }
  15553. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15554. {
  15555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15557. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15558. {
  15559. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15560. }
  15561. else
  15562. {
  15563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15564. }
  15565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15566. isKnowKey = TRUE;
  15567. }
  15568. //=========================================================
  15569. if(!isEmpty && !isKnowKey)
  15570. {
  15571. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15572. strcpy(unknownkey[UnknownKeynum], keyReq);
  15573. UnknownKeynum = UnknownKeynum + 1;
  15574. }
  15575. }
  15576. void processUnkownKey(void)
  15577. {
  15578. DEBUG_INFO("processUnkownKey...\n");
  15579. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15580. for(int index=0; index < UnknownKeynum; index++)
  15581. {
  15582. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15583. {
  15584. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15585. }
  15586. }
  15587. }
  15588. int setKeyValue(char *key, char *value)
  15589. {
  15590. int isSuccess = NotSupported;
  15591. int check_ascii=0;
  15592. char str[501]={0};
  15593. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15594. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15595. {
  15596. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15597. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15598. {
  15599. strcpy(str, (const char*)value);
  15600. for(int i = 0; str[i]; i++){
  15601. str[i] = tolower(str[i]);
  15602. }
  15603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15604. isSuccess = ConfigurationStatus_Accepted;
  15605. }
  15606. else
  15607. {
  15608. isSuccess = ConfigurationStatus_Rejected;
  15609. }
  15610. }
  15611. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15612. {
  15613. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15614. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15615. {
  15616. strcpy(str, (const char*)value);
  15617. for(int i = 0; str[i]; i++){
  15618. str[i] = tolower(str[i]);
  15619. }
  15620. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15621. isSuccess = ConfigurationStatus_Accepted;
  15622. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  15623. }
  15624. else
  15625. {
  15626. isSuccess = ConfigurationStatus_Rejected;
  15627. }
  15628. }
  15629. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15630. {
  15631. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15632. {
  15633. strcpy(str, (const char*)value);
  15634. for(int i = 0; str[i]; i++)
  15635. {
  15636. str[i] = tolower(str[i]);
  15637. }
  15638. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15640. isSuccess = ConfigurationStatus_Accepted;
  15641. }
  15642. else
  15643. {
  15644. isSuccess = ConfigurationStatus_Rejected;
  15645. }
  15646. }
  15647. if(strcmp(key, "BlinkRepeat") == 0)
  15648. {
  15649. //Charger.BlinkRepeat = Integer.parseInt(value);
  15650. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15651. {
  15652. check_ascii = value[0];
  15653. if( (check_ascii < 48) || (check_ascii > 57) )
  15654. {
  15655. isSuccess = ConfigurationStatus_Rejected;
  15656. }
  15657. else
  15658. {
  15659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15660. isSuccess = ConfigurationStatus_Accepted;
  15661. }
  15662. }
  15663. else
  15664. {
  15665. isSuccess = ConfigurationStatus_Rejected;
  15666. }
  15667. }
  15668. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15669. {
  15670. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15671. {
  15672. check_ascii = value[0];
  15673. if( (check_ascii < 48) || (check_ascii > 57) )
  15674. {
  15675. isSuccess = ConfigurationStatus_Rejected;
  15676. }
  15677. else
  15678. {
  15679. if((atoi(value) == 0) || (atoi(value) >= 5))
  15680. {
  15681. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15682. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15683. isSuccess = ConfigurationStatus_Accepted;
  15684. }
  15685. else
  15686. isSuccess = ConfigurationStatus_Rejected;
  15687. }
  15688. }
  15689. else
  15690. {
  15691. isSuccess = ConfigurationStatus_Rejected;
  15692. }
  15693. }
  15694. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15695. {
  15696. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15697. {
  15698. check_ascii = value[0];
  15699. if( (check_ascii < 48) || (check_ascii > 57) )
  15700. {
  15701. isSuccess = ConfigurationStatus_Rejected;
  15702. }
  15703. else
  15704. {
  15705. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15706. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15707. isSuccess = ConfigurationStatus_Accepted;
  15708. }
  15709. }
  15710. else
  15711. {
  15712. isSuccess = ConfigurationStatus_Rejected;
  15713. }
  15714. }
  15715. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15716. {
  15717. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15718. {
  15719. check_ascii = value[0];
  15720. if( (check_ascii < 48) || (check_ascii > 57) )
  15721. {
  15722. isSuccess = ConfigurationStatus_Rejected;
  15723. }
  15724. else
  15725. {
  15726. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15727. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15728. isSuccess = ConfigurationStatus_Accepted;
  15729. }
  15730. }
  15731. else
  15732. {
  15733. isSuccess = ConfigurationStatus_Rejected;
  15734. }
  15735. }
  15736. if(strcmp(key, "HeartbeatInterval") == 0)
  15737. {
  15738. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15739. {
  15740. check_ascii = value[0];
  15741. if( (check_ascii < 48) || (check_ascii > 57) )
  15742. {
  15743. isSuccess = ConfigurationStatus_Rejected;
  15744. }
  15745. else
  15746. {
  15747. if((atoi(value) == 0) || (atoi(value) >= 10))
  15748. {
  15749. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15751. HeartBeatWaitTime = atoi(value);
  15752. isSuccess = ConfigurationStatus_Accepted;
  15753. }
  15754. else
  15755. {
  15756. isSuccess = ConfigurationStatus_Rejected;
  15757. }
  15758. }
  15759. }
  15760. else
  15761. {
  15762. isSuccess = ConfigurationStatus_Rejected;
  15763. }
  15764. }
  15765. if(strcmp(key, "LightIntensity") == 0)
  15766. {
  15767. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15768. {
  15769. check_ascii = value[0];
  15770. if( (check_ascii < 48) || (check_ascii > 57) )
  15771. {
  15772. isSuccess = ConfigurationStatus_Rejected;
  15773. }
  15774. else
  15775. {
  15776. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15777. isSuccess = ConfigurationStatus_Accepted;
  15778. }
  15779. }
  15780. else
  15781. {
  15782. isSuccess = ConfigurationStatus_Rejected;
  15783. }
  15784. }
  15785. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15786. {
  15787. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15788. {
  15789. strcpy(str, (const char*)value);
  15790. for(int i = 0; str[i]; i++)
  15791. {
  15792. str[i] = tolower(str[i]);
  15793. }
  15794. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15795. isSuccess = ConfigurationStatus_Accepted;
  15796. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15797. }
  15798. else
  15799. {
  15800. isSuccess = ConfigurationStatus_Rejected;
  15801. }
  15802. }
  15803. if(strcmp(key, "LocalPreAuthorize") == 0)
  15804. {
  15805. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15806. {
  15807. strcpy(str, (const char*)value);
  15808. for(int i = 0; str[i]; i++)
  15809. {
  15810. str[i] = tolower(str[i]);
  15811. }
  15812. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15813. isSuccess = ConfigurationStatus_Accepted;
  15814. }
  15815. else
  15816. {
  15817. isSuccess = ConfigurationStatus_Rejected;
  15818. }
  15819. }
  15820. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15821. {
  15822. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15823. {
  15824. check_ascii = value[0];
  15825. if( (check_ascii < 48) || (check_ascii > 57) )
  15826. {
  15827. isSuccess = ConfigurationStatus_Rejected;
  15828. }
  15829. else
  15830. {
  15831. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15832. isSuccess = ConfigurationStatus_Accepted;
  15833. }
  15834. }
  15835. else
  15836. {
  15837. isSuccess = ConfigurationStatus_Rejected;
  15838. }
  15839. }
  15840. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15841. {
  15842. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15843. {
  15844. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15845. isSuccess = ConfigurationStatus_Accepted;
  15846. }
  15847. else
  15848. {
  15849. isSuccess = ConfigurationStatus_Rejected;
  15850. }
  15851. }
  15852. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15853. {
  15854. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15855. {
  15856. check_ascii = value[0];
  15857. if( (check_ascii < 48) || (check_ascii > 57) )
  15858. {
  15859. isSuccess = ConfigurationStatus_Rejected;
  15860. }
  15861. else
  15862. {
  15863. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15864. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15865. isSuccess = ConfigurationStatus_Accepted;
  15866. }
  15867. }
  15868. else
  15869. {
  15870. isSuccess = ConfigurationStatus_Rejected;
  15871. }
  15872. }
  15873. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15874. {
  15875. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15876. {
  15877. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15878. isSuccess = ConfigurationStatus_Accepted;
  15879. }
  15880. else
  15881. {
  15882. isSuccess = ConfigurationStatus_Rejected;
  15883. }
  15884. }
  15885. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15886. {
  15887. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15888. {
  15889. check_ascii = value[0];
  15890. if( (check_ascii < 48) || (check_ascii > 57) )
  15891. {
  15892. isSuccess = ConfigurationStatus_Rejected;
  15893. }
  15894. else
  15895. {
  15896. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15897. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15898. isSuccess = ConfigurationStatus_Accepted;
  15899. }
  15900. }
  15901. else
  15902. {
  15903. isSuccess = ConfigurationStatus_Rejected;
  15904. }
  15905. }
  15906. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15907. {
  15908. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15909. {
  15910. check_ascii = value[0];
  15911. if( (check_ascii < 48) || (check_ascii > 57) )
  15912. {
  15913. isSuccess = ConfigurationStatus_Rejected;
  15914. }
  15915. else
  15916. {
  15917. if((atoi(value) == 0) || (atoi(value) >= 3))
  15918. {
  15919. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15920. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15921. isSuccess = ConfigurationStatus_Accepted;
  15922. }
  15923. else
  15924. {
  15925. isSuccess = ConfigurationStatus_Rejected;
  15926. }
  15927. }
  15928. }
  15929. else
  15930. {
  15931. isSuccess = ConfigurationStatus_Rejected;
  15932. }
  15933. }
  15934. if(strcmp(key, "MinimumStatusDuration") == 0)
  15935. {
  15936. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15937. {
  15938. check_ascii = value[0];
  15939. if( (check_ascii < 48) || (check_ascii > 57) )
  15940. {
  15941. isSuccess = ConfigurationStatus_Rejected;
  15942. }
  15943. else
  15944. {
  15945. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15946. {
  15947. isSuccess = ConfigurationStatus_Rejected;
  15948. }
  15949. else
  15950. {
  15951. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15952. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15953. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15954. isSuccess = ConfigurationStatus_Accepted;
  15955. }
  15956. }
  15957. }
  15958. else
  15959. {
  15960. isSuccess = ConfigurationStatus_Rejected;
  15961. }
  15962. }
  15963. if(strcmp(key, "NumberOfConnectors") == 0)
  15964. {
  15965. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15966. {
  15967. check_ascii = value[0];
  15968. if( (check_ascii < 48) || (check_ascii > 57) )
  15969. {
  15970. isSuccess = ConfigurationStatus_Rejected;
  15971. }
  15972. else
  15973. {
  15974. //Charger.ResetRetries = Integer.parseInt(value);
  15975. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15976. isSuccess = ConfigurationStatus_Accepted;
  15977. }
  15978. }
  15979. else
  15980. {
  15981. isSuccess = ConfigurationStatus_Rejected;
  15982. }
  15983. }
  15984. if(strcmp(key, "ResetRetries") == 0)
  15985. {
  15986. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15987. {
  15988. check_ascii = value[0];
  15989. if( (check_ascii < 48) || (check_ascii > 57) )
  15990. {
  15991. isSuccess = ConfigurationStatus_Rejected;
  15992. }
  15993. else
  15994. {
  15995. //Charger.ResetRetries = Integer.parseInt(value);
  15996. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15997. isSuccess = ConfigurationStatus_Accepted;
  15998. }
  15999. }
  16000. else
  16001. {
  16002. isSuccess = ConfigurationStatus_Rejected;
  16003. }
  16004. }
  16005. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  16006. {
  16007. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  16008. {
  16009. strcpy(str, (const char*)value);
  16010. for(int i = 0; str[i]; i++)
  16011. {
  16012. str[i] = tolower(str[i]);
  16013. }
  16014. if(strcmp(str, "notapplicable")== 0)
  16015. {
  16016. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  16017. isSuccess = ConfigurationStatus_Accepted;
  16018. }
  16019. else if(strcmp(str, "unknown")== 0)
  16020. {
  16021. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  16022. isSuccess = ConfigurationStatus_Accepted;
  16023. }
  16024. else if(strcmp(str, "rst")== 0)
  16025. {
  16026. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  16027. isSuccess = ConfigurationStatus_Accepted;
  16028. }
  16029. else if(strcmp(str, "rts")== 0)
  16030. {
  16031. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  16032. isSuccess = ConfigurationStatus_Accepted;
  16033. }
  16034. else if(strcmp(str, "srt")== 0)
  16035. {
  16036. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  16037. isSuccess = ConfigurationStatus_Accepted;
  16038. }
  16039. else if(strcmp(str, "str")== 0)
  16040. {
  16041. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  16042. isSuccess = ConfigurationStatus_Accepted;
  16043. }
  16044. else if(strcmp(str, "trs")== 0)
  16045. {
  16046. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  16047. isSuccess = ConfigurationStatus_Accepted;
  16048. }
  16049. else if(strcmp(str, "tsr")== 0)
  16050. {
  16051. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  16052. isSuccess = ConfigurationStatus_Accepted;
  16053. }
  16054. else
  16055. {
  16056. isSuccess = ConfigurationStatus_Rejected;
  16057. }
  16058. }
  16059. else
  16060. {
  16061. isSuccess = ConfigurationStatus_Rejected;
  16062. }
  16063. }
  16064. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  16065. {
  16066. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  16067. {
  16068. check_ascii = value[0];
  16069. if( (check_ascii < 48) || (check_ascii > 57) )
  16070. {
  16071. isSuccess = ConfigurationStatus_Rejected;
  16072. }
  16073. else
  16074. {
  16075. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  16076. isSuccess = ConfigurationStatus_Accepted;
  16077. }
  16078. }
  16079. else
  16080. {
  16081. isSuccess = ConfigurationStatus_Rejected;
  16082. }
  16083. }
  16084. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  16085. {
  16086. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  16087. {
  16088. strcpy(str, (const char*)value);
  16089. for(int i = 0; str[i]; i++)
  16090. {
  16091. str[i] = tolower(str[i]);
  16092. }
  16093. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16094. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16095. isSuccess = ConfigurationStatus_Accepted;
  16096. }
  16097. else
  16098. {
  16099. isSuccess = ConfigurationStatus_Rejected;
  16100. }
  16101. }
  16102. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  16103. {
  16104. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  16105. {
  16106. strcpy(str, (const char*)value);
  16107. for(int i = 0; str[i]; i++)
  16108. {
  16109. str[i] = tolower(str[i]);
  16110. }
  16111. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  16112. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16113. isSuccess = ConfigurationStatus_Accepted;
  16114. }
  16115. else
  16116. {
  16117. isSuccess = ConfigurationStatus_Rejected;
  16118. }
  16119. }
  16120. if(strcmp(key, "StopTxnAlignedData") == 0)
  16121. {
  16122. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  16123. {
  16124. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  16125. isSuccess = ConfigurationStatus_Accepted;
  16126. }
  16127. else
  16128. {
  16129. isSuccess = ConfigurationStatus_Rejected;
  16130. }
  16131. }
  16132. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  16133. {
  16134. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  16135. {
  16136. check_ascii = value[0];
  16137. if( (check_ascii < 48) || (check_ascii > 57) )
  16138. {
  16139. isSuccess = ConfigurationStatus_Rejected;
  16140. }
  16141. else
  16142. {
  16143. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  16144. isSuccess = ConfigurationStatus_Accepted;
  16145. }
  16146. }
  16147. else
  16148. {
  16149. isSuccess = ConfigurationStatus_Rejected;
  16150. }
  16151. }
  16152. if(strcmp(key, "StopTxnSampledData") == 0)
  16153. {
  16154. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  16155. {
  16156. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  16157. isSuccess = ConfigurationStatus_Accepted;
  16158. }
  16159. else
  16160. {
  16161. isSuccess = ConfigurationStatus_Rejected;
  16162. }
  16163. }
  16164. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  16165. {
  16166. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  16167. {
  16168. check_ascii = value[0];
  16169. if( (check_ascii < 48) || (check_ascii > 57) )
  16170. {
  16171. isSuccess = ConfigurationStatus_Rejected;
  16172. }
  16173. else
  16174. {
  16175. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  16176. isSuccess = ConfigurationStatus_Accepted;
  16177. }
  16178. }
  16179. else
  16180. {
  16181. isSuccess = ConfigurationStatus_Rejected;
  16182. }
  16183. }
  16184. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  16185. {
  16186. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  16187. {
  16188. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  16189. isSuccess = ConfigurationStatus_Accepted;
  16190. }
  16191. else
  16192. {
  16193. isSuccess = ConfigurationStatus_Rejected;
  16194. }
  16195. }
  16196. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  16197. {
  16198. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  16199. {
  16200. check_ascii = value[0];
  16201. if( (check_ascii < 48) || (check_ascii > 57) )
  16202. {
  16203. isSuccess = ConfigurationStatus_Rejected;
  16204. }
  16205. else
  16206. {
  16207. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  16208. isSuccess = ConfigurationStatus_Accepted;
  16209. }
  16210. }
  16211. else
  16212. {
  16213. isSuccess = ConfigurationStatus_Rejected;
  16214. }
  16215. }
  16216. if(strcmp(key, "TransactionMessageAttempts") == 0)
  16217. {
  16218. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  16219. {
  16220. check_ascii = value[0];
  16221. if( (check_ascii < 48) || (check_ascii > 57) )
  16222. {
  16223. isSuccess = ConfigurationStatus_Rejected;
  16224. }
  16225. else
  16226. {
  16227. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  16228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  16229. TransactionMessageAttemptsValue = atoi(value);
  16230. isSuccess = ConfigurationStatus_Accepted;
  16231. }
  16232. }
  16233. else
  16234. {
  16235. isSuccess = ConfigurationStatus_Rejected;
  16236. }
  16237. }
  16238. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  16239. {
  16240. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  16241. {
  16242. check_ascii = value[0];
  16243. if( (check_ascii < 48) || (check_ascii > 57) )
  16244. {
  16245. isSuccess = ConfigurationStatus_Rejected;
  16246. }
  16247. else
  16248. {
  16249. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  16250. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  16251. TransactionMessageRetryIntervalValue = atoi(value);
  16252. isSuccess = ConfigurationStatus_Accepted;
  16253. }
  16254. }
  16255. else
  16256. {
  16257. isSuccess = ConfigurationStatus_Rejected;
  16258. }
  16259. }
  16260. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  16261. {
  16262. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  16263. {
  16264. strcpy(str, (const char*)value);
  16265. for(int i = 0; str[i]; i++)
  16266. {
  16267. str[i] = tolower(str[i]);
  16268. }
  16269. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  16270. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16271. isSuccess = ConfigurationStatus_Accepted;
  16272. }
  16273. else
  16274. {
  16275. isSuccess = ConfigurationStatus_Rejected;
  16276. }
  16277. }
  16278. if(strcmp(key, "WebSocketPingInterval") == 0)
  16279. {
  16280. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  16281. {
  16282. check_ascii = value[0];
  16283. if( (check_ascii < 48) || (check_ascii > 57) )
  16284. {
  16285. isSuccess = ConfigurationStatus_Rejected;
  16286. }
  16287. else
  16288. {
  16289. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16290. isSuccess = ConfigurationStatus_Accepted;
  16291. if((atoi(value) == 0) || (atoi(value) >= 10))
  16292. {
  16293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  16294. isSuccess = ConfigurationStatus_Accepted;
  16295. }
  16296. else
  16297. isSuccess = ConfigurationStatus_Rejected;
  16298. }
  16299. }
  16300. else
  16301. {
  16302. isSuccess = ConfigurationStatus_Rejected;
  16303. }
  16304. }
  16305. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  16306. {
  16307. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  16308. {
  16309. strcpy(str, (const char*)value);
  16310. for(int i = 0; str[i]; i++)
  16311. {
  16312. str[i] = tolower(str[i]);
  16313. }
  16314. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16315. isSuccess = ConfigurationStatus_Accepted;
  16316. }
  16317. else
  16318. {
  16319. isSuccess = ConfigurationStatus_Rejected;
  16320. }
  16321. }
  16322. if(strcmp(key, "AuthorizationKey") == 0)
  16323. {
  16324. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  16325. {
  16326. strcpy(str, (const char*)value);
  16327. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  16328. strcpy((char*)ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16329. isSuccess = ConfigurationStatus_Accepted;
  16330. }
  16331. else
  16332. {
  16333. isSuccess = ConfigurationStatus_Rejected;
  16334. }
  16335. }
  16336. if(strcmp(key, "SecurityProfile") == 0)
  16337. {
  16338. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  16339. {
  16340. check_ascii = value[0];
  16341. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  16342. {
  16343. isSuccess = ConfigurationStatus_Rejected;
  16344. }
  16345. else if(check_ascii == 0x33)
  16346. {
  16347. isSuccess = NotSupported;
  16348. }
  16349. else
  16350. {
  16351. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  16352. {
  16353. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  16354. ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile = atoi(value);
  16355. isSuccess = ConfigurationStatus_Accepted;
  16356. }
  16357. else
  16358. isSuccess = ConfigurationStatus_Rejected;
  16359. }
  16360. }
  16361. else
  16362. {
  16363. isSuccess = ConfigurationStatus_Rejected;
  16364. }
  16365. }
  16366. if(strcmp(key, "DefaultPrice") == 0)
  16367. {
  16368. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  16369. {
  16370. strcpy(str, (const char*)value);
  16371. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  16372. isSuccess = ConfigurationStatus_Accepted;
  16373. }
  16374. else
  16375. {
  16376. isSuccess = ConfigurationStatus_Rejected;
  16377. }
  16378. }
  16379. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  16380. {
  16381. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  16382. {
  16383. strcpy(str, (const char*)value);
  16384. for(int i = 0; str[i]; i++)
  16385. {
  16386. str[i] = tolower(str[i]);
  16387. }
  16388. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16389. isSuccess = ConfigurationStatus_Accepted;
  16390. }
  16391. else
  16392. {
  16393. isSuccess = ConfigurationStatus_Rejected;
  16394. }
  16395. }
  16396. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  16397. {
  16398. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  16399. {
  16400. strcpy(str, (const char*)value);
  16401. for(int i = 0; str[i]; i++)
  16402. {
  16403. str[i] = tolower(str[i]);
  16404. }
  16405. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16406. isSuccess = ConfigurationStatus_Accepted;
  16407. }
  16408. else
  16409. {
  16410. isSuccess = ConfigurationStatus_Rejected;
  16411. }
  16412. }
  16413. if(strcmp(key, "SystemUptimeSec") == 0)
  16414. {
  16415. isSuccess = NotSupported;
  16416. }
  16417. if(strcmp(key, "FreeVend") == 0)
  16418. {
  16419. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  16420. {
  16421. strcpy(str, (const char*)value);
  16422. for(int i = 0; str[i]; i++)
  16423. {
  16424. str[i] = tolower(str[i]);
  16425. }
  16426. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  16427. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16428. isSuccess = ConfigurationStatus_Accepted;
  16429. }
  16430. else
  16431. {
  16432. isSuccess = ConfigurationStatus_Rejected;
  16433. }
  16434. }
  16435. if(strcmp(key, "FreeVendIdtag") == 0)
  16436. {
  16437. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemAccessibility == 1)
  16438. {
  16439. strcpy(str, (const char*)value);
  16440. if(strlen(str) <= 20)
  16441. {
  16442. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[FreeVendIdtag].ItemData, "%s", str );
  16443. isSuccess = ConfigurationStatus_Accepted;
  16444. }
  16445. else
  16446. {
  16447. DEBUG_WARN("FreeVendIdtag(%s) length over 20 bytes.\n", str);
  16448. isSuccess = ConfigurationStatus_Rejected;
  16449. }
  16450. }
  16451. else
  16452. {
  16453. isSuccess = ConfigurationStatus_Rejected;
  16454. }
  16455. }
  16456. if(strcmp(key, "OcppServer") == 0)
  16457. {
  16458. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemAccessibility == 1)
  16459. {
  16460. strcpy(str, (const char*)value);
  16461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[OcppServer].ItemData, "%s", str );
  16462. sprintf((char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL, "%s", str );
  16463. isSuccess = ConfigurationStatus_Accepted;
  16464. }
  16465. else
  16466. {
  16467. isSuccess = ConfigurationStatus_Rejected;
  16468. }
  16469. }
  16470. if(strcmp(key, "MaintainServer") == 0)
  16471. {
  16472. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemAccessibility == 1)
  16473. {
  16474. strcpy(str, (const char*)value);
  16475. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaintainServer].ItemData, "%s", str );
  16476. sprintf((char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL, "%s", str );
  16477. isSuccess = ConfigurationStatus_Accepted;
  16478. }
  16479. else
  16480. {
  16481. isSuccess = ConfigurationStatus_Rejected;
  16482. }
  16483. }
  16484. if(strcmp(key, "StatusNotificationPeriodically") == 0)
  16485. {
  16486. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemAccessibility == 1)
  16487. {
  16488. strcpy(str, (const char*)value);
  16489. for(int i = 0; str[i]; i++)
  16490. {
  16491. str[i] = tolower(str[i]);
  16492. }
  16493. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationPeriodically].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE");
  16494. isSuccess = ConfigurationStatus_Accepted;
  16495. }
  16496. else
  16497. {
  16498. isSuccess = ConfigurationStatus_Rejected;
  16499. }
  16500. }
  16501. if(strcmp(key, "StatusNotificationInterval") == 0)
  16502. {
  16503. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemAccessibility == 1)
  16504. {
  16505. check_ascii = value[0];
  16506. if( (check_ascii < 48) || (check_ascii > 57) )
  16507. {
  16508. isSuccess = ConfigurationStatus_Rejected;
  16509. }
  16510. else
  16511. {
  16512. if((atoi(value) == 0) || (atoi(value) >= 10))
  16513. {
  16514. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StatusNotificationInterval].ItemData, "%d", atoi(value) );
  16515. isSuccess = ConfigurationStatus_Accepted;
  16516. }
  16517. else
  16518. isSuccess = ConfigurationStatus_Rejected;
  16519. }
  16520. }
  16521. else
  16522. {
  16523. isSuccess = ConfigurationStatus_Rejected;
  16524. }
  16525. }
  16526. #if 0
  16527. //For OCPP Test Case
  16528. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  16529. {
  16530. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16531. {
  16532. strcpy(str, (const char*)value);
  16533. for(int i = 0; str[i]; i++)
  16534. {
  16535. str[i] = tolower(str[i]);
  16536. }
  16537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16538. isSuccess = ConfigurationStatus_Accepted;
  16539. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16540. }
  16541. else
  16542. {
  16543. isSuccess = ConfigurationStatus_Rejected;
  16544. }
  16545. }
  16546. #endif
  16547. #if 1
  16548. if(strcmp(key, "LocalAuthListEnabled") == 0)
  16549. {
  16550. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  16551. {
  16552. strcpy(str, (const char*)value);
  16553. for(int i = 0; str[i]; i++)
  16554. {
  16555. str[i] = tolower(str[i]);
  16556. }
  16557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16558. isSuccess = ConfigurationStatus_Accepted;
  16559. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16560. }
  16561. else
  16562. {
  16563. isSuccess = ConfigurationStatus_Rejected;
  16564. }
  16565. }
  16566. #endif
  16567. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16568. {
  16569. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16570. {
  16571. check_ascii = value[0];
  16572. if( (check_ascii < 48) || (check_ascii > 57) )
  16573. {
  16574. isSuccess = ConfigurationStatus_Rejected;
  16575. }
  16576. else
  16577. {
  16578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16579. isSuccess = ConfigurationStatus_Accepted;
  16580. }
  16581. }
  16582. else
  16583. {
  16584. isSuccess = ConfigurationStatus_Rejected;
  16585. }
  16586. }
  16587. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16588. {
  16589. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16590. {
  16591. check_ascii = value[0];
  16592. if( (check_ascii < 48) || (check_ascii > 57) )
  16593. {
  16594. isSuccess = ConfigurationStatus_Rejected;
  16595. }
  16596. else
  16597. {
  16598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16599. isSuccess = ConfigurationStatus_Accepted;
  16600. }
  16601. }
  16602. else
  16603. {
  16604. isSuccess = ConfigurationStatus_Rejected;
  16605. }
  16606. }
  16607. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16608. {
  16609. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16610. {
  16611. strcpy(str, (const char*)value);
  16612. for(int i = 0; str[i]; i++)
  16613. {
  16614. str[i] = tolower(str[i]);
  16615. }
  16616. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16617. isSuccess = ConfigurationStatus_Accepted;
  16618. }
  16619. else
  16620. {
  16621. isSuccess = ConfigurationStatus_Rejected;
  16622. }
  16623. }
  16624. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16625. {
  16626. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16627. {
  16628. check_ascii = value[0];
  16629. if( (check_ascii < 48) || (check_ascii > 57) )
  16630. {
  16631. isSuccess = ConfigurationStatus_Rejected;
  16632. }
  16633. else
  16634. {
  16635. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16636. isSuccess = ConfigurationStatus_Accepted;
  16637. }
  16638. }
  16639. else
  16640. {
  16641. isSuccess = ConfigurationStatus_Rejected;
  16642. }
  16643. }
  16644. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16645. {
  16646. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16647. {
  16648. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16649. isSuccess = ConfigurationStatus_Accepted;
  16650. }
  16651. else
  16652. {
  16653. isSuccess = ConfigurationStatus_Rejected;
  16654. }
  16655. }
  16656. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16657. {
  16658. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16659. {
  16660. check_ascii = value[0];
  16661. if( (check_ascii < 48) || (check_ascii > 57) )
  16662. {
  16663. isSuccess = ConfigurationStatus_Rejected;
  16664. }
  16665. else
  16666. {
  16667. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16668. isSuccess = ConfigurationStatus_Accepted;
  16669. }
  16670. }
  16671. else
  16672. {
  16673. isSuccess = ConfigurationStatus_Rejected;
  16674. }
  16675. }
  16676. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16677. {
  16678. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16679. {
  16680. strcpy(str, (const char*)value);
  16681. for(int i = 0; str[i]; i++)
  16682. {
  16683. str[i] = tolower(str[i]);
  16684. }
  16685. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16686. isSuccess = ConfigurationStatus_Accepted;
  16687. }
  16688. else
  16689. {
  16690. isSuccess = ConfigurationStatus_Rejected;
  16691. }
  16692. }
  16693. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16694. {
  16695. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16696. {
  16697. check_ascii = value[0];
  16698. if( (check_ascii < 48) || (check_ascii > 57) )
  16699. {
  16700. isSuccess = ConfigurationStatus_Rejected;
  16701. }
  16702. else
  16703. {
  16704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16705. isSuccess = ConfigurationStatus_Accepted;
  16706. }
  16707. }
  16708. else
  16709. {
  16710. isSuccess = ConfigurationStatus_Rejected;
  16711. }
  16712. }
  16713. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16714. return isSuccess;
  16715. }
  16716. int TransactionMessageAttemptsGet(void)
  16717. {
  16718. return TransactionMessageAttemptsValue;
  16719. }
  16720. int FirstHeartBeatResponse(void)
  16721. {
  16722. return FirstHeartBeat;
  16723. }
  16724. int TransactionMessageRetryIntervalGet(void)
  16725. {
  16726. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16727. }
  16728. int ReadHttpStatus(int sock)
  16729. {
  16730. //char c;
  16731. char buff[1024]="",*ptr=buff+1;
  16732. int bytes_received, status;
  16733. DEBUG_INFO("Begin Response ..\n");
  16734. while((bytes_received = recv(sock, ptr, 1, 0))){
  16735. if(bytes_received==-1){
  16736. perror("ReadHttpStatus");
  16737. exit(1);
  16738. }
  16739. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16740. ptr++;
  16741. }
  16742. *ptr=0;
  16743. ptr=buff+1;
  16744. sscanf(ptr,"%*s %d ", &status);
  16745. DEBUG_INFO("%s\n",ptr);
  16746. DEBUG_INFO("status=%d\n",status);
  16747. DEBUG_INFO("End Response ..\n");
  16748. return (bytes_received>0)?status:0;
  16749. }
  16750. //the only filed that it parsed is 'Content-Length'
  16751. int ParseHeader(int sock)
  16752. {
  16753. //char c;
  16754. char buff[1024]="",*ptr=buff+4;
  16755. int bytes_received;
  16756. DEBUG_INFO("Begin HEADER ..\n");
  16757. while((bytes_received = recv(sock, ptr, 1, 0))){
  16758. if(bytes_received==-1){
  16759. perror("Parse Header");
  16760. exit(1);
  16761. }
  16762. if(
  16763. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16764. (ptr[-1]=='\r') && (*ptr=='\n' )
  16765. ) break;
  16766. ptr++;
  16767. }
  16768. *ptr=0;
  16769. ptr=buff+4;
  16770. //printf("%s",ptr);
  16771. if(bytes_received){
  16772. ptr=strstr(ptr,"Content-Length:");
  16773. if(ptr){
  16774. sscanf(ptr,"%*s %d",&bytes_received);
  16775. }else
  16776. bytes_received=-1; //unknown size
  16777. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16778. }
  16779. DEBUG_INFO("End HEADER ..\n");
  16780. return bytes_received ;
  16781. }
  16782. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16783. {
  16784. int result = TRUE;
  16785. char rmFileCmd[100]={0};
  16786. char FilePath[100]={0};
  16787. char ftpbuf[200];
  16788. int systemresult;
  16789. sprintf(FilePath,"/mnt/%s",filename);
  16790. system("ping 8.8.8.8 &");
  16791. if((access(FilePath,F_OK))!=-1)
  16792. {
  16793. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16794. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16795. system(rmFileCmd);
  16796. }
  16797. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16798. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16799. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16800. systemresult = system(ftpbuf);
  16801. if(systemresult != 0)
  16802. {
  16803. DEBUG_INFO("http DownLoad error!\n");
  16804. result = FALSE;
  16805. }
  16806. system("pkill ping");
  16807. return result;
  16808. }
  16809. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16810. {
  16811. int result = TRUE;
  16812. char rmFileCmd[100]={0};
  16813. char FilePath[100]={0};
  16814. char ftpbuf[200];
  16815. int systemresult;
  16816. sprintf(FilePath,"/mnt/%s",filename);
  16817. system("ping 8.8.8.8 &");
  16818. if((access(FilePath,F_OK))!=-1)
  16819. {
  16820. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16821. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16822. system(rmFileCmd);
  16823. }
  16824. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16825. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16826. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16827. systemresult = system(ftpbuf);
  16828. if(systemresult != 0)
  16829. {
  16830. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16831. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16832. systemresult = system(ftpbuf);
  16833. if(systemresult != 0)
  16834. {
  16835. DEBUG_WARN("wget error!\n");
  16836. result = FALSE;
  16837. }
  16838. }
  16839. system("pkill ping");
  16840. return result;
  16841. }
  16842. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16843. {
  16844. char rmFileCmd[100]={0};
  16845. char FilePath[100]={0};
  16846. char buf[512];
  16847. int systemresult = 0;
  16848. //DEBUG_INFO("filename=%s\n",filename);
  16849. //DEBUG_INFO("url=%s\n",url);
  16850. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16851. if((access(FilePath,F_OK))!=-1)
  16852. {
  16853. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16854. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16855. system(rmFileCmd);
  16856. }
  16857. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16858. if(fp == NULL)
  16859. {
  16860. DEBUG_INFO("log is NULL\n");
  16861. return FALSE;
  16862. }
  16863. else
  16864. {
  16865. fprintf(fp, "%s\n", url);
  16866. fprintf(fp, "%s\n", filename);
  16867. fclose(fp);
  16868. }
  16869. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16870. if(phpFP == NULL)
  16871. {
  16872. DEBUG_INFO("PHP upload fail.\n");
  16873. return FALSE;
  16874. }
  16875. else
  16876. {
  16877. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16878. {
  16879. if(strstr(buf, "result") != NULL)
  16880. {
  16881. sscanf(buf, "result: %d", &systemresult);
  16882. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16883. }
  16884. }
  16885. pclose(phpFP);
  16886. }
  16887. if(systemresult != 1)
  16888. {
  16889. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  16890. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  16891. if(phpFP == NULL)
  16892. {
  16893. DEBUG_WARN("PHP PUT upload fail.\n");
  16894. return FALSE;
  16895. }
  16896. else
  16897. {
  16898. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16899. {
  16900. if(strstr(buf, "result") != NULL)
  16901. {
  16902. sscanf(buf, "result: %d", &systemresult);
  16903. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  16904. }
  16905. }
  16906. pclose(phpFP);
  16907. }
  16908. }
  16909. return TRUE;
  16910. }
  16911. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16912. {
  16913. int result = FALSE;
  16914. char ftpbuf[200];
  16915. int systemresult;
  16916. /*
  16917. // Domaind name transfer to IP address
  16918. struct hostent* server;
  16919. char *IPbuffer;
  16920. server = gethostbyname(location);
  16921. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16922. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16923. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16924. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16925. systemresult = system(ftpbuf);
  16926. if(systemresult != 0)
  16927. {
  16928. DEBUG_INFO("ftpput error!\n");
  16929. }
  16930. else
  16931. {
  16932. result = TRUE;
  16933. DEBUG_INFO("ftpput OK!\n");
  16934. }
  16935. return result;
  16936. }
  16937. int GetOcppServerURL()
  16938. {
  16939. int result = FALSE;
  16940. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16941. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16942. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16943. struct yuarel url;
  16944. char urlStr[512];
  16945. // OCPPPH only
  16946. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  16947. if((ShmSysConfigAndInfo->SysConfig.MaintainServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.MaintainServerURL,"") != 0) )
  16948. {
  16949. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  16950. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16951. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16952. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.MaintainServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.MaintainServerURL));
  16953. if(yuarel_parse(&url, urlStr) != -1)
  16954. {
  16955. sprintf(OcppProtocol, "%s", url.scheme);
  16956. sprintf(OcppHost, "%s", url.host);
  16957. if(url.path == NULL)
  16958. OcppTempPath[0] = '\0';
  16959. else
  16960. sprintf(OcppTempPath, "%s", url.path);
  16961. if(url.port == 0)
  16962. {
  16963. if(strcmp(OcppProtocol, "wss") == 0)
  16964. OcppPort = 443;
  16965. else
  16966. OcppPort = 80;
  16967. }
  16968. else
  16969. OcppPort = url.port;
  16970. result = TRUE;
  16971. }
  16972. }
  16973. else
  16974. {
  16975. strcpy(OcppHost,"");
  16976. }
  16977. return result;
  16978. }
  16979. int GetOcppPath()
  16980. {
  16981. int result = FALSE;
  16982. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  16983. {
  16984. if(OcppTempPath == NULL)
  16985. {
  16986. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  16987. }
  16988. else
  16989. {
  16990. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  16991. }
  16992. result = TRUE;
  16993. goto End;
  16994. }
  16995. else
  16996. {
  16997. strcpy(OcppPath,"");
  16998. }
  16999. End:
  17000. return result;
  17001. }
  17002. int GetOcppPort()
  17003. {
  17004. return OcppPort;
  17005. }
  17006. int GetOcppConnStatus(void)
  17007. {
  17008. return ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus;
  17009. }
  17010. void SetOcppConnStatus(uint8_t status)
  17011. {
  17012. ShmOCPP16DataPH->OcppConnStatus = status;
  17013. ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus = status;
  17014. }
  17015. int GetHeartBeatWithNOResponse(void)
  17016. {
  17017. return HeartBeatWithNOResponse;
  17018. }
  17019. void SetHeartBeatWithNOResponse(void)
  17020. {
  17021. HeartBeatWithNOResponse = 0;
  17022. }
  17023. void GetStartTransactionIdTag(int gun_index)
  17024. {
  17025. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  17026. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17027. }
  17028. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  17029. {
  17030. char ch;
  17031. FILE *fptr1;
  17032. int temptransactionId;
  17033. char str[100]={0};
  17034. temptransactionId = 0;
  17035. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  17036. {
  17037. DEBUG_INFO("IdTag is empty.\n");
  17038. return temptransactionId;
  17039. }
  17040. /*------ Read the file ----------------*/
  17041. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  17042. if (!fptr1)
  17043. {
  17044. DEBUG_INFO("QueueTransactionId file open error.\n");
  17045. //printf(" File not found or unable to open the input file!!\n");
  17046. return temptransactionId;
  17047. }
  17048. ch=fgetc(fptr1);
  17049. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  17050. rewind(fptr1);
  17051. if(ch!=EOF)
  17052. {
  17053. // printf("%c",ch);
  17054. while (fgets(str, 100, fptr1) != NULL)
  17055. {
  17056. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17057. if(str[0]=='\0')
  17058. {
  17059. break;
  17060. }
  17061. char *revbuf[8] = {0}; // Variable store string split
  17062. int num = 0;// Quantity after string split
  17063. DEBUG_INFO("Transaction queue data= %s\n", str);
  17064. splitstring(str,",",revbuf,&num); // String split
  17065. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  17066. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  17067. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  17068. DEBUG_INFO("------------------------------\n");
  17069. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  17070. {
  17071. if(isStopTransaction)
  17072. {
  17073. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  17074. {
  17075. temptransactionId = atoi(revbuf[2]);
  17076. //break;
  17077. }
  17078. }
  17079. else
  17080. {
  17081. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  17082. {
  17083. temptransactionId = atoi(revbuf[2]);
  17084. //break;
  17085. }
  17086. }
  17087. }
  17088. }
  17089. }
  17090. else
  17091. DEBUG_INFO("EOF\n");
  17092. fclose(fptr1);
  17093. /*------- End of reading ---------------*/
  17094. return temptransactionId;
  17095. }
  17096. void SetTransactionIdZero(int transactionId)
  17097. {
  17098. char ch;
  17099. FILE *fptr1, *fptr2;
  17100. int temptransactionId = 0;
  17101. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  17102. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  17103. if (!fptr1)
  17104. {
  17105. //printf(" File not found or unable to open the input file!!\n");
  17106. return ;
  17107. }
  17108. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  17109. if (!fptr2)
  17110. {
  17111. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  17112. fclose(fptr1);
  17113. return ;
  17114. }
  17115. ch=fgetc(fptr1);
  17116. rewind(fptr1);
  17117. if(ch!=EOF)
  17118. {
  17119. // copy all contents to the temporary file except the specific line
  17120. while (fgets(str, 100, fptr1) != NULL)
  17121. {
  17122. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17123. if(str[0]=='\0')
  17124. {
  17125. break;
  17126. }
  17127. char *revbuf[8] = {0};
  17128. int num = 0;
  17129. strcpy(strtemp, str);
  17130. splitstring(str,",",revbuf,&num);
  17131. if(revbuf[2][0] != '\0')
  17132. {
  17133. temptransactionId = atoi(revbuf[2]);
  17134. if(transactionId != temptransactionId)
  17135. {
  17136. fprintf(fptr2, "%s\n", strtemp);
  17137. }
  17138. }
  17139. }
  17140. }
  17141. fclose(fptr1);
  17142. fclose(fptr2);
  17143. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  17144. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  17145. /*------ Read the file ----------------*/
  17146. }
  17147. int InternetDisconnect(void)
  17148. {
  17149. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  17150. }
  17151. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  17152. void storeTempStopTransaction(int gun_index)
  17153. {
  17154. char guid[37]={0};
  17155. int tempIndex = 0;
  17156. char TempStopTransaction[256];
  17157. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  17158. DEBUG_INFO("storeTempStopTransaction...\n");
  17159. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  17160. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  17161. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  17162. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17163. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17164. {
  17165. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17166. {
  17167. tempIndex = ((gun_index==2) ? 1: 0);
  17168. }
  17169. else
  17170. {
  17171. tempIndex = gun_index;
  17172. }
  17173. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17174. {
  17175. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17176. {
  17177. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  17178. }
  17179. }// END OF CHAdeMO_QUANTITY
  17180. }
  17181. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17182. {
  17183. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17184. {
  17185. tempIndex = ((gun_index==2) ? 1: 0);
  17186. }
  17187. else
  17188. {
  17189. tempIndex = gun_index;
  17190. }
  17191. for (int index = 0; index < CCS_QUANTITY; index++)
  17192. {
  17193. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17194. {
  17195. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  17196. }
  17197. }// END OF CCS_QUANTITY
  17198. }
  17199. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17200. {
  17201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17202. {
  17203. tempIndex = ((gun_index==2) ? 1: 0);
  17204. }
  17205. else
  17206. {
  17207. tempIndex = gun_index;
  17208. }
  17209. for (int index = 0; index < GB_QUANTITY; index++)
  17210. {
  17211. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17212. {
  17213. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  17214. }
  17215. }// END OF GB_QUANTITY
  17216. }
  17217. else if(gunType[gun_index] == GUN_TYPE_DO)
  17218. {
  17219. tempIndex = gun_index;
  17220. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17221. {
  17222. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17223. {
  17224. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  17225. }
  17226. }
  17227. }
  17228. else
  17229. {
  17230. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17231. {
  17232. tempIndex = 2;
  17233. }
  17234. else
  17235. {
  17236. tempIndex = gun_index;
  17237. }
  17238. for (int index = 0; index < AC_QUANTITY; index++)
  17239. {
  17240. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17241. {
  17242. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  17243. }
  17244. }// END OF AC_QUANTITY
  17245. }
  17246. //Stop Transaction Time
  17247. struct timeval tmnow;
  17248. struct tm *tm;
  17249. char buf[28];//, usec_buf[6];
  17250. gettimeofday(&tmnow, NULL);
  17251. time_t t;
  17252. t = time(NULL);
  17253. /*UTC time and date*/
  17254. tm = gmtime(&t);
  17255. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  17256. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  17257. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  17258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  17259. random_uuid(guid);
  17260. /***********************************transactionData******************************************************/
  17261. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  17262. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  17263. //=================================
  17264. //1. Transaction_Begin
  17265. //=================================
  17266. //============================== Energy.Active.Import.Interval ===========================================
  17267. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17268. {
  17269. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  17270. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17271. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  17272. 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*/]);
  17273. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17274. 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))
  17275. {
  17276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  17277. }
  17278. else
  17279. {
  17280. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  17281. }
  17282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  17283. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17284. }
  17285. //=================================
  17286. //2. Transaction_End
  17287. //=================================
  17288. //2.1====================================== Current.Import L1 ==============================================
  17289. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17290. {
  17291. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  17292. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17293. {
  17294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17295. {
  17296. tempIndex = ((gun_index==2) ? 1: 0);
  17297. }
  17298. else
  17299. {
  17300. tempIndex = gun_index;
  17301. }
  17302. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17303. {
  17304. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17305. {
  17306. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17307. }
  17308. }// End of for CHAdeMO_QUANTITY
  17309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17310. }
  17311. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17312. {
  17313. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17314. {
  17315. tempIndex = ((gun_index==2) ? 1: 0);
  17316. }
  17317. else
  17318. {
  17319. tempIndex = gun_index;
  17320. }
  17321. for (int index = 0; index < CCS_QUANTITY; index++)
  17322. {
  17323. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17324. {
  17325. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17326. }
  17327. }// End of for CCS_QUANTITY
  17328. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17329. }
  17330. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17331. {
  17332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17333. {
  17334. tempIndex = ((gun_index==2) ? 1: 0);
  17335. }
  17336. else
  17337. {
  17338. tempIndex = gun_index;
  17339. }
  17340. for (int index = 0; index < GB_QUANTITY; index++)
  17341. {
  17342. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17343. {
  17344. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17345. }
  17346. }// End of for GB_QUANTITY
  17347. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17348. }
  17349. else if(gunType[gun_index] == GUN_TYPE_DO)
  17350. {
  17351. tempIndex = gun_index;
  17352. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17353. {
  17354. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17355. {
  17356. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  17357. }
  17358. }
  17359. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  17360. }
  17361. else
  17362. {
  17363. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17364. {
  17365. tempIndex = 2;
  17366. }
  17367. else
  17368. {
  17369. tempIndex = gun_index;
  17370. }
  17371. for (int index = 0; index < AC_QUANTITY; index++)
  17372. {
  17373. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17374. {
  17375. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  17376. }
  17377. }// End of for AC_QUANTITY
  17378. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17379. }
  17380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  17382. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  17383. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  17384. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  17385. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17386. }
  17387. //2.2===================================== Energy.Active.Import.Interval ==========================================
  17388. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  17389. {
  17390. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17391. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17392. {
  17393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17394. {
  17395. tempIndex = ((gun_index==2) ? 1: 0);
  17396. }
  17397. else
  17398. {
  17399. tempIndex = gun_index;
  17400. }
  17401. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17402. {
  17403. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17404. {
  17405. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17406. }
  17407. }// END OF CHAdeMO_QUANTITY
  17408. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17409. }
  17410. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17411. {
  17412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17413. {
  17414. tempIndex = ((gun_index==2) ? 1: 0);
  17415. }
  17416. else
  17417. {
  17418. tempIndex = gun_index;
  17419. }
  17420. for (int index = 0; index < CCS_QUANTITY; index++)
  17421. {
  17422. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17423. {
  17424. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17425. }
  17426. }// END OF CCS_QUANTITY
  17427. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17428. }
  17429. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17430. {
  17431. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17432. {
  17433. tempIndex = ((gun_index==2) ? 1: 0);
  17434. }
  17435. else
  17436. {
  17437. tempIndex = gun_index;
  17438. }
  17439. for (int index = 0; index < GB_QUANTITY; index++)
  17440. {
  17441. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17442. {
  17443. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17444. }
  17445. }// END OF GB_QUANTITY
  17446. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17447. }
  17448. else if(gunType[gun_index] == GUN_TYPE_DO)
  17449. {
  17450. tempIndex = gun_index;
  17451. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17452. {
  17453. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17454. {
  17455. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17456. }
  17457. }
  17458. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  17459. }
  17460. else
  17461. {
  17462. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17463. {
  17464. tempIndex = 2;
  17465. }
  17466. else
  17467. {
  17468. tempIndex = gun_index;
  17469. }
  17470. for (int index = 0; index < AC_QUANTITY; index++)
  17471. {
  17472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17473. {
  17474. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  17475. }
  17476. }// END OF AC_QUANTITY
  17477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17478. }
  17479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17480. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  17481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  17482. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  17483. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  17484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  17485. }
  17486. //2.3====================================== Power.Active.Import =========================================
  17487. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  17488. {
  17489. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17490. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17491. {
  17492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17493. {
  17494. tempIndex = ((gun_index==2) ? 1: 0);
  17495. }
  17496. else
  17497. {
  17498. tempIndex = gun_index;
  17499. }
  17500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17501. {
  17502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17503. {
  17504. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17505. }
  17506. } // End for CHAdeMO_QUANTITY
  17507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17508. }
  17509. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17510. {
  17511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17512. {
  17513. tempIndex = ((gun_index==2) ? 1: 0);
  17514. }
  17515. else
  17516. {
  17517. tempIndex = gun_index;
  17518. }
  17519. for (int index = 0; index < CCS_QUANTITY; index++)
  17520. {
  17521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17522. {
  17523. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17524. }
  17525. } // END for CCS_QUANTITY
  17526. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17527. }
  17528. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17529. {
  17530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17531. {
  17532. tempIndex = ((gun_index==2) ? 1: 0);
  17533. }
  17534. else
  17535. {
  17536. tempIndex = gun_index;
  17537. }
  17538. for (int index = 0; index < GB_QUANTITY; index++)
  17539. {
  17540. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17541. {
  17542. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17543. }
  17544. }// END for GB_QUANTITY
  17545. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17546. }
  17547. else if(gunType[gun_index] == GUN_TYPE_DO)
  17548. {
  17549. tempIndex = gun_index;
  17550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17551. {
  17552. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17553. {
  17554. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17555. }
  17556. }
  17557. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17558. }
  17559. else
  17560. {
  17561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17562. {
  17563. tempIndex = 2;
  17564. }
  17565. else
  17566. {
  17567. tempIndex = gun_index;
  17568. }
  17569. for (int index = 0; index < AC_QUANTITY; index++)
  17570. {
  17571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17572. {
  17573. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17574. }
  17575. } // END for AC_QUANTITY
  17576. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17577. }
  17578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17579. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17581. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17584. }
  17585. //2.4====================================== Voltage L1 ====================================================
  17586. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17587. {
  17588. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17589. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17590. {
  17591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17592. {
  17593. tempIndex = ((gun_index==2) ? 1: 0);
  17594. }
  17595. else
  17596. {
  17597. tempIndex = gun_index;
  17598. }
  17599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17600. {
  17601. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17602. {
  17603. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17604. }
  17605. } // END OF FOR CHAdeMO_QUANTITY
  17606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17607. }
  17608. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17609. {
  17610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17611. {
  17612. tempIndex = ((gun_index==2) ? 1: 0);
  17613. }
  17614. else
  17615. {
  17616. tempIndex = gun_index;
  17617. }
  17618. for (int index = 0; index < CCS_QUANTITY; index++)
  17619. {
  17620. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17621. {
  17622. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17623. }
  17624. } // END OF FOR CCS_QUANTITY
  17625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17626. }
  17627. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17628. {
  17629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17630. {
  17631. tempIndex = ((gun_index==2) ? 1: 0);
  17632. }
  17633. else
  17634. {
  17635. tempIndex = gun_index;
  17636. }
  17637. for (int index = 0; index < GB_QUANTITY; index++)
  17638. {
  17639. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17640. {
  17641. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17642. }
  17643. } // END OF FOR GB_QUANTITY
  17644. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17645. }
  17646. else if(gunType[gun_index] == GUN_TYPE_DO)
  17647. {
  17648. tempIndex = gun_index;
  17649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17650. {
  17651. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17652. {
  17653. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17654. }
  17655. }
  17656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17657. }
  17658. else
  17659. {
  17660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17661. {
  17662. tempIndex = 2;
  17663. }
  17664. else
  17665. {
  17666. tempIndex = gun_index;
  17667. }
  17668. for (int index = 0; index < AC_QUANTITY; index++)
  17669. {
  17670. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17671. {
  17672. 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
  17673. }
  17674. } // END OF FOR AC_QUANTITY
  17675. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17676. }
  17677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17678. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17680. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17683. }
  17684. //2.5============================================== End SoC =========================================================
  17685. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17686. {
  17687. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17688. 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))
  17689. {
  17690. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17691. {
  17692. tempIndex = ((gun_index==2) ? 1: 0);
  17693. }
  17694. else
  17695. {
  17696. tempIndex = gun_index;
  17697. }
  17698. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17699. {
  17700. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17701. {
  17702. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17703. {
  17704. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17705. }
  17706. }
  17707. }
  17708. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17709. {
  17710. for (int index = 0; index < CCS_QUANTITY; index++)
  17711. {
  17712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17713. {
  17714. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17715. }
  17716. }
  17717. }
  17718. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17719. {
  17720. for (int index = 0; index < GB_QUANTITY; index++)
  17721. {
  17722. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17723. {
  17724. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17725. }
  17726. }
  17727. }
  17728. else if(gunType[gun_index] == GUN_TYPE_DO)
  17729. {
  17730. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17731. {
  17732. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17733. {
  17734. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17735. }
  17736. }
  17737. }
  17738. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17739. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17744. } // END FOR DC CASE
  17745. }
  17746. //2.6====================================== Current.Import L2 ==============================================
  17747. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17748. {
  17749. // AC 3 phase L2 current
  17750. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17751. {
  17752. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17753. {
  17754. tempIndex = 2;
  17755. }
  17756. else
  17757. {
  17758. tempIndex = gun_index;
  17759. }
  17760. for (int index = 0; index < AC_QUANTITY; index++)
  17761. {
  17762. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17763. {
  17764. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17765. }
  17766. }// End of for AC_QUANTITY
  17767. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17768. }
  17769. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17770. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17771. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17772. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17773. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17774. }
  17775. //2.7====================================== Current.Import L3 ==============================================
  17776. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17777. {
  17778. // AC 3 phase L3 current
  17779. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17780. {
  17781. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17782. {
  17783. tempIndex = 2;
  17784. }
  17785. else
  17786. {
  17787. tempIndex = gun_index;
  17788. }
  17789. for (int index = 0; index < AC_QUANTITY; index++)
  17790. {
  17791. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17792. {
  17793. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17794. }
  17795. }// End of for AC_QUANTITY
  17796. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17797. }
  17798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17799. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17803. }
  17804. //2.9====================================== Voltage L2 ====================================================
  17805. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17806. {
  17807. // AC 3 phase L2 volatge
  17808. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17809. {
  17810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17811. {
  17812. tempIndex = 2;
  17813. }
  17814. else
  17815. {
  17816. tempIndex = gun_index;
  17817. }
  17818. for (int index = 0; index < AC_QUANTITY; index++)
  17819. {
  17820. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17821. {
  17822. 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
  17823. }
  17824. } // END OF FOR AC_QUANTITY
  17825. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17826. }
  17827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17829. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17830. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17831. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17832. }
  17833. //2.10====================================== Voltage L3 ====================================================
  17834. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17835. {
  17836. // AC 3 phase L3 volatge
  17837. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17838. {
  17839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17840. {
  17841. tempIndex = 2;
  17842. }
  17843. else
  17844. {
  17845. tempIndex = gun_index;
  17846. }
  17847. for (int index = 0; index < AC_QUANTITY; index++)
  17848. {
  17849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17850. {
  17851. 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
  17852. }
  17853. } // END OF FOR AC_QUANTITY
  17854. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17855. }
  17856. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17857. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17859. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17861. }
  17862. //====================== Start SoC ================================
  17863. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17864. {
  17865. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17866. 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))
  17867. {
  17868. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17869. {
  17870. tempIndex = ((gun_index==2) ? 1: 0);
  17871. }
  17872. else
  17873. {
  17874. tempIndex = gun_index;
  17875. }
  17876. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17877. {
  17878. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17879. {
  17880. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17881. {
  17882. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17883. }
  17884. }
  17885. }
  17886. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17887. {
  17888. for (int index = 0; index < CCS_QUANTITY; index++)
  17889. {
  17890. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17891. {
  17892. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17893. }
  17894. }
  17895. }
  17896. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17897. {
  17898. for (int index = 0; index < GB_QUANTITY; index++)
  17899. {
  17900. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17901. {
  17902. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17903. }
  17904. }
  17905. }
  17906. else if(gunType[gun_index] == GUN_TYPE_DO)
  17907. {
  17908. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17909. {
  17910. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17911. {
  17912. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17913. }
  17914. }
  17915. }
  17916. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17920. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17922. } // END FOR DC CASE
  17923. }
  17924. //======================================== Message create ==============================================
  17925. json_object *StopTransaction = json_object_new_object();
  17926. json_object *transactionDatas = json_object_new_array();
  17927. json_object *sampledValues = json_object_new_array();
  17928. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  17929. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  17930. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  17931. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  17932. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  17933. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17934. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  17935. {
  17936. json_object *transactionData = json_object_new_object();
  17937. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17938. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17939. {
  17940. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17941. {
  17942. json_object *sampledValue = json_object_new_object();
  17943. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17944. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17945. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17946. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17947. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17948. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17949. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17950. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17951. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17952. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17953. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17954. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17955. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17956. json_object_array_add(sampledValues, sampledValue);
  17957. }
  17958. }
  17959. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17960. json_object_array_add(transactionDatas, transactionData);
  17961. }
  17962. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17963. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17964. ,MESSAGE_TYPE_CALL
  17965. ,guid
  17966. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17967. json_object_put(StopTransaction);
  17968. // Check File "TempStopTransaction" Exist
  17969. if((access(TempStopTransaction,F_OK))!=-1)
  17970. {
  17971. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17972. fclose(fopen(TempStopTransaction, "w"));
  17973. }
  17974. else
  17975. {
  17976. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17977. FILE *log = fopen(TempStopTransaction, "w+");
  17978. if(log == NULL)
  17979. {
  17980. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17981. return ;
  17982. }
  17983. else
  17984. {
  17985. fclose(log);
  17986. }
  17987. }
  17988. //Add TempStopTransaction | Update TempStopTransaction
  17989. // open file for writing
  17990. FILE *outfile;
  17991. outfile = fopen (TempStopTransaction, "a");
  17992. //DEBUG_INFO("data = %s\n", queuedata);
  17993. fputs(queuedata, outfile);
  17994. fputs("\n", outfile);
  17995. fclose (outfile);
  17996. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17997. }
  17998. void checkTempStopTransaction(int gun_index)
  17999. {
  18000. FILE *fptr1;
  18001. char ch;
  18002. char str[QUEUE_MESSAGE_LENGTH]={0};
  18003. char guid[37]={0};
  18004. char tempdata[65]={0};
  18005. char connectorStr[2]={0};
  18006. char TempStopTransaction[256];
  18007. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  18008. fptr1 = fopen(TempStopTransaction, "r");
  18009. //TempStopTransaction格式: 槍號,StopTransaction封包
  18010. if (!fptr1)
  18011. {
  18012. //printf(" File not found or unable to open the input file!!\n");
  18013. return ;
  18014. }
  18015. ch=fgetc(fptr1);
  18016. //printf(" Now the content of the file %s is : \n",fname);
  18017. rewind(fptr1);
  18018. if(ch!=EOF)
  18019. {
  18020. // copy all contents to the temporary file except the specific line
  18021. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18022. {
  18023. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18024. if(str[0]=='\0')
  18025. {
  18026. break;
  18027. }
  18028. //TempStopTransaction格式: 槍號,StopTransaction封包
  18029. strncpy(connectorStr, str, 1);
  18030. if(atoi(connectorStr) != (gun_index+1))
  18031. {
  18032. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  18033. fclose(fptr1);
  18034. return ;
  18035. }
  18036. //random_uuid(guid);
  18037. strncpy(guid, str+6, 36); //copy guid
  18038. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  18039. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18040. {
  18041. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18042. }
  18043. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18044. OCPP_insert_transaction_msg(NO, str);
  18045. memset(str,0,ARRAY_SIZE(str));
  18046. }
  18047. }
  18048. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18049. fclose(fptr1);
  18050. remove(TempStopTransaction); // remove the original file
  18051. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  18052. }
  18053. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  18054. {
  18055. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  18056. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  18057. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  18058. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  18059. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  18060. }
  18061. int GetWebSocketPingInterval(void)
  18062. {
  18063. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  18064. }
  18065. int GetServerSign(void)
  18066. {
  18067. return server_sign;
  18068. }
  18069. uint8_t GetOcppSecurityProfile()
  18070. {
  18071. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  18072. }
  18073. void GetOcppChargerBoxId(uint8_t *data)
  18074. {
  18075. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  18076. }
  18077. void GetOcppSecurityPassword(uint8_t *data)
  18078. {
  18079. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  18080. }
  18081. void SetOcppVersion(uint8_t *version)
  18082. {
  18083. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  18084. DEBUG_INFO("ocpp version: %s\n", version);
  18085. if(strstr((char*)version, "ocpp1.6") != NULL)
  18086. {
  18087. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  18088. }
  18089. else if(strstr((char*)version, "ocpp2.0") != NULL)
  18090. {
  18091. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  18092. system("pkill OcppBackend");
  18093. }
  18094. }
  18095. void SetServerSign(int value)
  18096. {
  18097. server_sign = value;
  18098. }
  18099. int GetBootNotificationInterval(void)
  18100. {
  18101. return BootNotificationInterval;
  18102. }
  18103. int GetInternetConn(void)
  18104. {
  18105. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18106. }
  18107. int GetBackendConnectionTimeout(void)
  18108. {
  18109. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18110. }
  18111. int isConnectorInitMode(int gun_index)
  18112. {
  18113. int tempIndex = 0;
  18114. int result = TRUE;
  18115. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18116. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18117. {
  18118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18119. {
  18120. tempIndex = ((gun_index==2) ? 1: 0);
  18121. }
  18122. else
  18123. {
  18124. tempIndex = gun_index;
  18125. }
  18126. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18127. {
  18128. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18129. {
  18130. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18131. } //end of the same index
  18132. }//end of for CHAdeMO_QUANTITY
  18133. }
  18134. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18135. {
  18136. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18137. {
  18138. tempIndex = ((gun_index==2) ? 1: 0);
  18139. }
  18140. else
  18141. {
  18142. tempIndex = gun_index;
  18143. }
  18144. for (int index = 0; index < CCS_QUANTITY; index++)
  18145. {
  18146. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18147. {
  18148. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18149. } //end of the same index
  18150. } // end of for CCS_QUANTITY
  18151. }
  18152. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18153. {
  18154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18155. {
  18156. tempIndex = ((gun_index==2) ? 1: 0);
  18157. }
  18158. else
  18159. {
  18160. tempIndex = gun_index;
  18161. }
  18162. for (int index = 0; index < GB_QUANTITY; index++)
  18163. {
  18164. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18165. {
  18166. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18167. } //end of the same index
  18168. } // end of for GB_QUANTITY
  18169. }
  18170. else if(gunType[gun_index] == GUN_TYPE_DO)
  18171. {
  18172. tempIndex = gun_index;
  18173. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18174. {
  18175. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18176. {
  18177. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18178. } //end of the same index
  18179. }
  18180. }
  18181. else
  18182. {
  18183. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18184. {
  18185. tempIndex = 2;
  18186. }
  18187. else
  18188. {
  18189. tempIndex = gun_index;
  18190. }
  18191. for (int index = 0; index < AC_QUANTITY; index++)
  18192. {
  18193. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  18194. {
  18195. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18196. }//end of the same index
  18197. }//end of for AC_QUANTITY
  18198. }
  18199. return result;
  18200. }
  18201. void refreshProcDogTimer()
  18202. {
  18203. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  18204. }
  18205. void InitialSystemValue(void)
  18206. {
  18207. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  18208. locallistVersion=0;
  18209. BootNotificationInterval = 0;
  18210. authorizeRetryTimes = 0;
  18211. GunStatusInterval = 10;
  18212. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  18213. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18214. //Hear Beat
  18215. HeartBeatWithNOResponse = 0;
  18216. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  18217. FirstHeartBeat = 0;
  18218. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  18219. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  18220. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  18221. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  18222. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  18223. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  18224. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  18225. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  18226. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  18227. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  18228. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  18229. //Status && ConnectorPlugIn Setting
  18230. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18231. {
  18232. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  18233. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  18234. }
  18235. for (int index = 0; index < CCS_QUANTITY; index++)
  18236. {
  18237. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  18238. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  18239. }
  18240. for (int index = 0; index < GB_QUANTITY; index++)
  18241. {
  18242. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  18243. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  18244. }
  18245. for (int index = 0; index < AC_QUANTITY; index++)
  18246. {
  18247. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  18248. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  18249. }
  18250. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18251. {
  18252. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  18253. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  18254. }
  18255. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  18256. {
  18257. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  18258. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  18259. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  18260. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  18261. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  18262. }
  18263. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  18264. refreshStartTimer(&clientTime.Heartbeat);
  18265. sleep(1);
  18266. }
  18267. void LWS_Send(char *str)
  18268. {
  18269. //=====================================================
  18270. // Check InternetConn 0: disconnected, 1: connected
  18271. //====================================================
  18272. if(GetOcppConnStatus() == 0)
  18273. {
  18274. DEBUG_INFO("offline now !!!\n");
  18275. return;
  18276. }
  18277. // Only disable isWebsocketSendable operation initiated by charger
  18278. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18279. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18280. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18281. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18282. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18283. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18284. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18285. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18286. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18287. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18288. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18289. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18290. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18291. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18292. {
  18293. isWebsocketSendable = 0;
  18294. }
  18295. pthread_mutex_lock(&lock_send);
  18296. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18297. sprintf((char *)SendBuffer, "%s", str);
  18298. SendBufLen = strlen(str);
  18299. pthread_mutex_unlock(&lock_send);
  18300. lws_callback_on_writable(wsi_client);
  18301. //lws_service(context, 0);
  18302. //sleep(1);
  18303. }
  18304. void LWS_SendNow(char *str)
  18305. {
  18306. //=====================================================
  18307. // Check InternetConn 0: disconnected, 1: connected
  18308. //====================================================
  18309. if(GetOcppConnStatus() == 0)
  18310. {
  18311. DEBUG_INFO("offline now !!!\n");
  18312. return;
  18313. }
  18314. // Only disable isWebsocketSendable operation initiated by charger
  18315. if((strstr((char*)str, "\"Authorize\"") != NULL)
  18316. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  18317. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  18318. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  18319. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  18320. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  18321. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  18322. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  18323. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  18324. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  18325. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  18326. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  18327. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  18328. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  18329. {
  18330. isWebsocketSendable = 0;
  18331. }
  18332. pthread_mutex_lock(&lock_send);
  18333. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  18334. sprintf((char *)SendBuffer, "%s", str);
  18335. SendBufLen = strlen(str);
  18336. pthread_mutex_unlock(&lock_send);
  18337. lws_callback_on_writable(wsi_client);
  18338. lws_service(context, 0);
  18339. //sleep(1);
  18340. }