MessageHandler.c 847 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct InterLock
  92. {
  93. unsigned char isGetDiagnosticGoing:1;
  94. unsigned char isUpdateFirmwareGoing:1;
  95. }interLock;
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // TTIA routine
  356. //=========================================
  357. int sendTTIAInfo(uint8_t gun_index)
  358. {
  359. static int sn = 0;
  360. int result = FAIL;
  361. struct hostent *server;
  362. int udp_socket_fd;
  363. struct sockaddr_in dest_addr = {0};
  364. uint8_t tx_buf[80] = {0};
  365. uint8_t logBuf[256]= {0};
  366. uint8_t tx_len, tempIndex, socStart, socEnd;
  367. uint16_t PresentChargedEnergy;
  368. struct tm tmStart, tmEnd;
  369. DEBUG_INFO("sendTTIAInfo...\n");
  370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  371. {
  372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  373. {
  374. tempIndex = ((gun_index==2) ? 1: 0);
  375. }
  376. else
  377. {
  378. tempIndex = gun_index;
  379. }
  380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  381. {
  382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  383. {
  384. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  385. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  386. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  387. }
  388. }
  389. }
  390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  391. {
  392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  393. {
  394. tempIndex = ((gun_index==2) ? 1: 0);
  395. }
  396. else
  397. {
  398. tempIndex = gun_index;
  399. }
  400. for (int index = 0; index < CCS_QUANTITY; index++)
  401. {
  402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  403. {
  404. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  405. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  406. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  407. }
  408. }
  409. }
  410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < GB_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_DO)
  431. {
  432. tempIndex = gun_index;
  433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  434. {
  435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  436. {
  437. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  438. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  439. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  440. }
  441. }
  442. }
  443. else
  444. {
  445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  446. {
  447. tempIndex = 2;
  448. }
  449. else
  450. {
  451. tempIndex = gun_index;
  452. }
  453. for (int index = 0; index < AC_QUANTITY; index++)
  454. {
  455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  456. {
  457. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  458. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  459. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  460. }
  461. }// END
  462. }
  463. // Message assembly
  464. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  465. tx_buf[4] = 0x02; // Protocol Version
  466. tx_buf[5] = 0xb0; // Message ID
  467. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  468. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  469. tx_buf[8] = 0x00; // CarID low byte
  470. tx_buf[9] = 0x00; // CarID high byte
  471. tx_buf[10] = 0x00; // ID Storage
  472. tx_buf[11] = 0x00; // Driver lowest byte
  473. tx_buf[12] = 0x00; // Driver 2nd byte
  474. tx_buf[13] = 0x00; // Driver 3rd byte
  475. tx_buf[14] = 0x00; // Driver highest byte
  476. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  477. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  478. tx_buf[17] = 0x00; // Reserve
  479. tx_buf[18] = 60 & 0xff; // Payload length low byte
  480. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  481. // EVSE provider
  482. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  483. // EVSE provider
  484. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  485. // EVSE id
  486. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  487. // Connector id
  488. tx_buf[37] = gun_index;
  489. // EVSE station
  490. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  491. // Vehicle SN
  492. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  493. // Mileage
  494. tx_buf[61] = 0x00; // lowest byte
  495. tx_buf[62] = 0x00; // 2nd byte
  496. tx_buf[63] = 0x00; // highest byte
  497. // Start date time 6 bytes
  498. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%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))
  499. {
  500. struct tm *tmTarget;
  501. struct timeb tbTarget;
  502. tmStart.tm_year -= 1900;
  503. tmStart.tm_mon -= 1;
  504. tmStart.tm_gmtoff = 0;
  505. tbTarget.time = mktime(&tmStart);
  506. tbTarget.timezone = 0;
  507. tbTarget.time += (8*3600);
  508. tmTarget = gmtime(&tbTarget.time);
  509. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  510. tx_buf[65] = (tmTarget->tm_mon+1);
  511. tx_buf[66] = tmTarget->tm_mday;
  512. tx_buf[67] = tmTarget->tm_hour;
  513. tx_buf[68] = tmTarget->tm_min;
  514. tx_buf[69] = tmTarget->tm_sec;
  515. }
  516. // Stop date time 6 bytes
  517. if((sscanf((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmEnd.tm_year, &tmEnd.tm_mon, &tmEnd.tm_mday, &tmEnd.tm_hour, &tmEnd.tm_min, &tmEnd.tm_sec) == 6))
  518. {
  519. struct tm *tmTarget;
  520. struct timeb tbTarget;
  521. tmEnd.tm_year -= 1900;
  522. tmEnd.tm_mon -= 1;
  523. tmEnd.tm_gmtoff = 0;
  524. tbTarget.time = mktime(&tmEnd);
  525. tbTarget.timezone = 0;
  526. tbTarget.time += (8*3600);
  527. tmTarget = gmtime(&tbTarget.time);
  528. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  529. tx_buf[71] = (tmTarget->tm_mon+1);
  530. tx_buf[72] = tmTarget->tm_mday;
  531. tx_buf[73] = tmTarget->tm_hour;
  532. tx_buf[74] = tmTarget->tm_min;
  533. tx_buf[75] = tmTarget->tm_sec;
  534. }
  535. // Session energy 2 bytes
  536. tx_buf[76] = PresentChargedEnergy & 0xff;
  537. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  538. // Start SOC 1 byte
  539. tx_buf[78] = socStart;
  540. // Stop SOC 1 byte
  541. tx_buf[79] = socEnd;
  542. // Open socket
  543. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  544. if(udp_socket_fd == -1)
  545. {
  546. DEBUG_ERROR("UDP socket create failed!\n");
  547. }
  548. else
  549. {
  550. // Get server DNS entry
  551. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  552. if (server == NULL)
  553. {
  554. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  555. }
  556. else
  557. {
  558. // Build the server's Internet address
  559. bzero((char *) &dest_addr, sizeof(dest_addr));
  560. dest_addr.sin_family = AF_INET;
  561. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  562. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  563. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  564. {
  565. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  566. {
  567. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  568. }
  569. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  570. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  571. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  572. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  573. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  574. DEBUG_TTIA_INFO("---------- Header ----------\n");
  575. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  576. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  577. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  578. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  579. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  580. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  581. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  582. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  583. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  584. DEBUG_TTIA_INFO("Len: 0x3C\n");
  585. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  586. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  587. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  588. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  589. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  590. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  591. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  592. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  593. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  594. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  595. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  596. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  597. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  598. DEBUG_TTIA_INFO("=========================================\n");
  599. sn++;
  600. result = PASS;
  601. }
  602. else
  603. {
  604. DEBUG_ERROR("UDP sent out fail.\n");
  605. }
  606. }
  607. }
  608. return result;
  609. }
  610. //=========================================
  611. // Save configuration
  612. //=========================================
  613. int runShellCmd(const char*cmd)
  614. {
  615. int result = FAIL;
  616. char buf[256];
  617. FILE *fp;
  618. fp = popen(cmd, "r");
  619. if(fp != NULL)
  620. {
  621. while(fgets(buf, sizeof(buf), fp) != NULL)
  622. {
  623. DEBUG_INFO("%s\n", buf);
  624. }
  625. result = PASS;
  626. }
  627. pclose(fp);
  628. return result;
  629. }
  630. int StoreUsrConfigData(struct SysConfigData *UsrData)
  631. {
  632. int result = PASS;
  633. int fd,wrd;
  634. unsigned int i,Chk;
  635. unsigned char *ptr, *BufTmp;
  636. int MtdBlockSize = 0x300000;
  637. Chk=0;
  638. ptr=(unsigned char *)UsrData;
  639. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  640. {
  641. memset(BufTmp,0,MtdBlockSize);
  642. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  643. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  644. Chk+=*(BufTmp+i);
  645. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  646. // Output configuration to file.
  647. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  648. if (fd < 0)
  649. {
  650. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  651. free(BufTmp);
  652. return 0;
  653. }
  654. wrd=write(fd, BufTmp, MtdBlockSize);
  655. close(fd);
  656. if(wrd<MtdBlockSize)
  657. {
  658. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  659. free(BufTmp);
  660. return 0;
  661. }
  662. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  663. DEBUG_INFO("Erase /dev/mtd10.\n");
  664. runShellCmd("flash_erase /dev/mtd10 0 0");
  665. DEBUG_INFO("Write /dev/mtd10.\n");
  666. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  667. DEBUG_INFO("Erase /dev/mtd11.\n");
  668. runShellCmd("flash_erase /dev/mtd11 0 0");
  669. DEBUG_INFO("Write /dev/mtd11.\n");
  670. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  671. system("rm -f /mnt/EvseConfig.bin");
  672. DEBUG_INFO("EvseConfig write to flash OK\n");
  673. }
  674. else
  675. {
  676. DEBUG_ERROR("alloc BlockSize NG\r\n");
  677. result = FAIL;
  678. }
  679. if(BufTmp!=NULL)
  680. free(BufTmp);
  681. return result;
  682. }
  683. //=========================================
  684. // Sqlite3 related function
  685. //=========================================
  686. static int selectSqlCount = 0;
  687. static int callback(void *data, int argc, char **argv, char **azColName){
  688. int i;
  689. //printf("%s: ", (const char*)data);
  690. selectSqlCount = argc;
  691. for(i = 0; i<argc; i++){
  692. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  693. }
  694. //printf("\n");
  695. return 0;
  696. }
  697. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  698. //int i;
  699. //printf("%s:\n", (const char*)data);
  700. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  701. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  702. return 0;
  703. }
  704. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  705. //printf("%s:\n", (const char*)data);
  706. //idTag
  707. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  708. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  709. //parentIdTag
  710. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  711. //expir_date
  712. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  713. //status
  714. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  715. //version
  716. if(columenCount > 5)
  717. idTagQuery.listVersionInt = atoi(columnValue[5]);
  718. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  719. return 0;
  720. }
  721. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  722. {
  723. // localversion = argv[5] ? atoi(argv[5]) : 0;
  724. // printf("localversion=%d\n", localversion);
  725. return 0;
  726. }
  727. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  728. {
  729. for (int i = 0; i < n_columns; i++)
  730. {
  731. DEBUG_INFO("%s\t", col_values[i]);
  732. }
  733. DEBUG_INFO("\n");
  734. return 0;
  735. }
  736. int OCPP_cleanLocalCache()
  737. {
  738. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  739. char *errMsg = 0;
  740. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  741. if (SQLITE_OK != rc)
  742. {
  743. DEBUG_INFO("SQL error: %s\n",errMsg);
  744. return FALSE;
  745. }
  746. return TRUE;
  747. }
  748. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  749. {
  750. int isSuccess = TRUE;
  751. int ret = 0;
  752. //const char* data = "Callback function called";
  753. char sql[300];
  754. char zErrMsg[200];
  755. memset(sql, 0, 300);
  756. memset(zErrMsg, 0, 200);
  757. 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);
  758. //* Execute SQL statement */
  759. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  760. if( ret != SQLITE_OK )
  761. {
  762. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  763. isSuccess = FALSE;
  764. }
  765. return isSuccess;
  766. }
  767. void OCPP_getIdTagFromLocalCache(char idTag[])
  768. {
  769. int rc = 0;
  770. char sql[100];
  771. char zErrMsg[100];
  772. memset(sql, 0, 100);
  773. memset(zErrMsg, 0, 100);
  774. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  775. memset(&idTagQuery, 0, sizeof(idTagQuery));
  776. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  777. /* Execute SQL statement */
  778. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  779. if( rc != SQLITE_OK )
  780. {
  781. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  782. }
  783. }
  784. void OCPP_getListVerion()
  785. {
  786. int rc = 0;
  787. // const char* data = "Callback function called";
  788. char sql[100];
  789. char zErrMsg[100];
  790. memset(sql, 0, 100);
  791. memset(zErrMsg, 0, 100);
  792. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  793. /* Execute SQL statement */
  794. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  795. if( rc != SQLITE_OK )
  796. {
  797. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  798. }
  799. }
  800. void OCPP_get_TableAuthlocalAllData(void)
  801. {
  802. int rc = 0;
  803. char sql[100];
  804. char zErrMsg[100];
  805. memset(sql, 0, 100);
  806. memset(zErrMsg, 0, 100);
  807. sprintf(sql,"select * from ocpp_auth_local ");
  808. /* Execute SQL statement */
  809. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  810. if( rc != SQLITE_OK )
  811. {
  812. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  813. }
  814. //return ver;
  815. }
  816. int OCPP_cleanLocalList()
  817. {
  818. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  819. char *errMsg = 0;
  820. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  821. if (SQLITE_OK != rc)
  822. {
  823. DEBUG_INFO("%s\n",errMsg);
  824. return FALSE;
  825. }
  826. return TRUE;
  827. }
  828. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  829. {
  830. int isSuccess = FALSE;
  831. int ret = 0;
  832. //const char* data = "Callback function called";
  833. char sql[300];
  834. char zErrMsg[200];
  835. memset(sql, 0, 300);
  836. memset(zErrMsg, 0, 200);
  837. 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);
  838. //* Execute SQL statement */
  839. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  840. if( ret != SQLITE_OK )
  841. {
  842. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  843. return isSuccess;
  844. }
  845. memset(sql, 0, 300);
  846. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  847. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  848. if( ret != SQLITE_OK )
  849. {
  850. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  851. return isSuccess;
  852. }
  853. isSuccess = TRUE;
  854. return isSuccess;
  855. }
  856. void OCPP_getIdTagFromLocalList(char idTag[])
  857. {
  858. int rc = 0;
  859. // const char* data = "Callback function called";
  860. char sql[100];
  861. char zErrMsg[100];
  862. memset(sql, 0, 100);
  863. memset(zErrMsg, 0, 100);
  864. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  865. memset(&idTagQuery, 0, sizeof(idTagQuery));
  866. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  867. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  868. /* Execute SQL statement */
  869. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  870. if( rc != SQLITE_OK )
  871. {
  872. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  873. }
  874. //return ver;
  875. }
  876. void OCPP_deleteIdTagFromLocalList(char idTag[])
  877. {
  878. //int ver = 0;
  879. //int isSuccess = FALSE;
  880. int rc = 0;
  881. char sql[100];
  882. char zErrMsg[100];
  883. memset(sql, 0, 100);
  884. memset(zErrMsg, 0, 100);
  885. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  886. //* Execute SQL statement */
  887. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  888. if( rc != SQLITE_OK )
  889. {
  890. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  891. }
  892. }
  893. int getCurrentYear()
  894. {
  895. int result = 0;
  896. time_t CurrentTime;
  897. struct tm *tm;
  898. CurrentTime = time(NULL);
  899. tm=localtime(&CurrentTime);
  900. result = (tm->tm_year + 1900);
  901. return result;
  902. }
  903. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  904. {
  905. int result = PASS;
  906. char* errMsg = NULL;
  907. char sqlStr[8192];
  908. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  909. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  910. {
  911. result = FAIL;
  912. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  913. }
  914. 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));
  915. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  916. {
  917. result = FAIL;
  918. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  919. }
  920. return result;
  921. }
  922. //==========================================
  923. // Check time passed since today
  924. //==========================================
  925. long long DiffTimebWithNow(struct timeb ST)
  926. {
  927. //return milli-second
  928. struct timeb ET;
  929. long long StartTime,StopTime;
  930. ftime(&ET);
  931. StartTime=(long long)ST.time;
  932. StopTime=(long long)ET.time;
  933. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  934. }
  935. int getTimePassSinceToday(uint8_t gun_index)
  936. {
  937. int result = -1;
  938. static time_t lastTime[4];
  939. time_t t;
  940. struct tm *tmStartToday;
  941. struct timeb tbStartToday;
  942. t=time(NULL);
  943. if(difftime(t, lastTime[gun_index])>0)
  944. {
  945. tmStartToday=localtime(&t);
  946. tmStartToday->tm_hour = 0;
  947. tmStartToday->tm_min = 0;
  948. tmStartToday->tm_sec = 0;
  949. tbStartToday.time = mktime(tmStartToday);
  950. tbStartToday.millitm = 0;
  951. result = DiffTimebWithNow(tbStartToday)/1000;
  952. lastTime[gun_index] = t;
  953. }
  954. return result;
  955. }
  956. void getNowDatetime(uint8_t *data)
  957. {
  958. time_t t = time(NULL);
  959. struct tm tm = *localtime(&t);
  960. 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);
  961. }
  962. int syncDateTimeRTC(uint8_t *data)
  963. {
  964. struct ParsingResult
  965. {
  966. int result;
  967. int scanedElement;
  968. int year;
  969. int month;
  970. int mday;
  971. int hour;
  972. int min;
  973. int sec;
  974. int tz_hour;
  975. int tz_min;
  976. float minSec;
  977. }result;
  978. struct tm tmOrg;
  979. struct tm *tmTarget;
  980. struct timeb tbTarget;
  981. char buf[128];
  982. memset(&result, 0x00, sizeof(struct ParsingResult));
  983. result.result = PASS;
  984. if(strstr((char*)data, ".") != NULL)
  985. {
  986. // Original data with mini second
  987. if(strstr((char*)data, "Z") != NULL)
  988. {
  989. // Original data with Z
  990. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  991. &result.year,
  992. &result.month,
  993. &result.mday,
  994. &result.hour,
  995. &result.min,
  996. &result.sec,
  997. &result.minSec);
  998. }
  999. else
  1000. {
  1001. // Original data without Z
  1002. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1003. &result.year,
  1004. &result.month,
  1005. &result.mday,
  1006. &result.hour,
  1007. &result.min,
  1008. &result.sec,
  1009. &result.minSec,
  1010. &result.tz_hour,
  1011. &result.tz_min);
  1012. }
  1013. }
  1014. else
  1015. {
  1016. // Original data without mini second
  1017. if(strstr((char*)data, "Z") != NULL)
  1018. {
  1019. // Original data with Z
  1020. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1021. &result.year,
  1022. &result.month,
  1023. &result.mday,
  1024. &result.hour,
  1025. &result.min,
  1026. &result.sec);
  1027. }
  1028. else
  1029. {
  1030. // Original data without Z
  1031. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1032. &result.year,
  1033. &result.month,
  1034. &result.mday,
  1035. &result.hour,
  1036. &result.min,
  1037. &result.sec,
  1038. &result.tz_hour,
  1039. &result.tz_min);
  1040. }
  1041. }
  1042. tmOrg.tm_year = result.year - 1900;
  1043. tmOrg.tm_mon = result.month - 1;
  1044. tmOrg.tm_mday = result.mday;
  1045. tmOrg.tm_hour = result.hour;
  1046. tmOrg.tm_min = result.min;
  1047. tmOrg.tm_sec = result.sec;
  1048. tmOrg.tm_gmtoff = 0;
  1049. tbTarget.time = mktime(&tmOrg);
  1050. tbTarget.timezone = 0;
  1051. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1052. tmTarget = gmtime(&tbTarget.time);
  1053. 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);
  1054. //DEBUG_INFO(" org date time: %s\n", data);
  1055. //DEBUG_INFO("parse date time: %s\n", buf);
  1056. system(buf);
  1057. system("/sbin/hwclock -w --systohc");
  1058. if(result.scanedElement < 6)
  1059. result.result = FAIL;
  1060. return result.result;
  1061. }
  1062. //==========================================
  1063. // GetCompositeSchedule logic related function
  1064. //==========================================
  1065. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1066. {
  1067. //return milli-second
  1068. unsigned int StartTime,StopTime;
  1069. StartTime=(unsigned int)ST.time;
  1070. StopTime=(unsigned int)ET.time;
  1071. return (StopTime-StartTime);
  1072. }
  1073. int DiffTimebWithNowSec(struct timeb ST)
  1074. {
  1075. //return milli-second
  1076. struct timeb ET;
  1077. unsigned int StartTime,StopTime;
  1078. ftime(&ET);
  1079. StartTime=(unsigned int)ST.time;
  1080. StopTime=(unsigned int)ET.time;
  1081. return (StopTime-StartTime);
  1082. }
  1083. int getStartStop(uint8_t *start, uint8_t *stop)
  1084. {
  1085. int result = -1;
  1086. struct tm tmStart;
  1087. struct timeb tbStart;
  1088. struct tm tmStop;
  1089. struct timeb tbStop;
  1090. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1091. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1092. {
  1093. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  1094. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  1095. tmStart.tm_year -= 1900;
  1096. tmStart.tm_mon -= 1;
  1097. tbStart.time = mktime(&tmStart);
  1098. tbStart.millitm = 0;
  1099. tmStop.tm_year -= 1900;
  1100. tmStop.tm_mon -= 1;
  1101. tbStop.time = mktime(&tmStop);
  1102. tbStop.millitm = 0;
  1103. result = DiffTimebSec(tbStart, tbStop);
  1104. //DEBUG_INFO("getStartStop(): %d\n", result);
  1105. }
  1106. else
  1107. {
  1108. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1109. }
  1110. return result;
  1111. }
  1112. int isOvertNow(uint8_t *start)
  1113. {
  1114. int result = NO;
  1115. struct ParsingResult
  1116. {
  1117. int result;
  1118. int scanedElement;
  1119. int year;
  1120. int month;
  1121. int mday;
  1122. int hour;
  1123. int min;
  1124. int sec;
  1125. int tz_hour;
  1126. int tz_min;
  1127. float minSec;
  1128. }parsingResult;
  1129. struct tm tmStart;
  1130. struct timeb tbStart;
  1131. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1132. if(strstr((char*)start, ".") != NULL)
  1133. {
  1134. // Original data with mini second
  1135. if(strstr((char*)start, "Z") != NULL)
  1136. {
  1137. // Original data with Z
  1138. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1139. &parsingResult.year,
  1140. &parsingResult.month,
  1141. &parsingResult.mday,
  1142. &parsingResult.hour,
  1143. &parsingResult.min,
  1144. &parsingResult.sec,
  1145. &parsingResult.minSec);
  1146. }
  1147. else
  1148. {
  1149. // Original data without Z
  1150. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1151. &parsingResult.year,
  1152. &parsingResult.month,
  1153. &parsingResult.mday,
  1154. &parsingResult.hour,
  1155. &parsingResult.min,
  1156. &parsingResult.sec,
  1157. &parsingResult.minSec,
  1158. &parsingResult.tz_hour,
  1159. &parsingResult.tz_min);
  1160. }
  1161. }
  1162. else
  1163. {
  1164. // Original data without mini second
  1165. if(strstr((char*)start, "Z") != NULL)
  1166. {
  1167. // Original data with Z
  1168. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1169. &parsingResult.year,
  1170. &parsingResult.month,
  1171. &parsingResult.mday,
  1172. &parsingResult.hour,
  1173. &parsingResult.min,
  1174. &parsingResult.sec);
  1175. }
  1176. else
  1177. {
  1178. // Original data without Z
  1179. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1180. &parsingResult.year,
  1181. &parsingResult.month,
  1182. &parsingResult.mday,
  1183. &parsingResult.hour,
  1184. &parsingResult.min,
  1185. &parsingResult.sec,
  1186. &parsingResult.tz_hour,
  1187. &parsingResult.tz_min);
  1188. }
  1189. }
  1190. if(parsingResult.scanedElement >= 6)
  1191. {
  1192. tmStart.tm_year = parsingResult.year - 1900;
  1193. tmStart.tm_mon = parsingResult.month - 1;
  1194. tmStart.tm_mday = parsingResult.mday;
  1195. tmStart.tm_hour = parsingResult.hour;
  1196. tmStart.tm_min = parsingResult.min;
  1197. tmStart.tm_sec = parsingResult.sec;
  1198. tmStart.tm_gmtoff = 0;
  1199. tbStart.time = mktime(&tmStart);
  1200. tbStart.timezone = 0;
  1201. tbStart.millitm = 0;
  1202. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1203. if(DiffTimebWithNowSec(tbStart) <= 0)
  1204. result = NO;
  1205. else
  1206. result = YES;
  1207. }
  1208. else
  1209. {
  1210. DEBUG_WARN("Start date parsing error.\n");
  1211. }
  1212. return result;
  1213. }
  1214. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1215. {
  1216. int result = -1;
  1217. struct tm tmStart;
  1218. struct timeb tbStart;
  1219. struct tm tmStop;
  1220. struct timeb tbStop;
  1221. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  1222. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  1223. {
  1224. tmStart.tm_year -= 1900;
  1225. tmStart.tm_mon -= 1;
  1226. tbStart.time = mktime(&tmStart);
  1227. tbStart.millitm = 0;
  1228. tmStop.tm_year -= 1900;
  1229. tmStop.tm_mon -= 1;
  1230. tbStop.time = mktime(&tmStop);
  1231. tbStop.millitm = 0;
  1232. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1233. }
  1234. return result;
  1235. }
  1236. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1237. {
  1238. FILE *fp;
  1239. char profileFileName[128];
  1240. char *line = NULL;
  1241. size_t len = 0;
  1242. time_t CurrentTime;
  1243. struct tm *tmComposite;
  1244. struct StructChargingProfile maxProfile;
  1245. uint8_t limitMax=0;
  1246. int compositePeriodIdx = 0;
  1247. CurrentTime = time(NULL);
  1248. tmComposite=localtime(&CurrentTime);
  1249. 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);
  1250. if(isUnitA)
  1251. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1252. else
  1253. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1254. compositeProfile->ChargingSchedule.Duration = durationReq;
  1255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1256. {
  1257. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1258. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1259. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1260. }
  1261. compositeProfile->ChargingProfileId = 0;
  1262. compositeProfile->StackLevel = 99 ;
  1263. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1264. maxProfile.ChargingProfileId = -1;
  1265. maxProfile.ChargingSchedule.Duration = -1;
  1266. system("rm -f /tmp/*.json");
  1267. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1268. // Search max profile
  1269. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1270. if((access(profileFileName, F_OK))!=-1)
  1271. {
  1272. fp = fopen(profileFileName, "r");
  1273. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1274. {
  1275. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1277. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1278. }
  1279. maxProfile.ChargingProfileId = -1;
  1280. maxProfile.StackLevel = -1;
  1281. while(getline(&line, &len, fp) != -1)
  1282. {
  1283. json_object *obj = NULL;
  1284. obj = json_tokener_parse(line);
  1285. if(is_error(obj))
  1286. {
  1287. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1288. }
  1289. else
  1290. {
  1291. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1292. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1293. )
  1294. {
  1295. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1296. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1297. )
  1298. {
  1299. struct tm tmFrom, tmTo;
  1300. struct timeb tbFrom, tbTo;
  1301. 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) &&
  1302. (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))
  1303. {
  1304. tmFrom.tm_year -= 1900;
  1305. tmFrom.tm_mon -= 1;
  1306. tbFrom.time = mktime(&tmFrom);
  1307. tmTo.tm_year -= 1900;
  1308. tmTo.tm_mon -= 1;
  1309. tbTo.time = mktime(&tmTo);
  1310. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1311. {
  1312. if(maxProfile.ChargingProfileId == -1)
  1313. DEBUG_INFO("MaxProfile found.\n");
  1314. else
  1315. DEBUG_INFO("MaxProfile updated.\n");
  1316. // Required item
  1317. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1318. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1319. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1320. if(isUnitA)
  1321. {
  1322. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1323. 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++)
  1324. {
  1325. 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"));
  1326. 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?
  1327. 3:
  1328. 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")));
  1329. 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")));
  1330. }
  1331. }
  1332. else
  1333. {
  1334. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1335. 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++)
  1336. {
  1337. 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"));
  1338. 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?
  1339. 3:
  1340. 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")));
  1341. 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));
  1342. }
  1343. }
  1344. // Optional item
  1345. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1346. {
  1347. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1348. }
  1349. else
  1350. {
  1351. sprintf((char*)maxProfile.ValidFrom, " ");
  1352. }
  1353. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1354. {
  1355. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1356. }
  1357. else
  1358. {
  1359. sprintf((char*)maxProfile.ValidTo, " ");
  1360. }
  1361. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1362. {
  1363. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1364. }
  1365. else
  1366. {
  1367. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1368. }
  1369. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1370. {
  1371. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1372. }
  1373. else
  1374. {
  1375. maxProfile.TransactionId = -1;
  1376. }
  1377. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1378. {
  1379. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1380. }
  1381. else
  1382. {
  1383. maxProfile.ChargingSchedule.Duration = 86400;
  1384. }
  1385. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1386. {
  1387. 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")));
  1388. }
  1389. else
  1390. {
  1391. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1392. }
  1393. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1394. {
  1395. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1396. }
  1397. else
  1398. {
  1399. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1400. }
  1401. }
  1402. }
  1403. }
  1404. else
  1405. {
  1406. if(maxProfile.ChargingProfileId == -1)
  1407. DEBUG_INFO("MaxProfile found.\n");
  1408. else
  1409. DEBUG_INFO("MaxProfile updated.\n");
  1410. // Required item
  1411. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1412. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1413. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1414. if(isUnitA)
  1415. {
  1416. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1417. 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++)
  1418. {
  1419. 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"));
  1420. 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?
  1421. 3:
  1422. 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")));
  1423. 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")));
  1424. }
  1425. }
  1426. else
  1427. {
  1428. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1429. 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++)
  1430. {
  1431. 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"));
  1432. 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?
  1433. 3:
  1434. 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")));
  1435. 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));
  1436. }
  1437. }
  1438. // Optional item
  1439. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1440. {
  1441. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1442. }
  1443. else
  1444. {
  1445. sprintf((char*)maxProfile.ValidFrom, " ");
  1446. }
  1447. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1448. {
  1449. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1450. }
  1451. else
  1452. {
  1453. sprintf((char*)maxProfile.ValidTo, " ");
  1454. }
  1455. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1456. {
  1457. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1458. }
  1459. else
  1460. {
  1461. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1462. }
  1463. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1464. {
  1465. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1466. }
  1467. else
  1468. {
  1469. maxProfile.TransactionId = -1;
  1470. }
  1471. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1472. {
  1473. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1474. }
  1475. else
  1476. {
  1477. maxProfile.ChargingSchedule.Duration = 86400;
  1478. }
  1479. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1480. {
  1481. 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")));
  1482. }
  1483. else
  1484. {
  1485. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1486. }
  1487. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1488. {
  1489. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1490. }
  1491. else
  1492. {
  1493. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1494. }
  1495. }
  1496. }
  1497. }
  1498. json_object_put(obj);
  1499. }
  1500. fclose(fp);
  1501. /*
  1502. if(maxProfile.ChargingProfileId !=-1)
  1503. {
  1504. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1505. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1506. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1507. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1508. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1509. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1510. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1511. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1512. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1513. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1514. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1518. {
  1519. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1520. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1521. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1522. }
  1523. }
  1524. }
  1525. else
  1526. DEBUG_INFO("MaxProfile not found.\n");
  1527. DEBUG_INFO("------------------------------------\n");*/
  1528. }
  1529. if(maxProfile.ChargingProfileId != -1)
  1530. {
  1531. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1532. {
  1533. if(maxProfile.ChargingSchedule.Duration != -1)
  1534. {
  1535. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1536. 0:
  1537. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1538. }
  1539. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1540. {
  1541. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1542. {
  1543. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1544. 0:
  1545. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1546. if(idxPeriod > 0)
  1547. {
  1548. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1549. {
  1550. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1551. }
  1552. }
  1553. }
  1554. }
  1555. }
  1556. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1557. {
  1558. if(maxProfile.ChargingSchedule.Duration != -1)
  1559. {
  1560. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1561. }
  1562. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1563. {
  1564. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1565. {
  1566. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1567. if(idxPeriod > 0)
  1568. {
  1569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1570. {
  1571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1572. }
  1573. }
  1574. }
  1575. }
  1576. }
  1577. else
  1578. {
  1579. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1580. {
  1581. if(maxProfile.ChargingSchedule.Duration != -1)
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1584. 0:
  1585. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1586. }
  1587. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1588. {
  1589. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1594. if(idxPeriod > 0)
  1595. {
  1596. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1597. {
  1598. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1599. }
  1600. }
  1601. }
  1602. }
  1603. }
  1604. else
  1605. {
  1606. if(maxProfile.ChargingSchedule.Duration != -1)
  1607. {
  1608. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1609. 0:
  1610. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1611. }
  1612. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1613. {
  1614. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1615. {
  1616. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1617. 0:
  1618. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1619. if(idxPeriod > 0)
  1620. {
  1621. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1622. {
  1623. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. }
  1630. /*
  1631. DEBUG_INFO("MaxProfile after align.\n");
  1632. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1633. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1634. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1635. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1636. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1637. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1638. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1639. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1640. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1641. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1642. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1643. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1644. {
  1645. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1646. {
  1647. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1648. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1649. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1650. }
  1651. }
  1652. DEBUG_INFO("------------------------------------\n");*/
  1653. }
  1654. // Find each profile period quantity
  1655. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1656. {
  1657. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1658. limitMax = idx+1;
  1659. }
  1660. if(maxProfile.ChargingProfileId != -1)
  1661. {
  1662. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1663. {
  1664. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1665. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1666. (maxProfile.ChargingSchedule.Duration > 0))
  1667. {
  1668. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1669. {
  1670. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1671. compositePeriodIdx++;
  1672. }
  1673. else
  1674. {
  1675. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1676. }
  1677. }
  1678. }
  1679. }
  1680. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1681. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1682. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1683. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1684. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1685. {
  1686. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1687. {
  1688. compositeProfile->ChargingProfileId = 1;
  1689. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1690. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1691. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1692. }
  1693. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1694. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1695. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1696. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1697. }
  1698. if(line)
  1699. free(line);
  1700. }
  1701. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1702. {
  1703. FILE *fp;
  1704. char profileFileName[128];
  1705. char *line = NULL;
  1706. size_t len = 0;
  1707. time_t CurrentTime;
  1708. struct tm *tmComposite;
  1709. struct StructChargingProfile maxProfile;
  1710. struct StructChargingProfile defaultTxProfile;
  1711. struct StructChargingProfile txProfile;
  1712. struct StructChargingSchedulePeriod tmpPeriod;
  1713. uint8_t limitMax=0;
  1714. uint8_t limitDef=0;
  1715. uint8_t limitTx=0;
  1716. int compositePeriodIdx = 0;
  1717. CurrentTime = time(NULL);
  1718. tmComposite=localtime(&CurrentTime);
  1719. 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);
  1720. if(isUnitA)
  1721. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1722. else
  1723. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1724. compositeProfile->ChargingSchedule.Duration = durationReq;
  1725. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1726. {
  1727. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1728. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1729. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1730. }
  1731. compositeProfile->ChargingProfileId = 0;
  1732. compositeProfile->StackLevel = 99 ;
  1733. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1734. maxProfile.ChargingProfileId = -1;
  1735. defaultTxProfile.ChargingProfileId = -1;
  1736. txProfile.ChargingProfileId = -1;
  1737. maxProfile.ChargingSchedule.Duration = -1;
  1738. defaultTxProfile.ChargingSchedule.Duration = -1;
  1739. txProfile.ChargingSchedule.Duration = -1;
  1740. system("rm -f /tmp/*.json");
  1741. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1742. /*
  1743. * Search valid charging profile
  1744. */
  1745. //DEBUG_INFO("====================================\n");
  1746. // Search tx profile
  1747. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1748. if((access(profileFileName, F_OK))!=-1)
  1749. {
  1750. fp = fopen(profileFileName, "r");
  1751. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1752. {
  1753. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1755. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1756. }
  1757. txProfile.ChargingProfileId = -1;
  1758. txProfile.StackLevel = -1;
  1759. while(getline(&line, &len, fp) != -1)
  1760. {
  1761. json_object *obj = NULL;
  1762. obj = json_tokener_parse(line);
  1763. if(is_error(obj))
  1764. {
  1765. DEBUG_ERROR("Parse txProfile from file error.\n");
  1766. }
  1767. else
  1768. {
  1769. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1770. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1771. )
  1772. {
  1773. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1774. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1775. )
  1776. {
  1777. struct tm tmFrom, tmTo;
  1778. struct timeb tbFrom, tbTo;
  1779. 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) &&
  1780. (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))
  1781. {
  1782. tmFrom.tm_year -= 1900;
  1783. tmFrom.tm_mon -= 1;
  1784. tbFrom.time = mktime(&tmFrom);
  1785. tmTo.tm_year -= 1900;
  1786. tmTo.tm_mon -= 1;
  1787. tbTo.time = mktime(&tmTo);
  1788. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1789. {
  1790. if(txProfile.ChargingProfileId == -1)
  1791. DEBUG_INFO("TxProfile found.\n");
  1792. else
  1793. DEBUG_INFO("TxProfile updated.\n");
  1794. // Required item
  1795. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1796. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1797. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1798. if(isUnitA)
  1799. {
  1800. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1801. 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++)
  1802. {
  1803. 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"));
  1804. 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?
  1805. 3:
  1806. 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")));
  1807. 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")));
  1808. }
  1809. }
  1810. else
  1811. {
  1812. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1813. 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++)
  1814. {
  1815. 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"));
  1816. 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?
  1817. 3:
  1818. 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")));
  1819. 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));
  1820. }
  1821. }
  1822. // Optional item
  1823. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1824. {
  1825. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1826. }
  1827. else
  1828. {
  1829. sprintf((char*)txProfile.ValidFrom, " ");
  1830. }
  1831. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1832. {
  1833. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1834. }
  1835. else
  1836. {
  1837. sprintf((char*)txProfile.ValidTo, " ");
  1838. }
  1839. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1840. {
  1841. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1842. }
  1843. else
  1844. {
  1845. sprintf((char*)txProfile.RecurrencyKind, " ");
  1846. }
  1847. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1848. {
  1849. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1850. }
  1851. else
  1852. {
  1853. txProfile.TransactionId = -1;
  1854. }
  1855. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1856. {
  1857. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1858. }
  1859. else
  1860. {
  1861. txProfile.ChargingSchedule.Duration = 86400;
  1862. }
  1863. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1864. {
  1865. 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")));
  1866. }
  1867. else
  1868. {
  1869. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1870. }
  1871. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1872. {
  1873. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1874. }
  1875. else
  1876. {
  1877. txProfile.ChargingSchedule.MinChargingRate = -1;
  1878. }
  1879. }
  1880. }
  1881. }
  1882. else
  1883. {
  1884. if(txProfile.ChargingProfileId == -1)
  1885. DEBUG_INFO("TxProfile found.\n");
  1886. else
  1887. DEBUG_INFO("TxProfile updated.\n");
  1888. // Required item
  1889. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1890. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1891. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1892. if(isUnitA)
  1893. {
  1894. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1895. 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++)
  1896. {
  1897. 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"));
  1898. 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?
  1899. 3:
  1900. 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")));
  1901. 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")));
  1902. }
  1903. }
  1904. else
  1905. {
  1906. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1907. 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++)
  1908. {
  1909. 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"));
  1910. 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?
  1911. 3:
  1912. 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")));
  1913. 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));
  1914. }
  1915. }
  1916. // Optional item
  1917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1918. {
  1919. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1920. }
  1921. else
  1922. {
  1923. sprintf((char*)txProfile.ValidFrom, " ");
  1924. }
  1925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1926. {
  1927. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1928. }
  1929. else
  1930. {
  1931. sprintf((char*)txProfile.ValidTo, " ");
  1932. }
  1933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1934. {
  1935. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1936. }
  1937. else
  1938. {
  1939. sprintf((char*)txProfile.RecurrencyKind, " ");
  1940. }
  1941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1942. {
  1943. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1944. }
  1945. else
  1946. {
  1947. txProfile.TransactionId = -1;
  1948. }
  1949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1950. {
  1951. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1952. }
  1953. else
  1954. {
  1955. txProfile.ChargingSchedule.Duration = 86400;
  1956. }
  1957. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1958. {
  1959. 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")));
  1960. }
  1961. else
  1962. {
  1963. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1964. }
  1965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1966. {
  1967. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1968. }
  1969. else
  1970. {
  1971. txProfile.ChargingSchedule.MinChargingRate = -1;
  1972. }
  1973. }
  1974. }
  1975. }
  1976. json_object_put(obj);
  1977. }
  1978. fclose(fp);
  1979. /*
  1980. if(txProfile.ChargingProfileId != -1)
  1981. {
  1982. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1983. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1984. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1985. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1986. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1987. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1988. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1989. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1990. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1991. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1992. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1993. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1994. {
  1995. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1996. {
  1997. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1998. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1999. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2000. }
  2001. }
  2002. }
  2003. else
  2004. DEBUG_INFO("TxProfile not found.\n");*/
  2005. }
  2006. // Search default tx profile
  2007. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2008. if((access(profileFileName, F_OK))==-1)
  2009. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2010. if((access(profileFileName, F_OK))!=-1)
  2011. {
  2012. fp = fopen(profileFileName, "r");
  2013. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2014. {
  2015. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2016. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2017. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2018. }
  2019. defaultTxProfile.ChargingProfileId = -1;
  2020. defaultTxProfile.StackLevel = -1;
  2021. while(getline(&line, &len, fp) != -1)
  2022. {
  2023. json_object *obj = NULL;
  2024. obj = json_tokener_parse(line);
  2025. if(is_error(obj))
  2026. {
  2027. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2028. }
  2029. else
  2030. {
  2031. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2032. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2033. )
  2034. {
  2035. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2036. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2037. )
  2038. {
  2039. struct tm tmFrom, tmTo;
  2040. struct timeb tbFrom, tbTo;
  2041. 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) &&
  2042. (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))
  2043. {
  2044. tmFrom.tm_year -= 1900;
  2045. tmFrom.tm_mon -= 1;
  2046. tbFrom.time = mktime(&tmFrom);
  2047. tmTo.tm_year -= 1900;
  2048. tmTo.tm_mon -= 1;
  2049. tbTo.time = mktime(&tmTo);
  2050. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2051. {
  2052. if(defaultTxProfile.ChargingProfileId == -1)
  2053. DEBUG_INFO("TxDefaultProfile found.\n");
  2054. else
  2055. DEBUG_INFO("TxDefaultProfile updated.\n");
  2056. // Required item
  2057. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2058. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2059. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2060. if(isUnitA)
  2061. {
  2062. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2063. 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++)
  2064. {
  2065. 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"));
  2066. 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?
  2067. 3:
  2068. 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")));
  2069. 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")));
  2070. }
  2071. }
  2072. else
  2073. {
  2074. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2075. 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++)
  2076. {
  2077. 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"));
  2078. 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?
  2079. 3:
  2080. 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")));
  2081. 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));
  2082. }
  2083. }
  2084. // Optional item
  2085. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2086. {
  2087. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2088. }
  2089. else
  2090. {
  2091. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2092. }
  2093. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2094. {
  2095. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2096. }
  2097. else
  2098. {
  2099. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2100. }
  2101. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2102. {
  2103. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2104. }
  2105. else
  2106. {
  2107. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2108. }
  2109. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2110. {
  2111. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2112. }
  2113. else
  2114. {
  2115. defaultTxProfile.TransactionId = -1;
  2116. }
  2117. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2118. {
  2119. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2120. }
  2121. else
  2122. {
  2123. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2124. }
  2125. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2126. {
  2127. 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")));
  2128. }
  2129. else
  2130. {
  2131. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2132. }
  2133. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2134. {
  2135. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2136. }
  2137. else
  2138. {
  2139. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2140. }
  2141. }
  2142. }
  2143. }
  2144. else
  2145. {
  2146. if(defaultTxProfile.ChargingProfileId == -1)
  2147. DEBUG_INFO("TxDefaultProfile found.\n");
  2148. else
  2149. DEBUG_INFO("TxDefaultProfile updated.\n");
  2150. // Required item
  2151. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2152. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2153. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2154. if(isUnitA)
  2155. {
  2156. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2157. 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++)
  2158. {
  2159. 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"));
  2160. 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?
  2161. 3:
  2162. 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")));
  2163. 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")));
  2164. }
  2165. }
  2166. else
  2167. {
  2168. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2169. 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++)
  2170. {
  2171. 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"));
  2172. 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?
  2173. 3:
  2174. 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")));
  2175. 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));
  2176. }
  2177. }
  2178. // Optional item
  2179. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2180. {
  2181. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2182. }
  2183. else
  2184. {
  2185. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2186. }
  2187. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2188. {
  2189. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2190. }
  2191. else
  2192. {
  2193. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2194. }
  2195. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2196. {
  2197. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2198. }
  2199. else
  2200. {
  2201. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2202. }
  2203. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2204. {
  2205. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2206. }
  2207. else
  2208. {
  2209. defaultTxProfile.TransactionId = -1;
  2210. }
  2211. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2212. {
  2213. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2214. }
  2215. else
  2216. {
  2217. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2218. }
  2219. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2220. {
  2221. 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")));
  2222. }
  2223. else
  2224. {
  2225. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2226. }
  2227. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2228. {
  2229. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2230. }
  2231. else
  2232. {
  2233. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2234. }
  2235. }
  2236. }
  2237. }
  2238. json_object_put(obj);
  2239. }
  2240. fclose(fp);
  2241. /*
  2242. if(defaultTxProfile.ChargingProfileId != -1)
  2243. {
  2244. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2245. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2246. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2247. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2248. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2249. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2250. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2251. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2252. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2253. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2254. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2256. {
  2257. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2258. {
  2259. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2260. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2261. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2262. }
  2263. }
  2264. }
  2265. else
  2266. DEBUG_INFO("TxDefaultProfile not found.\n");
  2267. DEBUG_INFO("------------------------------------\n");*/
  2268. }
  2269. // Search max profile
  2270. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2271. if((access(profileFileName, F_OK))!=-1)
  2272. {
  2273. fp = fopen(profileFileName, "r");
  2274. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2275. {
  2276. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2277. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2278. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2279. }
  2280. maxProfile.ChargingProfileId = -1;
  2281. maxProfile.StackLevel = -1;
  2282. while(getline(&line, &len, fp) != -1)
  2283. {
  2284. json_object *obj = NULL;
  2285. obj = json_tokener_parse(line);
  2286. if(is_error(obj))
  2287. {
  2288. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2289. }
  2290. else
  2291. {
  2292. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2293. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2294. )
  2295. {
  2296. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2297. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2298. )
  2299. {
  2300. struct tm tmFrom, tmTo;
  2301. struct timeb tbFrom, tbTo;
  2302. 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) &&
  2303. (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))
  2304. {
  2305. tmFrom.tm_year -= 1900;
  2306. tmFrom.tm_mon -= 1;
  2307. tbFrom.time = mktime(&tmFrom);
  2308. tmTo.tm_year -= 1900;
  2309. tmTo.tm_mon -= 1;
  2310. tbTo.time = mktime(&tmTo);
  2311. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2312. {
  2313. if(maxProfile.ChargingProfileId == -1)
  2314. DEBUG_INFO("MaxProfile found.\n");
  2315. else
  2316. DEBUG_INFO("MaxProfile updated.\n");
  2317. // Required item
  2318. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2319. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2320. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2321. if(isUnitA)
  2322. {
  2323. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2324. 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++)
  2325. {
  2326. 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"));
  2327. 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?
  2328. 3:
  2329. 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")));
  2330. 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")));
  2331. }
  2332. }
  2333. else
  2334. {
  2335. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2336. 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++)
  2337. {
  2338. 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"));
  2339. 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?
  2340. 3:
  2341. 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")));
  2342. 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));
  2343. }
  2344. }
  2345. // Optional item
  2346. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2347. {
  2348. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2349. }
  2350. else
  2351. {
  2352. sprintf((char*)maxProfile.ValidFrom, " ");
  2353. }
  2354. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2355. {
  2356. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2357. }
  2358. else
  2359. {
  2360. sprintf((char*)maxProfile.ValidTo, " ");
  2361. }
  2362. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2363. {
  2364. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2365. }
  2366. else
  2367. {
  2368. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2369. }
  2370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2371. {
  2372. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2373. }
  2374. else
  2375. {
  2376. maxProfile.TransactionId = -1;
  2377. }
  2378. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2379. {
  2380. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2381. }
  2382. else
  2383. {
  2384. maxProfile.ChargingSchedule.Duration = 86400;
  2385. }
  2386. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2387. {
  2388. 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")));
  2389. }
  2390. else
  2391. {
  2392. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2393. }
  2394. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2395. {
  2396. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2397. }
  2398. else
  2399. {
  2400. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2401. }
  2402. }
  2403. }
  2404. }
  2405. else
  2406. {
  2407. if(maxProfile.ChargingProfileId == -1)
  2408. DEBUG_INFO("MaxProfile found.\n");
  2409. else
  2410. DEBUG_INFO("MaxProfile updated.\n");
  2411. // Required item
  2412. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2413. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2414. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2415. if(isUnitA)
  2416. {
  2417. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2418. 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++)
  2419. {
  2420. 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"));
  2421. 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?
  2422. 3:
  2423. 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")));
  2424. 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")));
  2425. }
  2426. }
  2427. else
  2428. {
  2429. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2430. 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++)
  2431. {
  2432. 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"));
  2433. 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?
  2434. 3:
  2435. 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")));
  2436. 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));
  2437. }
  2438. }
  2439. // Optional item
  2440. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2441. {
  2442. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2443. }
  2444. else
  2445. {
  2446. sprintf((char*)maxProfile.ValidFrom, " ");
  2447. }
  2448. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2449. {
  2450. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2451. }
  2452. else
  2453. {
  2454. sprintf((char*)maxProfile.ValidTo, " ");
  2455. }
  2456. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2457. {
  2458. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2459. }
  2460. else
  2461. {
  2462. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2463. }
  2464. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2465. {
  2466. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2467. }
  2468. else
  2469. {
  2470. maxProfile.TransactionId = -1;
  2471. }
  2472. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2473. {
  2474. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2475. }
  2476. else
  2477. {
  2478. maxProfile.ChargingSchedule.Duration = 86400;
  2479. }
  2480. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2481. {
  2482. 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")));
  2483. }
  2484. else
  2485. {
  2486. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2487. }
  2488. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2489. {
  2490. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2491. }
  2492. else
  2493. {
  2494. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2495. }
  2496. }
  2497. }
  2498. }
  2499. json_object_put(obj);
  2500. }
  2501. fclose(fp);
  2502. /*
  2503. if(maxProfile.ChargingProfileId !=-1)
  2504. {
  2505. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2506. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2507. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2508. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2509. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2510. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2511. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2512. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2513. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2514. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2515. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2516. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2517. {
  2518. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2519. {
  2520. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2521. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2522. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2523. }
  2524. }
  2525. }
  2526. else
  2527. DEBUG_INFO("MaxProfile not found.\n");
  2528. DEBUG_INFO("------------------------------------\n");*/
  2529. }
  2530. /*
  2531. * Align found profile start schedule & periods
  2532. */
  2533. //DEBUG_INFO("====================================\n");
  2534. /*
  2535. // For local test usage, force modify found profile start schedule info
  2536. 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);
  2537. 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);
  2538. 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);
  2539. */
  2540. if(txProfile.ChargingProfileId != -1)
  2541. {
  2542. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2543. {
  2544. if(txProfile.ChargingSchedule.Duration != -1)
  2545. {
  2546. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2547. 0:
  2548. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2549. }
  2550. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2551. {
  2552. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2553. {
  2554. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2555. 0:
  2556. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2557. if(idxPeriod > 0)
  2558. {
  2559. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2560. {
  2561. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2562. }
  2563. }
  2564. }
  2565. }
  2566. }
  2567. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2568. {
  2569. if(txProfile.ChargingSchedule.Duration != -1)
  2570. {
  2571. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2572. 0:
  2573. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2574. }
  2575. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2576. {
  2577. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2578. {
  2579. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2580. 0:
  2581. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2582. if(idxPeriod > 0)
  2583. {
  2584. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2585. {
  2586. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2587. }
  2588. }
  2589. }
  2590. }
  2591. }
  2592. else
  2593. {
  2594. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2595. {
  2596. if(txProfile.ChargingSchedule.Duration != -1)
  2597. {
  2598. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2599. 0:
  2600. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2601. }
  2602. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2603. {
  2604. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2605. {
  2606. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2607. 0:
  2608. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2609. if(idxPeriod > 0)
  2610. {
  2611. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2612. {
  2613. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2614. }
  2615. }
  2616. }
  2617. }
  2618. }
  2619. else
  2620. {
  2621. if(txProfile.ChargingSchedule.Duration != -1)
  2622. {
  2623. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2624. 0:
  2625. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2626. }
  2627. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2628. {
  2629. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2630. {
  2631. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2632. 0:
  2633. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2634. if(idxPeriod > 0)
  2635. {
  2636. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2637. {
  2638. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. /*
  2646. DEBUG_INFO("txProfile after align.\n");
  2647. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2648. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2649. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2650. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2651. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2652. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2653. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2654. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2655. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2656. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2657. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2658. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2659. {
  2660. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2661. {
  2662. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2663. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2664. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2665. }
  2666. }*/
  2667. }
  2668. if(defaultTxProfile.ChargingProfileId != -1)
  2669. {
  2670. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2671. {
  2672. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2673. {
  2674. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2675. 0:
  2676. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2677. }
  2678. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2679. {
  2680. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2681. {
  2682. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2683. 0:
  2684. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2685. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2686. {
  2687. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2688. }
  2689. if(idxPeriod > 0)
  2690. {
  2691. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2692. {
  2693. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2694. }
  2695. }
  2696. }
  2697. }
  2698. }
  2699. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2700. {
  2701. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2702. {
  2703. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2704. 0:
  2705. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2706. }
  2707. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2708. {
  2709. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2710. {
  2711. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2712. 0:
  2713. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2714. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2715. {
  2716. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2717. }
  2718. if(idxPeriod > 0)
  2719. {
  2720. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2721. {
  2722. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2723. }
  2724. }
  2725. }
  2726. }
  2727. }
  2728. else
  2729. {
  2730. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2731. {
  2732. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2733. {
  2734. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2735. 0:
  2736. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2737. }
  2738. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2739. {
  2740. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2741. {
  2742. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2743. 0:
  2744. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2745. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2746. {
  2747. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2748. }
  2749. if(idxPeriod > 0)
  2750. {
  2751. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2752. {
  2753. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2754. }
  2755. }
  2756. }
  2757. }
  2758. }
  2759. else
  2760. {
  2761. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2762. {
  2763. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2764. 0:
  2765. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2766. }
  2767. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2768. {
  2769. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2770. {
  2771. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2772. 0:
  2773. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2774. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2775. {
  2776. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2777. }
  2778. if(idxPeriod > 0)
  2779. {
  2780. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2781. {
  2782. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. }
  2789. /*
  2790. DEBUG_INFO("defaultTxProfile after align.\n");
  2791. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2792. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2793. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2794. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2795. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2796. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2797. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2798. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2799. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2800. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2801. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2802. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2803. {
  2804. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2805. {
  2806. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2807. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2808. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2809. }
  2810. }
  2811. DEBUG_INFO("------------------------------------\n");*/
  2812. }
  2813. if(maxProfile.ChargingProfileId != -1)
  2814. {
  2815. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2816. {
  2817. if(maxProfile.ChargingSchedule.Duration != -1)
  2818. {
  2819. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2820. 0:
  2821. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2822. }
  2823. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2824. {
  2825. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2826. {
  2827. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2828. 0:
  2829. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2830. if(idxPeriod > 0)
  2831. {
  2832. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2833. {
  2834. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2835. }
  2836. }
  2837. }
  2838. }
  2839. }
  2840. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2841. {
  2842. if(maxProfile.ChargingSchedule.Duration != -1)
  2843. {
  2844. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2845. 0:
  2846. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2847. }
  2848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2849. {
  2850. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2851. {
  2852. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2853. 0:
  2854. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2855. if(idxPeriod > 0)
  2856. {
  2857. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2858. {
  2859. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2868. {
  2869. if(maxProfile.ChargingSchedule.Duration != -1)
  2870. {
  2871. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2872. 0:
  2873. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2874. }
  2875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2876. {
  2877. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2878. {
  2879. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2880. 0:
  2881. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2882. if(idxPeriod > 0)
  2883. {
  2884. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2885. {
  2886. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2887. }
  2888. }
  2889. }
  2890. }
  2891. }
  2892. else
  2893. {
  2894. if(maxProfile.ChargingSchedule.Duration != -1)
  2895. {
  2896. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2897. 0:
  2898. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2899. }
  2900. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2901. {
  2902. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2903. {
  2904. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2905. 0:
  2906. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2907. if(idxPeriod > 0)
  2908. {
  2909. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2910. {
  2911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. }
  2918. /*
  2919. DEBUG_INFO("MaxProfile after align.\n");
  2920. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2921. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2922. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2923. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2924. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2925. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2926. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2927. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2928. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2929. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2930. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2931. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2932. {
  2933. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2934. {
  2935. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2936. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2937. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2938. }
  2939. }
  2940. DEBUG_INFO("------------------------------------\n");*/
  2941. }
  2942. /*
  2943. * Merge to conposite schedule
  2944. */
  2945. //DEBUG_INFO("====================================\n");
  2946. // Find each profile period quantity
  2947. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2948. {
  2949. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2950. limitMax = idx+1;
  2951. }
  2952. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2953. {
  2954. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2955. limitDef = idx+1;
  2956. }
  2957. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2958. {
  2959. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2960. limitTx = idx+1;
  2961. }
  2962. // TxProfile found, composite schedule based on it
  2963. if(txProfile.ChargingProfileId != -1)
  2964. {
  2965. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2966. {
  2967. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2968. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2969. (txProfile.ChargingSchedule.Duration > 0))
  2970. {
  2971. if(maxProfile.ChargingProfileId != -1)
  2972. {
  2973. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2974. {
  2975. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2976. {
  2977. if((maxProfile.ChargingSchedule.Duration > 0))
  2978. {
  2979. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2980. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2981. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2982. }
  2983. else
  2984. {
  2985. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2986. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2987. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2988. }
  2989. }
  2990. if(idxMaxPeriod == (limitMax-1))
  2991. {
  2992. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2993. {
  2994. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2995. {
  2996. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2997. compositePeriodIdx++;
  2998. }
  2999. else
  3000. {
  3001. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3002. }
  3003. }
  3004. }
  3005. }
  3006. }
  3007. else
  3008. {
  3009. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3010. {
  3011. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3012. compositePeriodIdx++;
  3013. }
  3014. else
  3015. {
  3016. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3017. }
  3018. }
  3019. }
  3020. if(idxTxPeriod == (limitTx-1))
  3021. {
  3022. if(defaultTxProfile.ChargingProfileId != -1)
  3023. {
  3024. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3025. {
  3026. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3027. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3028. (defaultTxProfile.ChargingSchedule.Duration>0))
  3029. {
  3030. if(maxProfile.ChargingProfileId != -1)
  3031. {
  3032. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3033. {
  3034. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3035. {
  3036. if((maxProfile.ChargingSchedule.Duration > 0))
  3037. {
  3038. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3039. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3040. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3041. }
  3042. else
  3043. {
  3044. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3045. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3046. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3047. }
  3048. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3049. {
  3050. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3051. {
  3052. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3053. compositePeriodIdx++;
  3054. }
  3055. else
  3056. {
  3057. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3058. }
  3059. }
  3060. // Delete duplicate period
  3061. if(compositePeriodIdx > 1)
  3062. {
  3063. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3064. {
  3065. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3066. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3067. compositePeriodIdx -= 1;
  3068. }
  3069. }
  3070. }
  3071. else
  3072. break;
  3073. }
  3074. }
  3075. else
  3076. {
  3077. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3078. {
  3079. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3080. compositePeriodIdx++;
  3081. }
  3082. else
  3083. {
  3084. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3085. }
  3086. }
  3087. }
  3088. }
  3089. }
  3090. }
  3091. }
  3092. }
  3093. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3094. else if(defaultTxProfile.ChargingProfileId != -1)
  3095. {
  3096. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3097. {
  3098. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3099. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3100. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3101. {
  3102. if(maxProfile.ChargingProfileId != -1)
  3103. {
  3104. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3105. {
  3106. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3107. {
  3108. if((maxProfile.ChargingSchedule.Duration > 0))
  3109. {
  3110. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3111. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3112. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3113. }
  3114. else
  3115. {
  3116. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3117. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3118. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3119. }
  3120. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3121. {
  3122. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3123. {
  3124. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3125. compositePeriodIdx++;
  3126. }
  3127. else
  3128. {
  3129. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3130. }
  3131. }
  3132. // Delete duplicate period
  3133. if(compositePeriodIdx > 1)
  3134. {
  3135. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3136. {
  3137. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3138. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3139. compositePeriodIdx -= 1;
  3140. }
  3141. }
  3142. }
  3143. else
  3144. break;
  3145. }
  3146. }
  3147. else
  3148. {
  3149. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3150. {
  3151. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3152. compositePeriodIdx++;
  3153. }
  3154. else
  3155. {
  3156. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3157. }
  3158. }
  3159. }
  3160. }
  3161. }
  3162. // Fill other period by MaxProfile
  3163. if(maxProfile.ChargingProfileId != -1)
  3164. {
  3165. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3166. {
  3167. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3168. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3169. (maxProfile.ChargingSchedule.Duration > 0))
  3170. {
  3171. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3172. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3173. {
  3174. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3175. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3176. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3177. }
  3178. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3179. {
  3180. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3181. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3182. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3183. }
  3184. if(tmpPeriod.Limit != -1)
  3185. {
  3186. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3187. {
  3188. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3189. {
  3190. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3191. compositePeriodIdx++;
  3192. }
  3193. else
  3194. {
  3195. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3196. }
  3197. }
  3198. // Delete duplicate period
  3199. if(compositePeriodIdx > 1)
  3200. {
  3201. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3202. {
  3203. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3204. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3205. compositePeriodIdx -= 1;
  3206. }
  3207. }
  3208. }
  3209. }
  3210. }
  3211. }
  3212. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3213. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3214. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3215. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3217. {
  3218. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3219. {
  3220. compositeProfile->ChargingProfileId = 1;
  3221. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3222. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3223. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3224. }
  3225. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3226. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3227. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3228. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3229. }
  3230. if(line)
  3231. free(line);
  3232. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3233. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3234. }
  3235. //==========================================
  3236. // Init all share memory
  3237. //==========================================
  3238. int InitShareMemory()
  3239. {
  3240. int result = PASS;
  3241. int MeterSMId;
  3242. //creat ShmSysConfigAndInfo
  3243. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3244. {
  3245. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3246. result = FAIL;
  3247. }
  3248. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3249. {
  3250. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3251. result = FAIL;
  3252. }
  3253. else
  3254. {}
  3255. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3256. {
  3257. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3258. result = FAIL;
  3259. }
  3260. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3261. {
  3262. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3263. result = FAIL;
  3264. }
  3265. else
  3266. {}
  3267. //creat ShmPsuData
  3268. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3269. {
  3270. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3271. result = FAIL;
  3272. }
  3273. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3274. {
  3275. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3276. result = FAIL;
  3277. }
  3278. else
  3279. {}
  3280. //creat ShmOCPP16Data
  3281. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3282. {
  3283. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3284. result = FAIL;
  3285. }
  3286. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3287. {
  3288. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3289. result = FAIL;
  3290. }
  3291. else
  3292. {}
  3293. /****************************** For Initial Settings************************************************/
  3294. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3295. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3296. // allocate Configuration memory address
  3297. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3298. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3299. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3300. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3301. //offline MeterValue Interval
  3302. TempMeterValueInterval = 0;
  3303. return result;
  3304. }
  3305. int ProcessShareMemory()
  3306. {
  3307. if(InitShareMemory() == FAIL)
  3308. {
  3309. DEBUG_ERROR("InitShareMemory NG\n");
  3310. if(ShmStatusCodeData!=NULL)
  3311. {
  3312. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3313. }
  3314. sleep(5);
  3315. return FAIL;
  3316. }
  3317. return PASS;
  3318. }
  3319. void CheckSystemValue(void)
  3320. {
  3321. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3322. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3323. char filenmae[100]={0};
  3324. char str[100]={0};
  3325. int tempIndex = 0;
  3326. //===============================
  3327. // send Heartbeat
  3328. //===============================
  3329. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3330. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3331. {
  3332. clientTime.Heartbeat=time((time_t*)NULL);
  3333. if(server_sign == TRUE)
  3334. {
  3335. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3336. }
  3337. else
  3338. {
  3339. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3340. }
  3341. }
  3342. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3343. {
  3344. //parameter for test
  3345. sendHeartbeatRequest(0);
  3346. //==============================================
  3347. // Reset Waiting Time
  3348. //==============================================
  3349. HeartBeatWithNOResponse += 1;
  3350. }
  3351. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3352. {
  3353. //==========================================
  3354. // csu trigger DataTransferReq
  3355. //==========================================
  3356. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3357. {
  3358. sendDataTransferRequest(gun_index);
  3359. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3360. }
  3361. //===============================
  3362. // CSU Trigger Authorize Request
  3363. //===============================
  3364. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3365. {
  3366. sendAuthorizeRequest(0);
  3367. authorizeRetryTimes = authorizeRetryTimes + 1;
  3368. if(authorizeRetryTimes < 3)
  3369. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3370. }
  3371. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3372. {
  3373. authorizeRetryTimes = 0;
  3374. SetOcppConnStatus(FALSE);
  3375. server_sign = FALSE;
  3376. }
  3377. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  3378. {
  3379. sendAuthorizeRequest(0);
  3380. }
  3381. //==============================================
  3382. // Charger start transaction
  3383. //==============================================
  3384. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3385. {
  3386. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3387. sendStartTransactionRequest(gun_index);
  3388. clientTime.StartTransaction = time((time_t*)NULL);
  3389. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3390. storeTempStopTransaction(gun_index);
  3391. }
  3392. //==============================================
  3393. // Charger stop transaction
  3394. //==============================================
  3395. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3396. {
  3397. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3398. sendStopTransactionRequest(gun_index);
  3399. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3400. clientTime.StopTransaction = time((time_t*)NULL);
  3401. }
  3402. //==============================================
  3403. // Charger status report
  3404. //==============================================
  3405. //--- Check Mode Change ---//
  3406. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3407. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3408. {
  3409. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3410. {
  3411. tempIndex = ((gun_index==2) ? 1: 0);
  3412. }
  3413. else
  3414. {
  3415. tempIndex = gun_index;
  3416. }
  3417. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3418. {
  3419. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3420. {
  3421. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3422. {
  3423. // Sent unplug message for California pricing logic
  3424. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3425. {
  3426. uint8_t ts[20];
  3427. getNowDatetime(ts);
  3428. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3429. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3430. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3431. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3432. }
  3433. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3434. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3435. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3436. }
  3437. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3438. {
  3439. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3440. if((access(filenmae,F_OK))!=-1)
  3441. {
  3442. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3443. sprintf(str,"rm -f %s",filenmae);
  3444. system(str);
  3445. }
  3446. }
  3447. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3448. #if 1 // for TempStopTransaction
  3449. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3450. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3451. {
  3452. checkTempStopTransaction(gun_index);
  3453. }
  3454. #endif
  3455. }
  3456. }
  3457. }
  3458. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3459. {
  3460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3461. {
  3462. tempIndex = ((gun_index==2) ? 1: 0);
  3463. }
  3464. else
  3465. {
  3466. tempIndex = gun_index;
  3467. }
  3468. for (int index = 0; index < CCS_QUANTITY; index++)
  3469. {
  3470. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3471. {
  3472. 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]*/ )
  3473. {
  3474. // Sent unplug message for California pricing logic
  3475. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3476. {
  3477. uint8_t ts[20];
  3478. getNowDatetime(ts);
  3479. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3480. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3481. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3482. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3483. }
  3484. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3485. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3486. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3487. }
  3488. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3489. {
  3490. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3491. if((access(filenmae,F_OK))!=-1)
  3492. {
  3493. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3494. sprintf(str,"rm -f %s",filenmae);
  3495. system(str);
  3496. }
  3497. }
  3498. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3499. #if 1 // for TempStopTransaction
  3500. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3501. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3502. {
  3503. checkTempStopTransaction(gun_index);
  3504. }
  3505. #endif
  3506. }
  3507. }
  3508. }
  3509. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3510. {
  3511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3512. {
  3513. tempIndex = ((gun_index==2) ? 1: 0);
  3514. }
  3515. else
  3516. {
  3517. tempIndex = gun_index;
  3518. }
  3519. for (int index = 0; index < GB_QUANTITY; index++)
  3520. {
  3521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3522. {
  3523. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3524. {
  3525. // Sent unplug message for California pricing logic
  3526. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3527. {
  3528. uint8_t ts[20];
  3529. getNowDatetime(ts);
  3530. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3531. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3532. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3533. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3534. }
  3535. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3536. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3537. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3538. }
  3539. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3540. {
  3541. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3542. if((access(filenmae,F_OK))!=-1)
  3543. {
  3544. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3545. sprintf(str,"rm -f %s",filenmae);
  3546. system(str);
  3547. }
  3548. }
  3549. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3550. #if 1 // for TempStopTransaction
  3551. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3552. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3553. {
  3554. checkTempStopTransaction(gun_index);
  3555. }
  3556. #endif
  3557. }
  3558. }
  3559. }
  3560. else if(gunType[gun_index] == GUN_TYPE_DO)
  3561. {
  3562. tempIndex = gun_index;
  3563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3564. {
  3565. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3566. {
  3567. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3568. {
  3569. // Sent unplug message for California pricing logic
  3570. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3571. {
  3572. uint8_t ts[20];
  3573. getNowDatetime(ts);
  3574. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3575. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3576. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3577. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3578. }
  3579. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3580. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3581. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3582. }
  3583. 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_PREPARING))) // complete
  3584. {
  3585. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3586. if((access(filenmae,F_OK))!=-1)
  3587. {
  3588. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3589. sprintf(str,"rm -f %s",filenmae);
  3590. system(str);
  3591. }
  3592. }
  3593. 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);
  3594. #if 1 // for TempStopTransaction
  3595. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3596. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3597. {
  3598. checkTempStopTransaction(gun_index);
  3599. }
  3600. #endif
  3601. }
  3602. }
  3603. }
  3604. else
  3605. {
  3606. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3607. {
  3608. tempIndex = 2;
  3609. }
  3610. else
  3611. {
  3612. tempIndex = gun_index;
  3613. }
  3614. for (int index = 0; index < AC_QUANTITY; index++)
  3615. {
  3616. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3617. {
  3618. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3619. {
  3620. // Sent unplug message for California pricing logic
  3621. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3622. {
  3623. uint8_t ts[20];
  3624. getNowDatetime(ts);
  3625. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3626. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3627. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3628. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3629. }
  3630. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3631. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3632. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3633. }
  3634. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3635. {
  3636. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3637. if((access(filenmae,F_OK))!=-1)
  3638. {
  3639. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3640. sprintf(str,"rm -f %s",filenmae);
  3641. system(str);
  3642. }
  3643. }
  3644. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3645. #if 1 // for TempStopTransaction
  3646. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3647. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3648. {
  3649. checkTempStopTransaction(gun_index);
  3650. }
  3651. #endif
  3652. }
  3653. }// END
  3654. }
  3655. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3656. (
  3657. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3658. )
  3659. )
  3660. {
  3661. if(SystemInitial > 0)
  3662. SystemInitial -= 1;
  3663. sendStatusNotificationRequest(gun_index);
  3664. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3665. }
  3666. //==============================================
  3667. // CSU Trigger Smart Charging Profilw
  3668. //==============================================
  3669. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3670. {
  3671. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3672. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3673. }
  3674. //==============================================
  3675. // Meter report
  3676. //==============================================
  3677. // Trigger MeterValue
  3678. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3679. {
  3680. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3681. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3682. }
  3683. // ClockAlign MeterValue
  3684. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3685. {
  3686. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3687. {
  3688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3689. {
  3690. tempIndex = ((gun_index==2) ? 1: 0);
  3691. }
  3692. else
  3693. {
  3694. tempIndex = gun_index;
  3695. }
  3696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3697. {
  3698. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3699. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3700. {
  3701. reqClockAlignMeter[gun_index] = 1;
  3702. }
  3703. }// End for CHAdeMO
  3704. }
  3705. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((gun_index==2) ? 1: 0);
  3710. }
  3711. else
  3712. {
  3713. tempIndex = gun_index;
  3714. }
  3715. for (int index = 0; index < CCS_QUANTITY; index++)
  3716. {
  3717. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3718. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3719. {
  3720. reqClockAlignMeter[gun_index] = 1;
  3721. }
  3722. } // End for CCS
  3723. }
  3724. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3725. {
  3726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3727. {
  3728. tempIndex = ((gun_index==2) ? 1: 0);
  3729. }
  3730. else
  3731. {
  3732. tempIndex = gun_index;
  3733. }
  3734. for (int index = 0; index < GB_QUANTITY; index++)
  3735. {
  3736. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3737. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3738. {
  3739. reqClockAlignMeter[gun_index] = 1;
  3740. }
  3741. }// End for GB
  3742. }
  3743. else if(gunType[gun_index] == GUN_TYPE_DO)
  3744. {
  3745. tempIndex = gun_index;
  3746. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3747. {
  3748. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3749. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3750. {
  3751. reqClockAlignMeter[gun_index] = 1;
  3752. }
  3753. }
  3754. }
  3755. else
  3756. {
  3757. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3758. {
  3759. tempIndex = 2;
  3760. }
  3761. else
  3762. {
  3763. tempIndex = gun_index;
  3764. }
  3765. for (int index = 0; index < AC_QUANTITY; index++)
  3766. {
  3767. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3768. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3769. {
  3770. reqClockAlignMeter[gun_index] = 1;
  3771. }
  3772. }//End for AC
  3773. }
  3774. if(reqClockAlignMeter[gun_index] == 1)
  3775. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3776. }
  3777. // Sample period MeterValue
  3778. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3779. {
  3780. //check Transaction active
  3781. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3784. {
  3785. tempIndex = ((gun_index==2) ? 1: 0);
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3792. {
  3793. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3794. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3795. {
  3796. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3797. {
  3798. reqSampleMeter[gun_index] = 1;
  3799. }
  3800. }
  3801. }// End for CHAdeMO
  3802. }
  3803. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3804. {
  3805. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3806. {
  3807. tempIndex = ((gun_index==2) ? 1: 0);
  3808. }
  3809. else
  3810. {
  3811. tempIndex = gun_index;
  3812. }
  3813. for (int index = 0; index < CCS_QUANTITY; index++)
  3814. {
  3815. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3816. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3817. {
  3818. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3819. {
  3820. reqSampleMeter[gun_index] = 1;
  3821. }
  3822. }
  3823. } // End for CCS
  3824. }
  3825. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3826. {
  3827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3828. {
  3829. tempIndex = ((gun_index==2) ? 1: 0);
  3830. }
  3831. else
  3832. {
  3833. tempIndex = gun_index;
  3834. }
  3835. for (int index = 0; index < GB_QUANTITY; index++)
  3836. {
  3837. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3838. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3839. {
  3840. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3841. {
  3842. reqSampleMeter[gun_index] = 1;
  3843. }
  3844. }
  3845. }// End for GB
  3846. }
  3847. else if(gunType[gun_index] == GUN_TYPE_DO)
  3848. {
  3849. tempIndex = gun_index;
  3850. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3851. {
  3852. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3853. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3854. {
  3855. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3856. {
  3857. reqSampleMeter[gun_index] = 1;
  3858. }
  3859. }
  3860. }
  3861. }
  3862. else
  3863. {
  3864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3865. {
  3866. tempIndex = 2;
  3867. }
  3868. else
  3869. {
  3870. tempIndex = gun_index;
  3871. }
  3872. for (int index = 0; index < AC_QUANTITY; index++)
  3873. {
  3874. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3875. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3876. {
  3877. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3878. {
  3879. reqSampleMeter[gun_index] = 1;
  3880. }
  3881. }
  3882. }//End for AC
  3883. }
  3884. if(reqSampleMeter[gun_index] == 1)
  3885. {
  3886. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3887. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3888. storeTempStopTransaction(gun_index);
  3889. }
  3890. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3891. }
  3892. //==============================================
  3893. // Check Connector reserved
  3894. //==============================================
  3895. //===============================
  3896. // Check if Reserve is expired
  3897. //===============================
  3898. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  3899. {
  3900. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  3901. {
  3902. DEBUG_INFO("reserve expired.\n");
  3903. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3904. }
  3905. }//END OF Check if Reserve is expired
  3906. //==========================================
  3907. // csu trigger FirmwareStatusNotificationReq
  3908. //==========================================
  3909. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3910. {
  3911. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3912. }
  3913. //==========================================
  3914. // csu trigger DiagnosticsStatusNotificationReq
  3915. //==========================================
  3916. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3917. {
  3918. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3919. }
  3920. //==========================================
  3921. // csu trigger CancelReservationConf
  3922. //==========================================
  3923. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3924. {
  3925. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3926. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3927. }
  3928. //==========================================
  3929. // csu trigger ChangeAvailabilityConf
  3930. //==========================================
  3931. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3932. {
  3933. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3934. }
  3935. //==========================================
  3936. // csu trigger UnlockConnectorConf
  3937. //==========================================
  3938. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3939. {
  3940. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3941. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3942. }
  3943. //==========================================
  3944. // csu trigger ReserveNowConf
  3945. //==========================================
  3946. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3947. {
  3948. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3949. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3950. }
  3951. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3952. {
  3953. sendSignCertificateRequest();
  3954. }
  3955. }
  3956. }
  3957. //==========================================
  3958. // send request routine
  3959. //==========================================
  3960. int sendAuthorizeRequest(int gun_index)
  3961. {
  3962. mtrace();
  3963. int result = FAIL;
  3964. char message[100]={0};
  3965. char guid[37];
  3966. char tempdata[65]={0};
  3967. DEBUG_INFO("sendAuthorizeRequest...\n");
  3968. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3969. //Local Authorize
  3970. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3971. {
  3972. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3973. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3974. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3975. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3976. result = PASS;
  3977. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3978. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3979. authorizeRetryTimes = 0;
  3980. return result;
  3981. }
  3982. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  3983. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3984. {
  3985. // Query from cache
  3986. DEBUG_INFO("Authorize from cache.\n");
  3987. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3988. // Query from list
  3989. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3990. {
  3991. DEBUG_INFO("Authorize from list.\n");
  3992. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3993. }
  3994. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3995. {
  3996. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3997. {
  3998. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3999. }
  4000. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4001. {
  4002. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4003. }
  4004. if(!GetOcppConnStatus())
  4005. {
  4006. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4007. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4008. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4009. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4010. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4011. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4012. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4013. authorizeRetryTimes = 0;
  4014. return result;
  4015. }
  4016. }
  4017. else
  4018. {
  4019. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4020. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4021. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4022. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4023. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4024. else
  4025. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4026. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4027. result = PASS;
  4028. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4029. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4030. authorizeRetryTimes = 0;
  4031. return result;
  4032. }
  4033. }
  4034. //initialize struct Authorize
  4035. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4036. //get data from shared memory
  4037. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4038. random_uuid(guid);
  4039. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4040. LWS_Send(message);
  4041. sprintf(tempdata, "Authorize,%d", gun_index);
  4042. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4043. {
  4044. result = PASS;
  4045. DEBUG_INFO("Authorize mapItem pass\n");
  4046. }
  4047. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4048. return result;
  4049. }
  4050. int sendBootNotificationRequest(void)
  4051. {
  4052. mtrace();
  4053. int result = FAIL;
  4054. char message[500]={0}, payload[700]={0};
  4055. char guid[37]={0};
  4056. char tempdata[65]={0};
  4057. // Fill BootNotification fields
  4058. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4059. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4060. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4061. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4062. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4063. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4064. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4065. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4066. ShmOCPP16Data->ChargeBoxId
  4067. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4068. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4069. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4070. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4071. ,ShmOCPP16Data->BootNotification.CpIccid
  4072. ,ShmOCPP16Data->BootNotification.CpImsi);
  4073. random_uuid(guid);
  4074. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4075. LWS_Send(message);
  4076. sprintf(tempdata, "BootNotification,0");
  4077. 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*/)
  4078. {
  4079. result = PASS;
  4080. }
  4081. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4082. strcpy(queuedata,message);
  4083. return result;
  4084. }
  4085. int sendDataTransferRequest(int gun_index)
  4086. {
  4087. mtrace();
  4088. char message[1000]={0};
  4089. char guid[37]={0};
  4090. char tempdata[65]={0};
  4091. int result = FAIL;
  4092. random_uuid(guid);
  4093. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4094. MESSAGE_TYPE_CALL,
  4095. guid,
  4096. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4097. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4098. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4099. LWS_Send(message);
  4100. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4101. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4102. {
  4103. result = PASS;
  4104. DEBUG_INFO("DataTransfer mapItem pass\n");
  4105. }
  4106. return result;
  4107. }
  4108. int sendDiagnosticsStatusNotificationRequest(char *status)
  4109. {
  4110. mtrace();
  4111. int result = FAIL;
  4112. char message[110]={0};
  4113. char guid[37]={0};
  4114. char tempdata[65]={0};
  4115. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4116. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4117. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4118. random_uuid(guid);
  4119. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4120. LWS_SendNow(message);
  4121. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4122. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4123. {
  4124. result = PASS;
  4125. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4126. }
  4127. //#ifdef SystemLogMessage
  4128. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4129. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4130. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4131. //#endif
  4132. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4133. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4134. //record status
  4135. if(strcmp(status,"Idle")==0)
  4136. {
  4137. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4138. }
  4139. else if(strcmp(status,"Uploaded")==0)
  4140. {
  4141. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4142. }
  4143. else if(strcmp(status,"UploadFailed")==0)
  4144. {
  4145. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4146. }
  4147. else if(strcmp(status,"Uploading")==0)
  4148. {
  4149. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4150. }
  4151. return result;
  4152. }
  4153. int sendFirmwareStatusNotificationRequest(char *status)
  4154. {
  4155. mtrace();
  4156. int result = FAIL;
  4157. char message[110]={0};
  4158. char guid[37]={0};
  4159. char tempdata[65]={0};
  4160. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4161. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4162. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4163. random_uuid(guid);
  4164. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4165. LWS_SendNow(message);
  4166. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4167. 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*/)
  4168. {
  4169. result = PASS;
  4170. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4171. }
  4172. //#ifdef SystemLogMessage
  4173. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4174. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4175. //#endif
  4176. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4177. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4178. //record status
  4179. if(strcmp(status,"Downloaded")==0)
  4180. {
  4181. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4182. }
  4183. else if(strcmp(status,"DownloadFailed")==0)
  4184. {
  4185. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4186. }
  4187. else if(strcmp(status,"Downloading")==0)
  4188. {
  4189. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4190. }
  4191. else if(strcmp(status,"Idle")==0)
  4192. {
  4193. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4194. }
  4195. else if(strcmp(status,"InstallationFailed")==0)
  4196. {
  4197. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4198. }
  4199. else if(strcmp(status,"Installing")==0)
  4200. {
  4201. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4202. }
  4203. else if(strcmp(status,"Installed")==0)
  4204. {
  4205. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4206. }
  4207. return result;
  4208. }
  4209. int sendHeartbeatRequest(int gun_index)
  4210. {
  4211. mtrace();
  4212. int result = FAIL;
  4213. char message[80]={0};
  4214. char guid[37]={0};
  4215. char tempdata[65]={0};
  4216. random_uuid(guid);
  4217. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4218. , MESSAGE_TYPE_CALL
  4219. , guid );
  4220. LWS_Send(message);
  4221. sprintf(tempdata, "Heartbeat,%d", 0);
  4222. 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*/)
  4223. {
  4224. result = PASS;
  4225. }
  4226. return result;
  4227. }
  4228. int sendStartTransactionRequest(int gun_index)
  4229. {
  4230. mtrace();
  4231. int result = FAIL;
  4232. char message[250]={0};
  4233. char guid[37]={0};
  4234. struct timeval tmnow;
  4235. struct tm *tm;
  4236. char buf[28];//, usec_buf[6];
  4237. char tempdata[65]={0};
  4238. int tempIndex = 0;
  4239. DEBUG_INFO("sendStartTransactionRequest...\n");
  4240. gettimeofday(&tmnow, NULL);
  4241. time_t t;
  4242. t = time(NULL);
  4243. /*UTC time and date*/
  4244. tm = gmtime(&t);
  4245. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4246. #if 0 // remove temporally
  4247. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4248. strcat(buf,".");
  4249. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4250. strcat(buf,usec_buf);
  4251. #endif
  4252. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4253. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4254. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4255. // clear StartTransaction Response
  4256. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4257. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4258. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4259. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4260. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4261. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4262. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4263. {
  4264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4265. {
  4266. tempIndex = ((gun_index==2) ? 1: 0);
  4267. }
  4268. else
  4269. {
  4270. tempIndex = gun_index;
  4271. }
  4272. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4273. {
  4274. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4275. {
  4276. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4277. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4278. }
  4279. }
  4280. }
  4281. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4282. {
  4283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4284. {
  4285. tempIndex = ((gun_index==2) ? 1: 0);
  4286. }
  4287. else
  4288. {
  4289. tempIndex = gun_index;
  4290. }
  4291. for (int index = 0; index < CCS_QUANTITY; index++)
  4292. {
  4293. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4294. {
  4295. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4296. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4297. }
  4298. }
  4299. }
  4300. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4301. {
  4302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4303. {
  4304. tempIndex = ((gun_index==2) ? 1: 0);
  4305. }
  4306. else
  4307. {
  4308. tempIndex = gun_index;
  4309. }
  4310. for (int index = 0; index < GB_QUANTITY; index++)
  4311. {
  4312. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4313. {
  4314. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4315. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4316. }
  4317. }
  4318. }
  4319. else if(gunType[gun_index] == GUN_TYPE_DO)
  4320. {
  4321. tempIndex = gun_index;
  4322. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4323. {
  4324. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4325. {
  4326. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4327. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4328. }
  4329. }
  4330. }
  4331. else
  4332. {
  4333. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4334. {
  4335. tempIndex = 2;
  4336. }
  4337. else
  4338. {
  4339. tempIndex = gun_index;
  4340. }
  4341. for (int index = 0; index < AC_QUANTITY; index++)
  4342. {
  4343. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4344. {
  4345. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4346. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4347. }
  4348. }
  4349. }
  4350. random_uuid(guid);
  4351. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4352. {
  4353. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4354. , gun_index +1
  4355. , MESSAGE_TYPE_CALL
  4356. , guid
  4357. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4358. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4359. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4360. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4361. }
  4362. else
  4363. {
  4364. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4365. , gun_index +1
  4366. , MESSAGE_TYPE_CALL
  4367. , guid
  4368. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4369. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4370. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4371. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4372. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4373. }
  4374. #if 1
  4375. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4376. 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*/)
  4377. {
  4378. result = PASS;
  4379. }
  4380. #endif
  4381. strcpy(queuedata, message);
  4382. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4383. OCPP_insert_transaction_msg(YES, queuedata);
  4384. return result;
  4385. }
  4386. int sendStatusNotificationRequest(int gun_index)
  4387. {
  4388. mtrace();
  4389. int result = FAIL;
  4390. char message[600]={0};
  4391. char guid[37];
  4392. int currentStatus = 0;
  4393. struct timeval tmnow;
  4394. struct tm *tm;
  4395. char buf[28];//, usec_buf[6];
  4396. char tempdata[65]={0};
  4397. int tempIndex = 0;
  4398. uint8_t isStateChanged = TRUE;
  4399. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4400. gettimeofday(&tmnow, NULL);
  4401. time_t t;
  4402. t = time(NULL);
  4403. /*UTC time and date*/
  4404. tm = gmtime(&t);
  4405. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4406. #if 0 // remove temporally
  4407. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4408. strcat(buf,".");
  4409. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4410. strcat(buf,usec_buf);
  4411. #endif
  4412. //printf("%s",buf);
  4413. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4414. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4415. // it's option
  4416. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4417. /*
  4418. enum _SYSTEM_STATUS
  4419. {
  4420. S_BOOTING = 0,
  4421. S_IDLE, = 1
  4422. S_AUTHORIZING, =2
  4423. S_REASSIGN_CHECK, =3
  4424. S_REASSIGN, =4
  4425. S_PRECHARGE, =5
  4426. S_PREPARING_FOR_EV, =6
  4427. S_PREPARING_FOR_EVSE, =7
  4428. S_CHARGING, =8
  4429. S_TERMINATING, =9
  4430. S_COMPLETE, =10
  4431. S_ALARM, =11
  4432. S_FAULT =12
  4433. }
  4434. */
  4435. //check Transaction active
  4436. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4437. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4438. {
  4439. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4440. {
  4441. tempIndex = ((gun_index==2) ? 1: 0);
  4442. }
  4443. else
  4444. {
  4445. tempIndex = gun_index;
  4446. }
  4447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4448. {
  4449. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4450. {
  4451. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4452. {
  4453. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4454. {
  4455. currentStatus = Preparing; //OCPP Status: Preparing
  4456. }
  4457. else
  4458. {
  4459. currentStatus = Available; //OCPP Status: Available
  4460. }
  4461. }
  4462. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4463. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4464. ) //S_PRECHARGE
  4465. {
  4466. currentStatus = Preparing; //OCPP Status: Preparing
  4467. }
  4468. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4469. {
  4470. currentStatus = Charging; //OCPP Status: Charging
  4471. }
  4472. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4473. {
  4474. currentStatus = Finishing; //OCPP Status: Finishing
  4475. }
  4476. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4477. {
  4478. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4479. }
  4480. 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
  4481. {
  4482. currentStatus = Unavailable; //OCPP Status: Unavailable
  4483. }
  4484. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4485. {
  4486. currentStatus = Faulted; //OCPP Status: Faulted
  4487. }
  4488. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4489. {
  4490. currentStatus = Reserved; //OCPP Status: Reserved
  4491. }
  4492. } //end of the same index
  4493. }//end of for CHAdeMO_QUANTITY
  4494. }
  4495. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4496. {
  4497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4498. {
  4499. tempIndex = ((gun_index==2) ? 1: 0);
  4500. }
  4501. else
  4502. {
  4503. tempIndex = gun_index;
  4504. }
  4505. for (int index = 0; index < CCS_QUANTITY; index++)
  4506. {
  4507. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4508. {
  4509. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4510. {
  4511. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4512. {
  4513. currentStatus = Preparing; //OCPP Status: Preparing
  4514. }
  4515. else
  4516. {
  4517. currentStatus = Available; //OCPP Status: Available
  4518. }
  4519. }
  4520. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4521. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4522. ) //S_PRECHARGE
  4523. {
  4524. currentStatus = Preparing; //OCPP Status: Preparing
  4525. }
  4526. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4527. {
  4528. currentStatus = Charging; //OCPP Status: Charging
  4529. }
  4530. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4531. {
  4532. currentStatus = Finishing; //OCPP Status: Finishing
  4533. }
  4534. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4535. {
  4536. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4537. }
  4538. 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
  4539. {
  4540. currentStatus = Unavailable; //OCPP Status : Unavailable
  4541. }
  4542. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4543. {
  4544. currentStatus = Faulted; //OCPP Status: Faulted
  4545. }
  4546. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4547. {
  4548. currentStatus = Reserved; //OCPP Status: Reserved
  4549. }
  4550. } //end of the same index
  4551. } // end of for CCS_QUANTITY
  4552. }
  4553. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4554. {
  4555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4556. {
  4557. tempIndex = ((gun_index==2) ? 1: 0);
  4558. }
  4559. else
  4560. {
  4561. tempIndex = gun_index;
  4562. }
  4563. for (int index = 0; index < GB_QUANTITY; index++)
  4564. {
  4565. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4566. {
  4567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4568. {
  4569. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4570. {
  4571. currentStatus = Preparing; //OCPP Status: Preparing
  4572. }
  4573. else
  4574. {
  4575. currentStatus = Available; //OCPP Status: Available
  4576. }
  4577. }
  4578. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4579. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4580. ) //S_PRECHARGE
  4581. {
  4582. currentStatus = Preparing; //OCPP Status: Preparing
  4583. }
  4584. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4585. {
  4586. currentStatus = Charging; //OCPP Status: Charging
  4587. }
  4588. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4589. {
  4590. currentStatus = Finishing; //OCPP Status: Finishing
  4591. }
  4592. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4593. {
  4594. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4595. }
  4596. 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
  4597. {
  4598. currentStatus = Unavailable; //OCPP Status: Unavailable
  4599. }
  4600. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4601. {
  4602. currentStatus = Faulted; //OCPP Status: Faulted
  4603. }
  4604. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4605. {
  4606. currentStatus = Reserved; //OCPP Status: Reserved
  4607. }
  4608. } //end of the same index
  4609. } // end of for GB_QUANTITY
  4610. }
  4611. else if(gunType[gun_index] == GUN_TYPE_DO)
  4612. {
  4613. tempIndex = gun_index;
  4614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4615. {
  4616. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4617. {
  4618. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4619. {
  4620. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4621. {
  4622. currentStatus = Preparing; //OCPP Status: Preparing
  4623. }
  4624. else
  4625. {
  4626. currentStatus = Available; //OCPP Status: Available
  4627. }
  4628. }
  4629. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4630. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4631. ) //S_PRECHARGE
  4632. {
  4633. currentStatus = Preparing; //OCPP Status: Preparing
  4634. }
  4635. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4636. {
  4637. currentStatus = Charging; //OCPP Status: Charging
  4638. }
  4639. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4640. {
  4641. currentStatus = Finishing; //OCPP Status: Finishing
  4642. }
  4643. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4644. {
  4645. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4646. }
  4647. 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
  4648. {
  4649. currentStatus = Unavailable; //OCPP Status: Unavailable
  4650. }
  4651. 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
  4652. {
  4653. currentStatus = Faulted; //OCPP Status: Faulted
  4654. }
  4655. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4656. {
  4657. currentStatus = Reserved; //OCPP Status: Reserved
  4658. }
  4659. } //end of the same index
  4660. }
  4661. }
  4662. else
  4663. {
  4664. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4665. {
  4666. tempIndex = 2;
  4667. }
  4668. else
  4669. {
  4670. tempIndex = gun_index;
  4671. }
  4672. for (int index = 0; index < AC_QUANTITY; index++)
  4673. {
  4674. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4675. {
  4676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4677. {
  4678. 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))
  4679. {
  4680. currentStatus = Preparing; //OCPP Status: Preparing
  4681. }
  4682. else
  4683. {
  4684. currentStatus = Available; //OCPP Status: Available
  4685. }
  4686. }
  4687. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4688. {
  4689. currentStatus = Preparing; //OCPP Status: Preparing
  4690. }
  4691. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4692. {
  4693. currentStatus = Charging; //OCPP Status: Charging
  4694. }
  4695. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4696. {
  4697. currentStatus = Finishing; //OCPP Status: Finishing
  4698. }
  4699. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4700. {
  4701. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4702. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4703. else
  4704. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4705. }
  4706. 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
  4707. {
  4708. currentStatus = Unavailable; //OCPP Status: Unavailable
  4709. }
  4710. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4711. {
  4712. currentStatus = Faulted; //OCPP Status: Faulted
  4713. }
  4714. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4715. {
  4716. currentStatus = Reserved; //OCPP Status: Reserved
  4717. }
  4718. }//end of the same index
  4719. }//end of for AC_QUANTITY
  4720. }
  4721. //it's option
  4722. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4723. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4724. {
  4725. isStateChanged = FALSE;
  4726. }
  4727. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4728. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4729. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4730. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4731. random_uuid(guid);
  4732. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4733. , MESSAGE_TYPE_CALL
  4734. , guid
  4735. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4736. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4737. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4738. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4739. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4740. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4741. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4742. if((server_sign == TRUE) && isStateChanged)
  4743. {
  4744. LWS_Send(message);
  4745. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4746. 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*/)
  4747. {
  4748. //DEBUG_ERROR("statusNotification mapitem pass");
  4749. result = PASS;
  4750. }
  4751. }
  4752. else
  4753. {
  4754. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4755. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4756. result = PASS;
  4757. }
  4758. return result;
  4759. }
  4760. int sendStopTransactionRequest(int gun_index)
  4761. {
  4762. mtrace();
  4763. int result = FAIL;
  4764. //char message[1500]={0};
  4765. char guid[37]={0};
  4766. char tempdata[65]={0};
  4767. int tempIndex = 0;
  4768. char TempStopTransaction[256];
  4769. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4770. //int idx_sample=0;
  4771. DEBUG_INFO("sendStopTransactionRequest \n");
  4772. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4773. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4774. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4775. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4776. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4777. {
  4778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4779. {
  4780. tempIndex = ((gun_index==2) ? 1: 0);
  4781. }
  4782. else
  4783. {
  4784. tempIndex = gun_index;
  4785. }
  4786. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4787. {
  4788. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4789. {
  4790. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4791. }
  4792. }// END OF CHAdeMO_QUANTITY
  4793. }
  4794. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4795. {
  4796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4797. {
  4798. tempIndex = ((gun_index==2) ? 1: 0);
  4799. }
  4800. else
  4801. {
  4802. tempIndex = gun_index;
  4803. }
  4804. for (int index = 0; index < CCS_QUANTITY; index++)
  4805. {
  4806. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4807. {
  4808. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4809. }
  4810. }// END OF CCS_QUANTITY
  4811. }
  4812. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4813. {
  4814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4815. {
  4816. tempIndex = ((gun_index==2) ? 1: 0);
  4817. }
  4818. else
  4819. {
  4820. tempIndex = gun_index;
  4821. }
  4822. for (int index = 0; index < GB_QUANTITY; index++)
  4823. {
  4824. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4825. {
  4826. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4827. }
  4828. }// END OF GB_QUANTITY
  4829. }
  4830. else if(gunType[gun_index] == GUN_TYPE_DO)
  4831. {
  4832. tempIndex = gun_index;
  4833. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4834. {
  4835. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4836. {
  4837. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4838. }
  4839. }// END OF GB_QUANTITY
  4840. }
  4841. else
  4842. {
  4843. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4844. {
  4845. tempIndex = 2;
  4846. }
  4847. else
  4848. {
  4849. tempIndex = gun_index;
  4850. }
  4851. for (int index = 0; index < AC_QUANTITY; index++)
  4852. {
  4853. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4854. {
  4855. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4856. }
  4857. }// END OF AC_QUANTITY
  4858. }
  4859. //====================================== Stop Transaction Time =====================================================
  4860. struct timeval tmnow;
  4861. struct tm *tm;
  4862. char buf[28];//, usec_buf[6];
  4863. gettimeofday(&tmnow, NULL);
  4864. time_t t;
  4865. t = time(NULL);
  4866. /*UTC time and date*/
  4867. tm = gmtime(&t);
  4868. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4870. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4871. random_uuid(guid);
  4872. /***********************************transactionData******************************************************/
  4873. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4875. //=================================
  4876. // Transaction_Begin
  4877. //=================================
  4878. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4879. {
  4880. //============================================ Energy.Active.Import.Interval ================================
  4881. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4885. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4886. 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))
  4887. {
  4888. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4889. }
  4890. else
  4891. {
  4892. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4893. }
  4894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4896. }
  4897. //=================================
  4898. // Transaction_End
  4899. //=================================
  4900. // ================================= Current.Import L1 ===============================================
  4901. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4902. {
  4903. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4904. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4905. {
  4906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4907. {
  4908. tempIndex = ((gun_index==2) ? 1: 0);
  4909. }
  4910. else
  4911. {
  4912. tempIndex = gun_index;
  4913. }
  4914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4915. {
  4916. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4917. {
  4918. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4919. }
  4920. }// End of for CHAdeMO_QUANTITY
  4921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4922. }
  4923. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4924. {
  4925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4926. {
  4927. tempIndex = ((gun_index==2) ? 1: 0);
  4928. }
  4929. else
  4930. {
  4931. tempIndex = gun_index;
  4932. }
  4933. for (int index = 0; index < CCS_QUANTITY; index++)
  4934. {
  4935. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4936. {
  4937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4938. }
  4939. }// End of for CCS_QUANTITY
  4940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4941. }
  4942. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4943. {
  4944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4945. {
  4946. tempIndex = ((gun_index==2) ? 1: 0);
  4947. }
  4948. else
  4949. {
  4950. tempIndex = gun_index;
  4951. }
  4952. for (int index = 0; index < GB_QUANTITY; index++)
  4953. {
  4954. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4955. {
  4956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4957. }
  4958. }// End of for GB_QUANTITY
  4959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4960. }
  4961. else if(gunType[gun_index] == GUN_TYPE_DO)
  4962. {
  4963. tempIndex = gun_index;
  4964. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4965. {
  4966. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4967. {
  4968. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4969. }
  4970. }
  4971. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4972. }
  4973. else
  4974. {
  4975. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4976. {
  4977. tempIndex = 2;
  4978. }
  4979. else
  4980. {
  4981. tempIndex = gun_index;
  4982. }
  4983. for (int index = 0; index < AC_QUANTITY; index++)
  4984. {
  4985. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4986. {
  4987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4988. }
  4989. }// End of for AC_QUANTITY
  4990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4991. }
  4992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4997. }
  4998. // ================================= Energy.Active.Import.Interval ==============================================
  4999. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5000. {
  5001. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5002. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5003. {
  5004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5005. {
  5006. tempIndex = ((gun_index==2) ? 1: 0);
  5007. }
  5008. else
  5009. {
  5010. tempIndex = gun_index;
  5011. }
  5012. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5015. {
  5016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5017. }
  5018. }// END OF CHAdeMO_QUANTITY
  5019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5020. }
  5021. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5022. {
  5023. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5024. {
  5025. tempIndex = ((gun_index==2) ? 1: 0);
  5026. }
  5027. else
  5028. {
  5029. tempIndex = gun_index;
  5030. }
  5031. for (int index = 0; index < CCS_QUANTITY; index++)
  5032. {
  5033. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5034. {
  5035. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5036. }
  5037. }// END OF CCS_QUANTITY
  5038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5039. }
  5040. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5041. {
  5042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5043. {
  5044. tempIndex = ((gun_index==2) ? 1: 0);
  5045. }
  5046. else
  5047. {
  5048. tempIndex = gun_index;
  5049. }
  5050. for (int index = 0; index < GB_QUANTITY; index++)
  5051. {
  5052. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5053. {
  5054. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5055. }
  5056. }// END OF GB_QUANTITY
  5057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5058. }
  5059. else if(gunType[gun_index] == GUN_TYPE_DO)
  5060. {
  5061. tempIndex = gun_index;
  5062. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5063. {
  5064. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5065. {
  5066. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5067. }
  5068. }
  5069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5070. }
  5071. else
  5072. {
  5073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5074. {
  5075. tempIndex = 2;
  5076. }
  5077. else
  5078. {
  5079. tempIndex = gun_index;
  5080. }
  5081. for (int index = 0; index < AC_QUANTITY; index++)
  5082. {
  5083. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5084. {
  5085. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5086. }
  5087. }// END OF AC_QUANTITY
  5088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5089. }
  5090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5092. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5094. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5095. }
  5096. //=================================== Power.Active.Import ==================================================
  5097. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5098. {
  5099. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5100. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5101. {
  5102. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5103. {
  5104. tempIndex = ((gun_index==2) ? 1: 0);
  5105. }
  5106. else
  5107. {
  5108. tempIndex = gun_index;
  5109. }
  5110. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5111. {
  5112. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5113. {
  5114. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5115. }
  5116. } // End for CHAdeMO_QUANTITY
  5117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5118. }
  5119. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5120. {
  5121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5122. {
  5123. tempIndex = ((gun_index==2) ? 1: 0);
  5124. }
  5125. else
  5126. {
  5127. tempIndex = gun_index;
  5128. }
  5129. for (int index = 0; index < CCS_QUANTITY; index++)
  5130. {
  5131. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5132. {
  5133. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5134. }
  5135. } // END for CCS_QUANTITY
  5136. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5137. }
  5138. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5139. {
  5140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5141. {
  5142. tempIndex = ((gun_index==2) ? 1: 0);
  5143. }
  5144. else
  5145. {
  5146. tempIndex = gun_index;
  5147. }
  5148. for (int index = 0; index < GB_QUANTITY; index++)
  5149. {
  5150. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5151. {
  5152. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5153. }
  5154. }// END for GB_QUANTITY
  5155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5156. }
  5157. else if(gunType[gun_index] == GUN_TYPE_DO)
  5158. {
  5159. tempIndex = gun_index;
  5160. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5161. {
  5162. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5163. {
  5164. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5165. }
  5166. }
  5167. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5168. }
  5169. else
  5170. {
  5171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5172. {
  5173. tempIndex = 2;
  5174. }
  5175. else
  5176. {
  5177. tempIndex = gun_index;
  5178. }
  5179. for (int index = 0; index < AC_QUANTITY; index++)
  5180. {
  5181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5182. {
  5183. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5184. }
  5185. } // END for AC_QUANTITY
  5186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5187. }
  5188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5193. }
  5194. //============================ Voltage L1 ====================================
  5195. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5196. {
  5197. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5198. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5199. {
  5200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5201. {
  5202. tempIndex = ((gun_index==2) ? 1: 0);
  5203. }
  5204. else
  5205. {
  5206. tempIndex = gun_index;
  5207. }
  5208. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5209. {
  5210. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5211. {
  5212. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5213. }
  5214. } // END OF FOR CHAdeMO_QUANTITY
  5215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5216. }
  5217. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5218. {
  5219. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5220. {
  5221. tempIndex = ((gun_index==2) ? 1: 0);
  5222. }
  5223. else
  5224. {
  5225. tempIndex = gun_index;
  5226. }
  5227. for (int index = 0; index < CCS_QUANTITY; index++)
  5228. {
  5229. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5230. {
  5231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5232. }
  5233. } // END OF FOR CCS_QUANTITY
  5234. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5235. }
  5236. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5237. {
  5238. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5239. {
  5240. tempIndex = ((gun_index==2) ? 1: 0);
  5241. }
  5242. else
  5243. {
  5244. tempIndex = gun_index;
  5245. }
  5246. for (int index = 0; index < GB_QUANTITY; index++)
  5247. {
  5248. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5249. {
  5250. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5251. }
  5252. } // END OF FOR GB_QUANTITY
  5253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5254. }
  5255. else if(gunType[gun_index] == GUN_TYPE_DO)
  5256. {
  5257. tempIndex = gun_index;
  5258. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5259. {
  5260. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5261. {
  5262. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5263. }
  5264. }
  5265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5266. }
  5267. else
  5268. {
  5269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5270. {
  5271. tempIndex = 2;
  5272. }
  5273. else
  5274. {
  5275. tempIndex = gun_index;
  5276. }
  5277. for (int index = 0; index < AC_QUANTITY; index++)
  5278. {
  5279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5280. {
  5281. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5282. }
  5283. } // END OF FOR AC_QUANTITY
  5284. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5285. }
  5286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5291. }
  5292. //====================== End SoC ================================
  5293. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5294. {
  5295. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5296. 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))
  5297. {
  5298. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5299. {
  5300. tempIndex = ((gun_index==2) ? 1: 0);
  5301. }
  5302. else
  5303. {
  5304. tempIndex = gun_index;
  5305. }
  5306. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5307. {
  5308. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5309. {
  5310. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5311. {
  5312. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5313. }
  5314. }
  5315. }
  5316. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5317. {
  5318. for (int index = 0; index < CCS_QUANTITY; index++)
  5319. {
  5320. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5321. {
  5322. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5323. }
  5324. }
  5325. }
  5326. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5327. {
  5328. for (int index = 0; index < GB_QUANTITY; index++)
  5329. {
  5330. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5331. {
  5332. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5333. }
  5334. }
  5335. }
  5336. else if(gunType[gun_index] == GUN_TYPE_DO)
  5337. {
  5338. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5339. {
  5340. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5341. {
  5342. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5343. }
  5344. }
  5345. }
  5346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5348. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5350. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5352. } // END FOR DC CASE
  5353. }
  5354. // ================================= Current.Import L2 ===============================================
  5355. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5356. {
  5357. // AC 3 phse L2 current
  5358. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5359. {
  5360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5361. {
  5362. tempIndex = 2;
  5363. }
  5364. else
  5365. {
  5366. tempIndex = gun_index;
  5367. }
  5368. for (int index = 0; index < AC_QUANTITY; index++)
  5369. {
  5370. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5371. {
  5372. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5373. }
  5374. }// End of for AC_QUANTITY
  5375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5376. }
  5377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5382. }
  5383. // ================================= Current.Import L3 ===============================================
  5384. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5385. {
  5386. // AC 3 phse L3 current
  5387. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5388. {
  5389. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5390. {
  5391. tempIndex = 2;
  5392. }
  5393. else
  5394. {
  5395. tempIndex = gun_index;
  5396. }
  5397. for (int index = 0; index < AC_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5400. {
  5401. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5402. }
  5403. }// End of for AC_QUANTITY
  5404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5405. }
  5406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5407. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5411. }
  5412. //============================ Voltage L2 ====================================
  5413. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5414. {
  5415. // AC 3 phse L2 voltage
  5416. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5417. {
  5418. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5419. {
  5420. tempIndex = 2;
  5421. }
  5422. else
  5423. {
  5424. tempIndex = gun_index;
  5425. }
  5426. for (int index = 0; index < AC_QUANTITY; index++)
  5427. {
  5428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5429. {
  5430. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5431. }
  5432. } // END OF FOR AC_QUANTITY
  5433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5434. }
  5435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5440. }
  5441. //============================ Voltage L3 ====================================
  5442. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5443. {
  5444. // AC 3 phse L3 voltage
  5445. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5446. {
  5447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5448. {
  5449. tempIndex = 2;
  5450. }
  5451. else
  5452. {
  5453. tempIndex = gun_index;
  5454. }
  5455. for (int index = 0; index < AC_QUANTITY; index++)
  5456. {
  5457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5458. {
  5459. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5460. }
  5461. } // END OF FOR AC_QUANTITY
  5462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5463. }
  5464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5467. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5469. }
  5470. //====================== Start SoC ================================
  5471. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5472. {
  5473. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5474. 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))
  5475. {
  5476. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5477. {
  5478. tempIndex = ((gun_index==2) ? 1: 0);
  5479. }
  5480. else
  5481. {
  5482. tempIndex = gun_index;
  5483. }
  5484. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5485. {
  5486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5487. {
  5488. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5489. {
  5490. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5491. }
  5492. }
  5493. }
  5494. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5495. {
  5496. for (int index = 0; index < CCS_QUANTITY; index++)
  5497. {
  5498. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5499. {
  5500. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5501. }
  5502. }
  5503. }
  5504. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5505. {
  5506. for (int index = 0; index < GB_QUANTITY; index++)
  5507. {
  5508. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5509. {
  5510. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5511. }
  5512. }
  5513. }
  5514. else if(gunType[gun_index] == GUN_TYPE_DO)
  5515. {
  5516. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5517. {
  5518. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5519. {
  5520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5521. }
  5522. }
  5523. }
  5524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5530. } // END FOR DC CASE
  5531. }
  5532. //================================================ Message create ====================================================
  5533. json_object *StopTransaction = json_object_new_object();
  5534. json_object *transactionDatas = json_object_new_array();
  5535. json_object *sampledValues = json_object_new_array();
  5536. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5537. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5538. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5539. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5540. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5541. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5542. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5543. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5544. {
  5545. json_object *transactionData = json_object_new_object();
  5546. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5547. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5548. {
  5549. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5550. {
  5551. json_object *sampledValue = json_object_new_object();
  5552. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5553. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5554. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5555. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5556. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5557. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5558. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5559. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5560. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5561. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5562. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5563. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5564. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5565. json_object_array_add(sampledValues, sampledValue);
  5566. }
  5567. }
  5568. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5569. json_object_array_add(transactionDatas, transactionData);
  5570. }
  5571. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5572. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5573. ,MESSAGE_TYPE_CALL
  5574. ,guid
  5575. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5576. json_object_put(StopTransaction);
  5577. #if 1 // for TempStopTransaction
  5578. //Delete TempStopTransaction
  5579. if((access(TempStopTransaction,F_OK))!=-1)
  5580. {
  5581. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5582. }
  5583. #endif
  5584. #if 1
  5585. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5586. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5587. {
  5588. result = PASS;
  5589. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5590. }
  5591. #endif
  5592. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5593. OCPP_insert_transaction_msg(NO, queuedata);
  5594. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5595. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5596. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5597. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5598. {
  5599. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5600. }
  5601. //for test
  5602. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5603. return result;
  5604. }
  5605. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5606. {
  5607. mtrace();
  5608. int result = FAIL;
  5609. char guid[37]={0};
  5610. char tempdata[65]={0};
  5611. int tempIndex = 0;
  5612. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5613. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5614. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5615. //set value
  5616. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5617. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5618. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5619. -1);
  5620. random_uuid(guid);
  5621. //UTC Date time
  5622. struct timeval tmnow;
  5623. struct tm *tm;
  5624. char buf[28];//, usec_buf[6];
  5625. gettimeofday(&tmnow, NULL);
  5626. time_t t;
  5627. t = time(NULL);
  5628. /*UTC time and date*/
  5629. tm = gmtime(&t);
  5630. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5632. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5633. //********************************(1)Current.Import L1************************************************/
  5634. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5635. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5636. (dataType == ReadingContext_Trigger))
  5637. {
  5638. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5639. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5640. {
  5641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5642. {
  5643. tempIndex = ((gun_index==2) ? 1: 0);
  5644. }
  5645. else
  5646. {
  5647. tempIndex = gun_index;
  5648. }
  5649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5650. {
  5651. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5652. {
  5653. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5654. }
  5655. }
  5656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5657. }
  5658. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5659. {
  5660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5661. {
  5662. tempIndex = ((gun_index==2) ? 1: 0);
  5663. }
  5664. else
  5665. {
  5666. tempIndex = gun_index;
  5667. }
  5668. for (int index = 0; index < CCS_QUANTITY; index++)
  5669. {
  5670. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5671. {
  5672. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5673. }
  5674. }
  5675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5676. }
  5677. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5678. {
  5679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5680. {
  5681. tempIndex = ((gun_index==2) ? 1: 0);
  5682. }
  5683. else
  5684. {
  5685. tempIndex = gun_index;
  5686. }
  5687. for (int index = 0; index < GB_QUANTITY; index++)
  5688. {
  5689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5690. {
  5691. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5692. }
  5693. }
  5694. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5695. }
  5696. else if(gunType[gun_index] == GUN_TYPE_DO)
  5697. {
  5698. tempIndex = gun_index;
  5699. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5700. {
  5701. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5702. {
  5703. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5704. }
  5705. }
  5706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5707. }
  5708. else
  5709. {
  5710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5711. {
  5712. tempIndex = 2;
  5713. }
  5714. else
  5715. {
  5716. tempIndex = gun_index;
  5717. }
  5718. for (int index = 0; index < AC_QUANTITY; index++)
  5719. {
  5720. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5721. {
  5722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5723. }
  5724. }
  5725. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5726. }
  5727. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5728. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5729. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5730. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5731. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5732. }
  5733. //********************************(2)Energy.Active.Import.Register ************************************************/
  5734. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5735. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5736. (dataType == ReadingContext_Trigger))
  5737. {
  5738. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5739. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5740. {
  5741. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5742. {
  5743. tempIndex = ((gun_index==2) ? 1: 0);
  5744. }
  5745. else
  5746. {
  5747. tempIndex = gun_index;
  5748. }
  5749. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5750. {
  5751. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5752. {
  5753. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5754. }
  5755. }
  5756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5757. }
  5758. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5759. {
  5760. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5761. {
  5762. tempIndex = ((gun_index==2) ? 1: 0);
  5763. }
  5764. else
  5765. {
  5766. tempIndex = gun_index;
  5767. }
  5768. for (int index = 0; index < CCS_QUANTITY; index++)
  5769. {
  5770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5771. {
  5772. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5773. }
  5774. }
  5775. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5776. }
  5777. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5778. {
  5779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5780. {
  5781. tempIndex = ((gun_index==2) ? 1: 0);
  5782. }
  5783. else
  5784. {
  5785. tempIndex = gun_index;
  5786. }
  5787. for (int index = 0; index < GB_QUANTITY; index++)
  5788. {
  5789. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5790. {
  5791. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5792. }
  5793. }
  5794. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5795. }
  5796. else if(gunType[gun_index] == GUN_TYPE_DO)
  5797. {
  5798. tempIndex = gun_index;
  5799. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5800. {
  5801. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5802. {
  5803. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5804. }
  5805. }
  5806. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5807. }
  5808. else
  5809. {
  5810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5811. {
  5812. tempIndex = 2;
  5813. }
  5814. else
  5815. {
  5816. tempIndex = gun_index;
  5817. }
  5818. for (int index = 0; index < AC_QUANTITY; index++)
  5819. {
  5820. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5821. {
  5822. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5823. }
  5824. }
  5825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5826. }
  5827. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5830. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5831. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5832. }
  5833. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5834. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5835. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5836. (dataType == ReadingContext_Trigger))
  5837. {
  5838. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5839. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5840. {
  5841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5842. {
  5843. tempIndex = ((gun_index==2) ? 1: 0);
  5844. }
  5845. else
  5846. {
  5847. tempIndex = gun_index;
  5848. }
  5849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5850. {
  5851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5852. {
  5853. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5854. }
  5855. } // END OF FOR CHAdeMO_QUANTITY
  5856. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5857. }
  5858. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5859. {
  5860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5861. {
  5862. tempIndex = ((gun_index==2) ? 1: 0);
  5863. }
  5864. else
  5865. {
  5866. tempIndex = gun_index;
  5867. }
  5868. for (int index = 0; index < CCS_QUANTITY; index++)
  5869. {
  5870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5871. {
  5872. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5873. }
  5874. } // END OF CCS_QUANTITY
  5875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5876. }
  5877. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5878. {
  5879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5880. {
  5881. tempIndex = ((gun_index==2) ? 1: 0);
  5882. }
  5883. else
  5884. {
  5885. tempIndex = gun_index;
  5886. }
  5887. for (int index = 0; index < GB_QUANTITY; index++)
  5888. {
  5889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5890. {
  5891. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5892. }
  5893. } // END OF GB_QUANTITY
  5894. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5895. }
  5896. else if(gunType[gun_index] == GUN_TYPE_DO)
  5897. {
  5898. tempIndex = gun_index;
  5899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5900. {
  5901. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5902. {
  5903. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5904. }
  5905. }
  5906. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5907. }
  5908. else
  5909. {
  5910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5911. {
  5912. tempIndex = 2;
  5913. }
  5914. else
  5915. {
  5916. tempIndex = gun_index;
  5917. }
  5918. for (int index = 0; index < AC_QUANTITY; index++)
  5919. {
  5920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5921. {
  5922. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5923. }
  5924. }
  5925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5926. }
  5927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5929. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5930. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5931. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5932. }
  5933. //********************************(4)Power.Active.Import************************************************/
  5934. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5935. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5936. (dataType == ReadingContext_Trigger))
  5937. {
  5938. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5939. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5940. {
  5941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5942. {
  5943. tempIndex = ((gun_index==2) ? 1: 0);
  5944. }
  5945. else
  5946. {
  5947. tempIndex = gun_index;
  5948. }
  5949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5950. {
  5951. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5952. {
  5953. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5954. }
  5955. } // END OF FOR
  5956. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5957. }
  5958. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5959. {
  5960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5961. {
  5962. tempIndex = ((gun_index==2) ? 1: 0);
  5963. }
  5964. else
  5965. {
  5966. tempIndex = gun_index;
  5967. }
  5968. for (int index = 0; index < CCS_QUANTITY; index++)
  5969. {
  5970. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5971. {
  5972. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5973. }
  5974. }
  5975. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5976. }
  5977. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5978. {
  5979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5980. {
  5981. tempIndex = ((gun_index==2) ? 1: 0);
  5982. }
  5983. else
  5984. {
  5985. tempIndex = gun_index;
  5986. }
  5987. for (int index = 0; index < GB_QUANTITY; index++)
  5988. {
  5989. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5990. {
  5991. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5992. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5993. }
  5994. }
  5995. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5996. }
  5997. else if(gunType[gun_index] == GUN_TYPE_DO)
  5998. {
  5999. tempIndex = gun_index;
  6000. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6001. {
  6002. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6003. {
  6004. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6005. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6006. }
  6007. }
  6008. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6009. }
  6010. else
  6011. {
  6012. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6013. {
  6014. tempIndex = 2;
  6015. }
  6016. else
  6017. {
  6018. tempIndex = gun_index;
  6019. }
  6020. for (int index = 0; index < AC_QUANTITY; index++)
  6021. {
  6022. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6023. {
  6024. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6025. }
  6026. }
  6027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6028. }
  6029. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6031. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6032. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6033. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6034. }
  6035. //***********************************************(5)VOLTAGE L1******************************************************/
  6036. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6037. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6038. (dataType == ReadingContext_Trigger))
  6039. {
  6040. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6041. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6042. {
  6043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6044. {
  6045. tempIndex = ((gun_index==2) ? 1: 0);
  6046. }
  6047. else
  6048. {
  6049. tempIndex = gun_index;
  6050. }
  6051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6052. {
  6053. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6054. {
  6055. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6056. }
  6057. }
  6058. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6059. }
  6060. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6061. {
  6062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6063. {
  6064. tempIndex = ((gun_index==2) ? 1: 0);
  6065. }
  6066. else
  6067. {
  6068. tempIndex = gun_index;
  6069. }
  6070. for (int index = 0; index < CCS_QUANTITY; index++)
  6071. {
  6072. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6073. {
  6074. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6075. }
  6076. }
  6077. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6078. }
  6079. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6080. {
  6081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6082. {
  6083. tempIndex = ((gun_index==2) ? 1: 0);
  6084. }
  6085. else
  6086. {
  6087. tempIndex = gun_index;
  6088. }
  6089. for (int index = 0; index < GB_QUANTITY; index++)
  6090. {
  6091. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6092. {
  6093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6094. }
  6095. }
  6096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6097. }
  6098. else if(gunType[gun_index] == GUN_TYPE_DO)
  6099. {
  6100. tempIndex = gun_index;
  6101. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6104. {
  6105. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6106. }
  6107. }
  6108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6109. }
  6110. else
  6111. {
  6112. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6113. {
  6114. tempIndex = 2;
  6115. }
  6116. else
  6117. {
  6118. tempIndex = gun_index;
  6119. }
  6120. for (int index = 0; index < AC_QUANTITY; index++)
  6121. {
  6122. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6123. {
  6124. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6125. }
  6126. }
  6127. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6128. }
  6129. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6134. }
  6135. //***********************************************(6)SOC******************************************************/
  6136. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6137. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6138. (dataType == ReadingContext_Trigger))
  6139. {
  6140. 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))
  6141. {
  6142. //idx_sample=5;
  6143. //sampledValue = NULL;
  6144. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6145. {
  6146. tempIndex = ((gun_index==2) ? 1: 0);
  6147. }
  6148. else
  6149. {
  6150. tempIndex = gun_index;
  6151. }
  6152. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6153. {
  6154. //tempIndex = ((gun_index==2) ? 1: 0);
  6155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6156. {
  6157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6158. {
  6159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6160. }
  6161. }
  6162. }
  6163. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6164. {
  6165. //tempIndex = ((gun_index==2) ? 1: 0);
  6166. for (int index = 0; index < CCS_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6169. {
  6170. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6171. }
  6172. }
  6173. }
  6174. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6175. {
  6176. //tempIndex = ((gun_index==2) ? 1: 0);
  6177. for (int index = 0; index < GB_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6180. {
  6181. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6182. }
  6183. }
  6184. }
  6185. else if(gunType[gun_index] == GUN_TYPE_DO)
  6186. {
  6187. //tempIndex = ((gun_index==2) ? 1: 0);
  6188. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6189. {
  6190. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6191. {
  6192. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6193. }
  6194. }
  6195. }
  6196. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6197. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6198. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6199. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6202. }
  6203. }
  6204. //********************************(7)Current.Import L2************************************************/
  6205. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6206. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6207. (dataType == ReadingContext_Trigger))
  6208. {
  6209. // Only for AC 3 phase
  6210. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6211. {
  6212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6213. {
  6214. tempIndex = 2;
  6215. }
  6216. else
  6217. {
  6218. tempIndex = gun_index;
  6219. }
  6220. for (int index = 0; index < AC_QUANTITY; index++)
  6221. {
  6222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6223. {
  6224. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6225. }
  6226. }
  6227. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6228. }
  6229. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6230. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6231. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6232. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6233. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6234. }
  6235. //********************************(8)Current.Import L3************************************************/
  6236. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6237. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6238. (dataType == ReadingContext_Trigger))
  6239. {
  6240. // Only for AC 3 phase
  6241. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6242. {
  6243. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6244. {
  6245. tempIndex = 2;
  6246. }
  6247. else
  6248. {
  6249. tempIndex = gun_index;
  6250. }
  6251. for (int index = 0; index < AC_QUANTITY; index++)
  6252. {
  6253. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6254. {
  6255. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6256. }
  6257. }
  6258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6259. }
  6260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6261. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6262. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6263. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6264. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6265. }
  6266. //***********************************************(9)VOLTAGE L2******************************************************/
  6267. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6268. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6269. (dataType == ReadingContext_Trigger))
  6270. {
  6271. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6272. {
  6273. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6274. {
  6275. tempIndex = 2;
  6276. }
  6277. else
  6278. {
  6279. tempIndex = gun_index;
  6280. }
  6281. for (int index = 0; index < AC_QUANTITY; index++)
  6282. {
  6283. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6284. {
  6285. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6286. }
  6287. }
  6288. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6289. }
  6290. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6291. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6292. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6295. }
  6296. //***********************************************(10)VOLTAGE L3******************************************************/
  6297. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6298. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6299. (dataType == ReadingContext_Trigger))
  6300. {
  6301. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6302. {
  6303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6304. {
  6305. tempIndex = 2;
  6306. }
  6307. else
  6308. {
  6309. tempIndex = gun_index;
  6310. }
  6311. for (int index = 0; index < AC_QUANTITY; index++)
  6312. {
  6313. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6314. {
  6315. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6316. }
  6317. }
  6318. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6319. }
  6320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6321. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6322. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6323. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6324. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6325. }
  6326. //***********************************************(11)Current.Offered******************************************************/
  6327. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6328. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6329. (dataType == ReadingContext_Trigger))
  6330. {
  6331. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6332. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6333. {
  6334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6335. {
  6336. tempIndex = ((gun_index==2) ? 1: 0);
  6337. }
  6338. else
  6339. {
  6340. tempIndex = gun_index;
  6341. }
  6342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6343. {
  6344. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6345. {
  6346. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6347. }
  6348. } // END OF FOR CHAdeMO_QUANTITY
  6349. }
  6350. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6351. {
  6352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6353. {
  6354. tempIndex = ((gun_index==2) ? 1: 0);
  6355. }
  6356. else
  6357. {
  6358. tempIndex = gun_index;
  6359. }
  6360. for (int index = 0; index < CCS_QUANTITY; index++)
  6361. {
  6362. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6363. {
  6364. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6365. }
  6366. } // END OF CCS_QUANTITY
  6367. }
  6368. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6369. {
  6370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6371. {
  6372. tempIndex = ((gun_index==2) ? 1: 0);
  6373. }
  6374. else
  6375. {
  6376. tempIndex = gun_index;
  6377. }
  6378. for (int index = 0; index < GB_QUANTITY; index++)
  6379. {
  6380. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6381. {
  6382. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6383. }
  6384. } // END OF GB_QUANTITY
  6385. }
  6386. else if(gunType[gun_index] == GUN_TYPE_DO)
  6387. {
  6388. tempIndex = gun_index;
  6389. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6390. {
  6391. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6392. {
  6393. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6394. }
  6395. }
  6396. }
  6397. else
  6398. {
  6399. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6400. {
  6401. tempIndex = 2;
  6402. }
  6403. else
  6404. {
  6405. tempIndex = gun_index;
  6406. }
  6407. for (int index = 0; index < AC_QUANTITY; index++)
  6408. {
  6409. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6410. {
  6411. uint16_t currentOffer;
  6412. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6413. {
  6414. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6415. }
  6416. else
  6417. {
  6418. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6419. }
  6420. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6421. }
  6422. }
  6423. }
  6424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6429. }
  6430. //***********************************************(12)Power.Offered******************************************************/
  6431. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6432. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6433. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6434. {
  6435. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6436. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6437. {
  6438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6439. {
  6440. tempIndex = ((gun_index==2) ? 1: 0);
  6441. }
  6442. else
  6443. {
  6444. tempIndex = gun_index;
  6445. }
  6446. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6447. {
  6448. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6449. {
  6450. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6451. }
  6452. } // END OF FOR CHAdeMO_QUANTITY
  6453. }
  6454. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6455. {
  6456. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6457. {
  6458. tempIndex = ((gun_index==2) ? 1: 0);
  6459. }
  6460. else
  6461. {
  6462. tempIndex = gun_index;
  6463. }
  6464. for (int index = 0; index < CCS_QUANTITY; index++)
  6465. {
  6466. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6467. {
  6468. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6469. }
  6470. } // END OF CCS_QUANTITY
  6471. }
  6472. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6473. {
  6474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6475. {
  6476. tempIndex = ((gun_index==2) ? 1: 0);
  6477. }
  6478. else
  6479. {
  6480. tempIndex = gun_index;
  6481. }
  6482. for (int index = 0; index < GB_QUANTITY; index++)
  6483. {
  6484. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6485. {
  6486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6487. }
  6488. } // END OF GB_QUANTITY
  6489. }
  6490. else if(gunType[gun_index] == GUN_TYPE_DO)
  6491. {
  6492. tempIndex = gun_index;
  6493. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6494. {
  6495. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6496. {
  6497. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6498. }
  6499. }
  6500. }
  6501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6506. }
  6507. // Message create ====================================================================================================
  6508. if(TRUE)
  6509. {
  6510. json_object *MeterValueReq = json_object_new_object();
  6511. json_object *MeterValues = json_object_new_array();
  6512. json_object *sampledValues = json_object_new_array();
  6513. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6514. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6515. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6516. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6517. {
  6518. json_object *MeterValue = json_object_new_object();
  6519. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6520. {
  6521. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6522. {
  6523. json_object *sampledValue = json_object_new_object();
  6524. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6525. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6526. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6527. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6528. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6529. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6530. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6531. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6532. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6533. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6534. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6535. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6536. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6537. json_object_array_add(sampledValues, sampledValue);
  6538. }
  6539. }
  6540. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6541. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6542. json_object_array_add(MeterValues, MeterValue);
  6543. }
  6544. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6545. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6546. ,gun_index + 1
  6547. ,MESSAGE_TYPE_CALL
  6548. ,guid
  6549. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6550. json_object_put(MeterValueReq);
  6551. }
  6552. // Put request guid to hash map
  6553. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6554. 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*/)
  6555. {
  6556. result = PASS;
  6557. //DEBUG_INFO("MeterValues mapitem pass\n");
  6558. }
  6559. if((dataType != ReadingContext_Trigger) &&
  6560. (dataType != ReadingContext_Sample_Clock) &&
  6561. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6562. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6563. else
  6564. {
  6565. if(FirstHeartBeat)
  6566. LWS_Send(queuedata +2);
  6567. }
  6568. return result;
  6569. }
  6570. int sendLogStatusNotificationRequest(char *status)
  6571. {
  6572. mtrace();
  6573. int result = PASS;
  6574. char message[4096]={0};
  6575. char guid[37]={0};
  6576. char tempdata[128]={0};
  6577. json_object *LogStatusNotification = json_object_new_object();
  6578. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6579. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6580. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6581. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6582. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6583. random_uuid(guid);
  6584. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6585. json_object_put(LogStatusNotification);
  6586. LWS_Send(message);
  6587. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6588. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6589. {
  6590. result = PASS;
  6591. }
  6592. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6593. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6594. return result;
  6595. }
  6596. int sendSecurityEventNotificationRequest()
  6597. {
  6598. mtrace();
  6599. int result = PASS;
  6600. char message[4096]={0};
  6601. char guid[37]={0};
  6602. char tempdata[128]={0};
  6603. json_object *SecurityEventNotification = json_object_new_object();
  6604. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6605. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6606. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6607. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6608. random_uuid(guid);
  6609. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6610. json_object_put(SecurityEventNotification);
  6611. LWS_Send(message);
  6612. sprintf(tempdata, "SecurityEventNotification,0");
  6613. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6614. {
  6615. result = PASS;
  6616. }
  6617. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6618. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6619. return result;
  6620. }
  6621. int sendSignCertificateRequest()
  6622. {
  6623. mtrace();
  6624. int result = PASS;
  6625. char message[4096]={0};
  6626. char guid[37]={0};
  6627. char tempdata[128]={0};
  6628. json_object *SignCertificate = json_object_new_object();
  6629. DEBUG_INFO("sendSignCertificateRequest...\n");
  6630. // Read csr file content
  6631. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6632. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6633. char *line = NULL;
  6634. size_t len = 0;
  6635. while(getline(&line, &len, fp) != -1)
  6636. {
  6637. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6638. {
  6639. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6640. }
  6641. }
  6642. fclose(fp);
  6643. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6644. random_uuid(guid);
  6645. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6646. json_object_put(SignCertificate);
  6647. LWS_Send(message);
  6648. sprintf(tempdata, "SignCertificate,0");
  6649. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6650. {
  6651. result = PASS;
  6652. }
  6653. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6654. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6655. return result;
  6656. }
  6657. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6658. {
  6659. mtrace();
  6660. int result = PASS;
  6661. char message[110]={0};
  6662. char guid[37]={0};
  6663. char tempdata[65]={0};
  6664. json_object *FirmwareStatusNotification = json_object_new_object();
  6665. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6666. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6667. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6668. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6669. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6670. random_uuid(guid);
  6671. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6672. json_object_put(FirmwareStatusNotification);
  6673. LWS_Send(message);
  6674. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6675. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6676. {
  6677. result = PASS;
  6678. }
  6679. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6680. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6681. return result;
  6682. }
  6683. //==========================================
  6684. // send confirm routine
  6685. //==========================================
  6686. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6687. {
  6688. mtrace();
  6689. int result = FAIL;
  6690. char message[100]={0};
  6691. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6692. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6693. LWS_Send(message);
  6694. result = TRUE;
  6695. return result;
  6696. }
  6697. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6698. {
  6699. mtrace();
  6700. int result = FAIL;
  6701. char message[100]={0};
  6702. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6703. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6704. LWS_Send(message);
  6705. result = TRUE;
  6706. return result;
  6707. }
  6708. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6709. {
  6710. mtrace();
  6711. int result = FAIL;
  6712. char message[100]={0};
  6713. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6714. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6715. LWS_Send(message);
  6716. result = TRUE;
  6717. return result;
  6718. }
  6719. int sendClearCacheConfirmation(char *uuid,char *payload)
  6720. {
  6721. mtrace();
  6722. int result = FAIL;
  6723. char message[500]={0};
  6724. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6725. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6726. LWS_Send(message);
  6727. return result;
  6728. }
  6729. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6730. {
  6731. mtrace();
  6732. int result = FAIL;
  6733. char message[500]={0};
  6734. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6735. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6736. LWS_Send(message);
  6737. return result;
  6738. }
  6739. int sendDataTransferConfirmation(char *uuid,char *payload)
  6740. {
  6741. mtrace();
  6742. char statusStr[20]={0};
  6743. char dataStr[10]={0};
  6744. char sstr[20]={0};
  6745. int c = 0;
  6746. char *loc;
  6747. int result = FAIL;
  6748. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6749. /**********************status**************************/
  6750. loc = strstr(payload, "status");
  6751. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6752. c = 0;
  6753. while (loc[3+strlen("status")+c] != '\"')
  6754. {
  6755. sstr[c] = loc[3+strlen("status")+c];
  6756. c++;
  6757. }
  6758. sstr[c] = '\0';
  6759. strcpy(statusStr, sstr);
  6760. /**********************data**************************/
  6761. loc = strstr(payload, "data");
  6762. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6763. c = 0;
  6764. while (loc[3+strlen("data")+c] != '\"')
  6765. {
  6766. sstr[c] = loc[3+strlen("data")+c];
  6767. c++;
  6768. }
  6769. sstr[c] = '\0';
  6770. strcpy(dataStr, sstr);
  6771. return result;
  6772. }
  6773. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6774. {
  6775. mtrace();
  6776. int result = FAIL;
  6777. char message[1000]={0};
  6778. int CompositeScheduleIndex = 0;
  6779. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6780. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6781. if(nPeriod == 0)
  6782. {
  6783. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6784. {
  6785. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6786. ,MESSAGE_TYPE_CALLRESULT
  6787. ,uuid
  6788. ,payload
  6789. ,connectorIdInt);
  6790. }
  6791. else
  6792. {
  6793. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6794. ,MESSAGE_TYPE_CALLRESULT
  6795. ,uuid
  6796. ,payload
  6797. ,connectorIdInt
  6798. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6799. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6800. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6801. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6802. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6803. }
  6804. }
  6805. else
  6806. {
  6807. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6808. ,MESSAGE_TYPE_CALLRESULT
  6809. ,uuid
  6810. ,payload
  6811. ,connectorIdInt
  6812. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6813. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6814. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6815. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6816. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6817. {
  6818. if (idx_sample == 0)
  6819. {
  6820. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6821. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6822. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6823. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6824. }
  6825. else
  6826. {
  6827. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6828. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6829. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6830. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6831. }
  6832. }
  6833. sprintf(message + strlen(message), "]}}]");
  6834. }
  6835. LWS_Send(message);
  6836. result = TRUE;
  6837. return result;
  6838. }
  6839. int sendGetConfigurationConfirmation(char *uuid)
  6840. {
  6841. mtrace();
  6842. int result = FAIL;
  6843. int MaxKeySupported = 0;
  6844. int sentConfigurationNumber= 0;
  6845. int sentunConfigurationNumber= 0;
  6846. char message[1024*10]={0};
  6847. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6848. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6849. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6850. ,MESSAGE_TYPE_CALLRESULT
  6851. ,uuid );
  6852. //configuration key
  6853. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6854. {
  6855. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6856. {
  6857. if (sentConfigurationNumber == 0)
  6858. {
  6859. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6860. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6861. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6862. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6863. }
  6864. else
  6865. {
  6866. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6867. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6868. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6869. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6870. }
  6871. sentConfigurationNumber = sentConfigurationNumber + 1;
  6872. }
  6873. }
  6874. sprintf(message + strlen(message), "]");
  6875. if(UnknownKeynum != 0)
  6876. {
  6877. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6878. //unkown key
  6879. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6880. {
  6881. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6882. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6883. if(sentunConfigurationNumber == 0)
  6884. {
  6885. sprintf(message + strlen(message), "\"%s\""
  6886. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6887. }
  6888. else
  6889. {
  6890. sprintf(message + strlen(message), ",\"%s\""
  6891. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6892. }
  6893. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6894. }
  6895. sprintf(message + strlen(message), "]");
  6896. }
  6897. sprintf(message + strlen(message), "}]");
  6898. LWS_Send(message);
  6899. return result;
  6900. }
  6901. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6902. {
  6903. mtrace();
  6904. int result = FAIL;
  6905. char message[400]={0};
  6906. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6907. if(strcmp(payload,"")==0)
  6908. {
  6909. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6910. }
  6911. else
  6912. {
  6913. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6914. }
  6915. LWS_Send(message);
  6916. result = TRUE;
  6917. return result;
  6918. }
  6919. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6920. {
  6921. mtrace();
  6922. int result = FAIL;
  6923. char message[80]={0};
  6924. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6925. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6926. LWS_Send(message);
  6927. result = TRUE;
  6928. return result;
  6929. }
  6930. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6931. {
  6932. mtrace();
  6933. int result = FAIL;
  6934. char message[80]={0};
  6935. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6936. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6937. LWS_Send(message);
  6938. result = TRUE;
  6939. return result;
  6940. }
  6941. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6942. {
  6943. mtrace();
  6944. int result = FAIL;
  6945. char message[80]={0};
  6946. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6947. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6948. LWS_Send(message);
  6949. result = TRUE;
  6950. return result;
  6951. }
  6952. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6953. {
  6954. mtrace();
  6955. int result = FAIL;
  6956. char message[80]={0};
  6957. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6958. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6959. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6960. LWS_Send(message);
  6961. result = TRUE;
  6962. return result;
  6963. }
  6964. int sendResetConfirmation(char *uuid,char *payload)
  6965. {
  6966. mtrace();
  6967. int result = FAIL;
  6968. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6969. char message[80]={0};
  6970. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6971. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6972. LWS_Send(message);
  6973. result = TRUE;
  6974. return result;
  6975. }
  6976. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6977. {
  6978. mtrace();
  6979. int result = FAIL;
  6980. char message[500]={0};
  6981. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6982. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6983. LWS_Send(message);
  6984. result = TRUE;
  6985. return result;
  6986. }
  6987. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6988. {
  6989. mtrace();
  6990. int result = FAIL;
  6991. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6992. char message[80]={0};
  6993. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6994. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6995. LWS_Send(message);
  6996. result = TRUE;
  6997. return result;
  6998. }
  6999. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7000. {
  7001. mtrace();
  7002. int result = FAIL;
  7003. char message[80]={0};
  7004. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7005. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7006. LWS_Send(message);
  7007. result = TRUE;
  7008. return result;
  7009. }
  7010. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7011. {
  7012. mtrace();
  7013. int result = FAIL;
  7014. char message[80]={0};
  7015. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7016. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7017. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7018. LWS_Send(message);
  7019. result = TRUE;
  7020. return result;
  7021. }
  7022. int sendUpdateFirmwareConfirmation(char *uuid)
  7023. {
  7024. mtrace();
  7025. int result = FAIL;
  7026. char message[60]={0};
  7027. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7028. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7029. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7030. LWS_Send(message);
  7031. result = TRUE;
  7032. return result;
  7033. }
  7034. int sendCertificateSignedConfirmation(char *uuid)
  7035. {
  7036. mtrace();
  7037. int result = PASS;
  7038. char message[4096]={0};
  7039. json_object *CertificateSigned = json_object_new_object();
  7040. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7041. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7042. sprintf(message,"[%d,\"%s\",%s]"
  7043. ,MESSAGE_TYPE_CALLRESULT
  7044. ,uuid
  7045. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7046. json_object_put(CertificateSigned);
  7047. LWS_Send(message);
  7048. return result;
  7049. }
  7050. int sendDeleteCertificateConfirmation(char *uuid)
  7051. {
  7052. mtrace();
  7053. int result = PASS;
  7054. char message[4096]={0};
  7055. json_object *DeleteCertificate = json_object_new_object();
  7056. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7057. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7058. sprintf(message,"[%d,\"%s\",%s]"
  7059. ,MESSAGE_TYPE_CALLRESULT
  7060. ,uuid
  7061. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7062. json_object_put(DeleteCertificate);
  7063. LWS_Send(message);
  7064. return result;
  7065. }
  7066. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7067. {
  7068. mtrace();
  7069. int result = PASS;
  7070. char message[4096]={0};
  7071. json_object *ExtendedTriggerMessage = json_object_new_object();
  7072. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7073. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7074. sprintf(message,"[%d,\"%s\",%s]"
  7075. ,MESSAGE_TYPE_CALLRESULT
  7076. ,uuid
  7077. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7078. json_object_put(ExtendedTriggerMessage);
  7079. LWS_Send(message);
  7080. return result;
  7081. }
  7082. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7083. {
  7084. mtrace();
  7085. int result = PASS;
  7086. char message[4096]={0};
  7087. json_object *GetInstalledCertificateIds = json_object_new_object();
  7088. json_object *certificateHashDataDatas = json_object_new_array();
  7089. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7090. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7091. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7092. {
  7093. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7094. {
  7095. json_object *certificateHashData = json_object_new_object();
  7096. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7097. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7098. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7099. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7100. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7101. }
  7102. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7103. }
  7104. else
  7105. {
  7106. json_object_put(certificateHashDataDatas);
  7107. }
  7108. sprintf(message,"[%d,\"%s\",%s]"
  7109. ,MESSAGE_TYPE_CALLRESULT
  7110. ,uuid
  7111. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7112. json_object_put(GetInstalledCertificateIds);
  7113. LWS_Send(message);
  7114. return result;
  7115. }
  7116. int sendGetLogConfirmation(char *uuid)
  7117. {
  7118. mtrace();
  7119. int result = PASS;
  7120. char message[4096]={0};
  7121. json_object *GetLog = json_object_new_object();
  7122. DEBUG_INFO("sendGetLogConfirmation...\n");
  7123. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7124. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7125. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7126. sprintf(message,"[%d,\"%s\",%s]"
  7127. ,MESSAGE_TYPE_CALLRESULT
  7128. ,uuid
  7129. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7130. json_object_put(GetLog);
  7131. LWS_Send(message);
  7132. return result;
  7133. }
  7134. int sendInstallCertificateConfirmation(char *uuid)
  7135. {
  7136. mtrace();
  7137. int result = PASS;
  7138. char message[4096]={0};
  7139. json_object *InstallCertificate = json_object_new_object();
  7140. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7141. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7142. sprintf(message,"[%d,\"%s\",%s]"
  7143. ,MESSAGE_TYPE_CALLRESULT
  7144. ,uuid
  7145. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7146. json_object_put(InstallCertificate);
  7147. LWS_Send(message);
  7148. return result;
  7149. }
  7150. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7151. {
  7152. mtrace();
  7153. int result = PASS;
  7154. char message[4096]={0};
  7155. json_object *SignedUpdateFirmware = json_object_new_object();
  7156. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7157. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7158. sprintf(message,"[%d,\"%s\",%s]"
  7159. ,MESSAGE_TYPE_CALLRESULT
  7160. ,uuid
  7161. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7162. json_object_put(SignedUpdateFirmware);
  7163. LWS_Send(message);
  7164. return result;
  7165. }
  7166. int sendUnknownConfirmation(char *uuid)
  7167. {
  7168. mtrace();
  7169. int result = PASS;
  7170. char message[256]={0};
  7171. DEBUG_INFO("sendUnknownConfirmation...\n");
  7172. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7173. LWS_Send(message);
  7174. return result;
  7175. }
  7176. //==========================================
  7177. // Handle server request routine Start
  7178. //==========================================
  7179. int handleCancelReservationRequest(char *uuid, char *payload)
  7180. {
  7181. mtrace();
  7182. int result = FAIL;
  7183. int gunNO = 0;
  7184. int reservationIdInt = -1;
  7185. char comfirmstr[20];
  7186. DEBUG_INFO("handleCancelReservationRequest...\n");
  7187. json_object *CancelReservation;
  7188. CancelReservation = json_tokener_parse(payload);
  7189. if(!is_error(CancelReservation))
  7190. {
  7191. // Required data
  7192. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7193. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7194. }
  7195. json_object_put(CancelReservation);
  7196. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7197. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7198. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7199. if(reservationIdInt != -1)
  7200. {
  7201. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7202. //check Transaction active
  7203. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7204. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7205. {
  7206. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7207. {
  7208. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7209. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7210. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7211. {
  7212. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7213. }
  7214. else
  7215. {
  7216. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7217. }
  7218. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7219. goto end;
  7220. }
  7221. }
  7222. for (int index = 0; index < CCS_QUANTITY; index++)
  7223. {
  7224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7225. {
  7226. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7227. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7228. if(gunType[2] == GUN_TYPE_CCS)
  7229. {
  7230. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7231. }
  7232. else
  7233. {
  7234. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7235. }
  7236. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7237. goto end;
  7238. }
  7239. }
  7240. for (int index = 0; index < GB_QUANTITY; index++)
  7241. {
  7242. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7243. {
  7244. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7245. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7246. if(gunType[2] == GUN_TYPE_GBT)
  7247. {
  7248. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7249. }
  7250. else
  7251. {
  7252. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7253. }
  7254. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7255. goto end;
  7256. }
  7257. }
  7258. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7261. {
  7262. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7263. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7264. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7265. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7266. goto end;
  7267. }
  7268. }
  7269. for (int index = 0; index < AC_QUANTITY; index++)
  7270. {
  7271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7272. {
  7273. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7274. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7275. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7276. {
  7277. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7278. }
  7279. else
  7280. {
  7281. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7282. }
  7283. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7284. goto end;
  7285. }
  7286. }
  7287. }
  7288. //The reservationId does NOT match the reservationId
  7289. sendCancelReservationConfirmation(uuid, comfirmstr);
  7290. end:
  7291. // Fill in ocpp packet uuid
  7292. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7293. return result;
  7294. }
  7295. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7296. {
  7297. mtrace();
  7298. int result = FAIL;
  7299. int gunIndex = 0;
  7300. char typeStr[16]={0};
  7301. char comfirmstr[20];
  7302. int specificId = FALSE;
  7303. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7304. json_object *ChangeAvailability;
  7305. ChangeAvailability = json_tokener_parse(payload);
  7306. if(!is_error(ChangeAvailability))
  7307. {
  7308. // Required data
  7309. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7310. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7311. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7312. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7313. }
  7314. json_object_put(ChangeAvailability);
  7315. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7316. {
  7317. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7318. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7319. }
  7320. else if(gunIndex == 0)
  7321. {
  7322. for(int i=0; i < gunTotalNumber; i++)
  7323. {
  7324. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7325. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7326. }
  7327. }
  7328. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7329. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7330. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7331. {
  7332. specificId = TRUE;
  7333. }
  7334. if(specificId == FALSE)
  7335. goto end;
  7336. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7337. {
  7338. //----------------------gunIndex is 0 ------------------------------------------------//
  7339. if(gunIndex == 0)
  7340. {
  7341. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7342. {
  7343. for(int i=0; i < gunTotalNumber; i++)
  7344. {
  7345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7346. {
  7347. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7348. {
  7349. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7350. {
  7351. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7352. goto end;
  7353. }
  7354. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7355. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7356. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7357. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7358. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7359. {
  7360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7361. goto end;
  7362. }
  7363. }
  7364. }//END FOR CHAdeMO_QUANTITY
  7365. for (int index = 0; index < CCS_QUANTITY; index++)
  7366. {
  7367. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7368. {
  7369. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7370. {
  7371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7372. goto end;
  7373. }
  7374. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7375. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7376. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7377. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7378. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7379. {
  7380. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7381. goto end;
  7382. }
  7383. }
  7384. }//END FOR CCS_QUANTITY
  7385. for (int index = 0; index < GB_QUANTITY; index++)
  7386. {
  7387. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7388. {
  7389. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7390. {
  7391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7392. goto end;
  7393. }
  7394. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7395. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7396. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7397. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7398. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7399. {
  7400. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7401. goto end;
  7402. }
  7403. }
  7404. }// END FOR GB_QUANTITY
  7405. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7406. {
  7407. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7408. {
  7409. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7410. {
  7411. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7412. goto end;
  7413. }
  7414. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7415. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7416. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7417. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7418. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7419. {
  7420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7421. goto end;
  7422. }
  7423. }
  7424. }// END FOR GENERAL_GUN_QUANTITY
  7425. for (int index = 0; index < AC_QUANTITY; index++)
  7426. {
  7427. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7428. {
  7429. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7430. {
  7431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7432. goto end;
  7433. }
  7434. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7435. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7436. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7437. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7438. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7439. {
  7440. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7441. goto end;
  7442. }
  7443. }
  7444. }//END FOR AC_QUANTITY
  7445. }// END FOR gunTotalNumber
  7446. }
  7447. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7448. {
  7449. for(int i=0; i < gunTotalNumber; i++)
  7450. {
  7451. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7452. {
  7453. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7454. goto end;
  7455. }
  7456. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7457. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7458. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7459. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7460. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7461. {
  7462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7463. goto end;
  7464. }
  7465. }
  7466. }
  7467. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7468. goto end;
  7469. }
  7470. //----------------------gunIndex is not 0 ------------------------------------------------//
  7471. //check Transaction active
  7472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7473. {
  7474. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7475. {
  7476. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7477. {
  7478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7479. goto end;
  7480. }
  7481. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7482. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7483. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7484. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7485. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7486. {
  7487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7488. goto end;
  7489. }
  7490. else
  7491. {
  7492. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7494. goto end;
  7495. }
  7496. }
  7497. }//END FOR CHAdeMO_QUANTITY
  7498. for (int index = 0; index < CCS_QUANTITY; index++)
  7499. {
  7500. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7501. {
  7502. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7503. {
  7504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7505. goto end;
  7506. }
  7507. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7508. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7509. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7510. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7511. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7512. {
  7513. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7514. goto end;
  7515. }
  7516. else
  7517. {
  7518. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7519. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7520. goto end;
  7521. }
  7522. }
  7523. }//END FOR CCS_QUANTITY
  7524. for (int index = 0; index < GB_QUANTITY; index++)
  7525. {
  7526. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7527. {
  7528. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7529. {
  7530. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7531. goto end;
  7532. }
  7533. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7534. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7535. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7536. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7537. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7538. {
  7539. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7540. goto end;
  7541. }
  7542. else
  7543. {
  7544. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7545. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7546. goto end;
  7547. }
  7548. }
  7549. }// END FOR GB_QUANTITY
  7550. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7551. {
  7552. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7553. {
  7554. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7555. {
  7556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7557. goto end;
  7558. }
  7559. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7560. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7561. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7562. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7563. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7564. {
  7565. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7566. goto end;
  7567. }
  7568. else
  7569. {
  7570. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7571. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7572. goto end;
  7573. }
  7574. }
  7575. }// END FOR GENERAL_GUN_QUANTITY
  7576. for (int index = 0; index < AC_QUANTITY; index++)
  7577. {
  7578. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7579. {
  7580. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7581. {
  7582. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7583. goto end;
  7584. }
  7585. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7586. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7587. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7588. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7589. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7590. {
  7591. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7592. goto end;
  7593. }
  7594. else
  7595. {
  7596. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7597. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7598. goto end;
  7599. }
  7600. }
  7601. }//END FOR AC_QUANTITY
  7602. }//END FOR AvailabilityTypeStr[Inoperative]
  7603. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7604. {
  7605. //----------------------gunIndex is 0 ------------------------------------------------//
  7606. if(gunIndex == 0)
  7607. {
  7608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7609. {
  7610. for(int i=0; i < gunTotalNumber; i++)
  7611. {
  7612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7613. {
  7614. 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
  7615. {
  7616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7617. goto end;
  7618. }
  7619. }//END FOR CHAdeMO_QUANTITY
  7620. for (int index = 0; index < CCS_QUANTITY; index++)
  7621. {
  7622. 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
  7623. {
  7624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7625. goto end;
  7626. }
  7627. }//END FOR CCS_QUANTITY
  7628. for (int index = 0; index < GB_QUANTITY; index++)
  7629. {
  7630. 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
  7631. {
  7632. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7633. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7634. goto end;
  7635. }
  7636. }// END FOR GB_QUANTITY
  7637. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7638. {
  7639. 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
  7640. {
  7641. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7643. goto end;
  7644. }
  7645. }// END FOR GENERAL_GUN_QUANTITY
  7646. for (int index = 0; index < AC_QUANTITY; index++)
  7647. {
  7648. 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
  7649. {
  7650. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7651. goto end;
  7652. }
  7653. }//END FOR CHAdeMO_QUANTITY
  7654. }// END FOR gunTotalNumber
  7655. }
  7656. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7657. {
  7658. for(int i=0; i < gunTotalNumber; i++)
  7659. {
  7660. for (int index = 0; index < AC_QUANTITY; index++)
  7661. {
  7662. 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
  7663. {
  7664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7665. goto end;
  7666. }
  7667. }//END FOR CHAdeMO_QUANTITY
  7668. } // END FOR gunTotalNumber
  7669. }
  7670. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7671. goto end;
  7672. }
  7673. //----------------------gunIndex is not 0 ------------------------------------------------//
  7674. //check Transaction active
  7675. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7676. {
  7677. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7678. {
  7679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7680. goto end;
  7681. }
  7682. }//END FOR CHAdeMO_QUANTITY
  7683. for (int index = 0; index < CCS_QUANTITY; index++)
  7684. {
  7685. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7686. {
  7687. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7688. goto end;
  7689. }
  7690. }//END FOR CCS_QUANTITY
  7691. for (int index = 0; index < GB_QUANTITY; index++)
  7692. {
  7693. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7694. {
  7695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7696. goto end;
  7697. }
  7698. }// END FOR GB_QUANTITY
  7699. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7700. {
  7701. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7702. {
  7703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7704. goto end;
  7705. }
  7706. }// END FOR GENERAL_GUN_QUANTITY
  7707. for (int index = 0; index < AC_QUANTITY; index++)
  7708. {
  7709. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7710. {
  7711. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7712. goto end;
  7713. }
  7714. }//END FOR AC_QUANTITY
  7715. }//END FOR AvailabilityTypeStr[Operative]
  7716. end:
  7717. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7718. {
  7719. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7720. }
  7721. else
  7722. {
  7723. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7724. }
  7725. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7726. {
  7727. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7728. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7729. }
  7730. else if(gunIndex == 0)
  7731. {
  7732. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7733. {
  7734. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7735. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7736. }
  7737. }
  7738. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7739. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7740. return result;
  7741. }
  7742. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7743. {
  7744. mtrace();
  7745. int result = FAIL;
  7746. char keystr[40]={0};
  7747. char valuestr[256]={0};
  7748. char comfirmstr[20]={0};
  7749. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7750. json_object *ChangeConfiguration;
  7751. ChangeConfiguration = json_tokener_parse(payload);
  7752. if(!is_error(ChangeConfiguration))
  7753. {
  7754. // Required data
  7755. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7756. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7757. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7758. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7759. }
  7760. json_object_put(ChangeConfiguration);
  7761. if((uuid==NULL) || (payload ==NULL) )
  7762. {
  7763. DEBUG_ERROR("Payload is null\n");
  7764. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7765. }
  7766. else
  7767. {
  7768. int status = setKeyValue(keystr, valuestr);
  7769. switch(status)
  7770. {
  7771. case ConfigurationStatus_Accepted:
  7772. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7773. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7774. StoreConfigurationTable();
  7775. break;
  7776. case RebootRequired:
  7777. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7778. StoreConfigurationTable();
  7779. break;
  7780. case NotSupported:
  7781. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7782. break;
  7783. case ConfigurationStatus_Rejected:
  7784. default:
  7785. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7786. break;
  7787. }
  7788. }
  7789. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7790. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7791. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7792. {
  7793. ChageWebSocketPingInterval(atoi(valuestr));
  7794. }
  7795. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7796. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7797. {
  7798. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7799. SetOcppConnStatus(FALSE);
  7800. }
  7801. return result;
  7802. }
  7803. int handleClearCacheRequest(char *uuid, char *payload)
  7804. {
  7805. mtrace();
  7806. int result = FAIL;
  7807. char comfirmstr[20];
  7808. char rmFileCmd[100]={0};
  7809. struct stat stats;
  7810. DEBUG_INFO("handleClearCacheRequest...\n");
  7811. stat("/Storage/OCPP", &stats);
  7812. // Check for directory existence
  7813. if (S_ISDIR(stats.st_mode) == 1)
  7814. {}
  7815. else
  7816. {
  7817. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7818. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7819. system(rmFileCmd);
  7820. }
  7821. if(OCPP_cleanLocalCache())
  7822. {
  7823. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7824. }
  7825. else
  7826. {
  7827. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7828. }
  7829. sendClearCacheConfirmation(uuid, comfirmstr);
  7830. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7831. return result;
  7832. }
  7833. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7834. {
  7835. mtrace();
  7836. int result = FAIL;
  7837. int resultRename;
  7838. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7839. char chargingProfilePurposeStr[26]={0};
  7840. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7841. char tempchargingProfilePurposeStr[26]={0};
  7842. char str[100]={0};
  7843. char fname[200]={0};
  7844. char comfirmstr[20]={0};
  7845. char word[1600]={0};
  7846. int clearflag = FALSE;
  7847. int chargingProfileIdIsNULL = FALSE;
  7848. int connectorIsNULL = FALSE;
  7849. int chargingProfilePurposeIsNULL = FALSE;
  7850. int stackLevelIsNULL = FALSE;
  7851. //int GotoEnd = FALSE;
  7852. FILE *fptr1, *fptr2;
  7853. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7854. int n_chargingProfile=0;
  7855. int isEmptyFile = FALSE;
  7856. char sLineWord[1600]={0};
  7857. char chargingProfiles[10][100]={0};
  7858. int ChargeProfileCount = 0;
  7859. int ch;
  7860. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7861. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7862. json_object *ClearChargingProfile;
  7863. ClearChargingProfile = json_tokener_parse(payload);
  7864. if(!is_error(ClearChargingProfile))
  7865. {
  7866. // Optional data
  7867. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7868. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7869. else
  7870. chargingProfileIdIsNULL = TRUE;
  7871. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7872. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7873. else
  7874. connectorIsNULL = TRUE;
  7875. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7876. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7877. else
  7878. chargingProfilePurposeIsNULL = TRUE;
  7879. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7880. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7881. else
  7882. stackLevelIsNULL = TRUE;
  7883. }
  7884. json_object_put(ClearChargingProfile);
  7885. if(connectorIsNULL == FALSE)
  7886. {
  7887. switch(connectorIdInt)
  7888. {
  7889. case 0:
  7890. if(chargingProfilePurposeIsNULL == TRUE)
  7891. {
  7892. int l = 0;
  7893. strcpy(fname, ChargePointMaxProfile_JSON);
  7894. if((access(fname,F_OK))!=-1)
  7895. {
  7896. strcpy(chargingProfiles[l], fname);
  7897. l = l + 1;
  7898. }
  7899. strcpy(fname, TxDefaultProfile_0_JSON);
  7900. if((access(fname,F_OK))!=-1)
  7901. {
  7902. strcpy(chargingProfiles[l], fname);
  7903. l = l + 1;
  7904. }
  7905. ChargeProfileCount = l;
  7906. }
  7907. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7908. {
  7909. strcpy(fname, ChargePointMaxProfile_JSON);
  7910. if((access(fname,F_OK))!=-1)
  7911. {
  7912. strcpy(chargingProfiles[0], fname);
  7913. ChargeProfileCount = 1;
  7914. }
  7915. }
  7916. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7917. {
  7918. strcpy(fname, TxDefaultProfile_0_JSON);
  7919. if((access(fname,F_OK))!=-1)
  7920. {
  7921. strcpy(chargingProfiles[0], fname);
  7922. ChargeProfileCount = 1;
  7923. }
  7924. }
  7925. break;
  7926. default:
  7927. if(chargingProfilePurposeIsNULL == TRUE)
  7928. {
  7929. int m = 0;
  7930. memset(fname, 0, ARRAY_SIZE(fname));
  7931. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7932. if((access(fname,F_OK))!=-1)
  7933. {
  7934. strcpy(chargingProfiles[m], fname);
  7935. m = m + 1;
  7936. }
  7937. memset(fname, 0, ARRAY_SIZE(fname));
  7938. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7939. if((access(fname,F_OK))!=-1)
  7940. {
  7941. strcpy(chargingProfiles[m], fname);
  7942. m = m + 1;
  7943. }
  7944. ChargeProfileCount = m;
  7945. }
  7946. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7947. {
  7948. //strcpy(fname, TxDefaultProfile_1_JSON);
  7949. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7950. if((access(fname,F_OK))!=-1)
  7951. {
  7952. strcpy(chargingProfiles[0], fname);
  7953. ChargeProfileCount = 1;
  7954. }
  7955. }
  7956. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7957. {
  7958. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7959. if((access(fname,F_OK))!=-1)
  7960. {
  7961. strcpy(chargingProfiles[0], fname);
  7962. ChargeProfileCount = 1;
  7963. }
  7964. //strcpy(fname, TxProfile_1_JSON);
  7965. }
  7966. //strcpy(fname, ChargePointMaxProfile_JSON );
  7967. break;
  7968. }
  7969. }
  7970. else // Check all Charging Profiles
  7971. {
  7972. int i = 0;
  7973. char fnametemp[200]={0};
  7974. ChargeProfileCount = 0;
  7975. //Check ChargePointMaxProfile.json exit
  7976. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7977. {
  7978. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7979. i = i + 1;
  7980. }
  7981. //Check TxDefaultProfile_0.json exit
  7982. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7983. {
  7984. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7985. i = i + 1;
  7986. }
  7987. //Check TxDefaultProfile_%d.json
  7988. for(int j=1; j <= gunTotalNumber; j++)
  7989. {
  7990. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7991. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7992. if((access(fnametemp,F_OK))!=-1)
  7993. {
  7994. strcpy(chargingProfiles[i], fnametemp);
  7995. i = i + 1;
  7996. }
  7997. }
  7998. //Check TxProfile_%d.json
  7999. for(int j=1; j <= gunTotalNumber; j++)
  8000. {
  8001. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8002. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8003. if((access(fnametemp,F_OK))!=-1)
  8004. {
  8005. strcpy(chargingProfiles[i], fnametemp);
  8006. i = i + 1;
  8007. }
  8008. }
  8009. ChargeProfileCount = i;
  8010. }// End connectorIsNULL is TRUE
  8011. if(ChargeProfileCount == 0)
  8012. {
  8013. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8014. goto end;
  8015. }
  8016. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8017. {
  8018. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8019. goto end;
  8020. }
  8021. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8022. {
  8023. memset(str, 0, ARRAY_SIZE(str));
  8024. // clear temp file
  8025. sprintf(str,"rm -f %s",temp);
  8026. system(str);
  8027. for(int k=0; k < ChargeProfileCount; k++)
  8028. {
  8029. memset(str, 0, ARRAY_SIZE(str));
  8030. //clear file in C
  8031. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8032. system(str);
  8033. }
  8034. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8035. goto end;
  8036. }
  8037. else if(connectorIsNULL == TRUE)
  8038. {
  8039. for(int k=0; k < ChargeProfileCount; k++)
  8040. {
  8041. fptr1 = fopen(chargingProfiles[k], "r");
  8042. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8043. //Check Charging Profile Count
  8044. while(fscanf(fptr1, "%s", word) != EOF)
  8045. {
  8046. //DEBUG_INFO("word=%s\n",word);
  8047. if(strstr(word, "chargingProfileId")!= NULL)
  8048. {
  8049. //DEBUG_INFO("test chargingProfileId \n");
  8050. n_chargingProfile = n_chargingProfile + 1;
  8051. //DEBUG_INFO("chargingProfileId Found\n");
  8052. }
  8053. }
  8054. rewind(fptr1);
  8055. //search Charging Profile Element
  8056. //int i= 0;
  8057. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8058. {
  8059. json_object *tmpProfilee;
  8060. tmpProfilee = json_tokener_parse(sLineWord);
  8061. if(!is_error(tmpProfilee))
  8062. {
  8063. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8064. {
  8065. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8066. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8067. }
  8068. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8069. {
  8070. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8071. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8072. }
  8073. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8074. {
  8075. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8076. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8077. }
  8078. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8079. {
  8080. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8081. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8082. }
  8083. }
  8084. json_object_put(tmpProfilee);
  8085. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8086. {
  8087. //------- not write to fptr2-------//
  8088. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8089. //clearflag = TRUE;
  8090. }
  8091. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8092. {
  8093. //------- not write to fptr2-------//
  8094. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8095. }
  8096. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8097. {
  8098. //------- not write to fptr2-------//
  8099. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8100. }
  8101. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8102. {
  8103. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8104. }
  8105. else
  8106. {
  8107. fprintf(fptr2, sLineWord);//writing data into file
  8108. }
  8109. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8110. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8111. if(clearflag == TRUE)
  8112. {
  8113. fclose(fptr1);
  8114. fclose(fptr2);
  8115. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8116. system(str);
  8117. // clear temp file
  8118. sprintf(str,"rm -f %s",temp);
  8119. system(str);
  8120. }
  8121. else
  8122. {
  8123. fclose(fptr1);
  8124. fclose(fptr2);
  8125. memset(str, 0, ARRAY_SIZE(str));
  8126. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8127. system(str);
  8128. resultRename = rename(temp, chargingProfiles[k]);
  8129. if(resultRename == 0)
  8130. {
  8131. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8132. }
  8133. else
  8134. {
  8135. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8136. }
  8137. if(comfirmstr[0]== 0)
  8138. {
  8139. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8140. }
  8141. //Check chargingProfile is empty file
  8142. /*------ Read the file ----------------*/
  8143. fptr1=fopen(chargingProfiles[k],"r");
  8144. ch=fgetc(fptr1);
  8145. rewind(fptr1);
  8146. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8147. if(ch!=EOF)
  8148. {
  8149. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8150. {
  8151. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8152. if(sLineWord[0]=='\0')
  8153. {
  8154. isEmptyFile = TRUE;
  8155. break;
  8156. }
  8157. else
  8158. {
  8159. isEmptyFile = FALSE;
  8160. break;
  8161. }
  8162. }
  8163. }
  8164. else
  8165. isEmptyFile = TRUE;
  8166. fclose(fptr1);
  8167. if(isEmptyFile == TRUE)
  8168. {
  8169. memset(str, 0, ARRAY_SIZE(str));
  8170. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8171. system(str);
  8172. }
  8173. }
  8174. }// End of while(int k=0; k < ChargePointCount; k++)
  8175. }
  8176. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8177. {
  8178. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8179. for(int k=0; k < ChargeProfileCount; k++)
  8180. {
  8181. fptr1 = fopen(chargingProfiles[k], "r");
  8182. fptr2 = fopen(temp, "w+");
  8183. //Check Charging Profile Count
  8184. while(fscanf(fptr1, "%s", word) != EOF)
  8185. {
  8186. //DEBUG_INFO("word=%s\n",word);
  8187. if(strstr(word, "chargingProfileId")!= NULL)
  8188. {
  8189. n_chargingProfile = n_chargingProfile + 1;
  8190. }
  8191. }
  8192. rewind(fptr1);
  8193. //search Charging Profile Element
  8194. //int i= 0;
  8195. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8196. {
  8197. json_object *tmpProfilee;
  8198. tmpProfilee = json_tokener_parse(sLineWord);
  8199. if(!is_error(tmpProfilee))
  8200. {
  8201. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8202. {
  8203. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8204. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8205. }
  8206. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8207. {
  8208. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8209. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8210. }
  8211. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8212. {
  8213. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8214. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8215. }
  8216. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8217. {
  8218. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8219. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8220. }
  8221. }
  8222. json_object_put(tmpProfilee);
  8223. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8224. {
  8225. //------- not write to fptr2-------//
  8226. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8227. //clearflag = TRUE;
  8228. }
  8229. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8230. {
  8231. //------- not write to fptr2-------//
  8232. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8233. }
  8234. else if(stackLevelIsNULL == TRUE)
  8235. {
  8236. //Clear Whole File
  8237. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8238. clearflag = TRUE;
  8239. break;
  8240. }
  8241. else
  8242. {
  8243. fprintf(fptr2, sLineWord);//writing data into file
  8244. }
  8245. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8246. }
  8247. if(clearflag == TRUE)
  8248. {
  8249. fclose(fptr1);
  8250. fclose(fptr2);
  8251. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8252. system(str);
  8253. // clear temp file
  8254. sprintf(str,"rm -f %s",temp);
  8255. system(str);
  8256. }
  8257. else
  8258. {
  8259. fclose(fptr1);
  8260. fclose(fptr2);
  8261. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8262. system(str);
  8263. resultRename = rename(temp, chargingProfiles[k]);
  8264. if(resultRename == 0)
  8265. {
  8266. DEBUG_INFO("File ChargingProfile renamed successfully");
  8267. }
  8268. else
  8269. {
  8270. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8271. }
  8272. if(comfirmstr[0]== 0)
  8273. {
  8274. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8275. }
  8276. //Check chargingProfile is empty file
  8277. /*------ Read the file ----------------*/
  8278. fptr1=fopen(chargingProfiles[k],"r");
  8279. ch=fgetc(fptr1);
  8280. rewind(fptr1);
  8281. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8282. if(ch!=EOF)
  8283. {
  8284. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8285. {
  8286. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8287. if(sLineWord[0]=='\0')
  8288. {
  8289. isEmptyFile = TRUE;
  8290. break;
  8291. }
  8292. else
  8293. {
  8294. isEmptyFile = FALSE;
  8295. break;
  8296. }
  8297. }
  8298. }
  8299. else
  8300. isEmptyFile = TRUE;
  8301. fclose(fptr1);
  8302. if(isEmptyFile == TRUE)
  8303. {
  8304. memset(str, 0, ARRAY_SIZE(str));
  8305. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8306. system(str);
  8307. }
  8308. /*------- End of reading ---------------*/
  8309. }
  8310. } // while(int k=0; k < ChargeProfileCount; k++)
  8311. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8312. end:
  8313. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8314. {
  8315. if(connectorIdInt == 0)
  8316. {
  8317. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8318. {
  8319. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8320. }
  8321. }
  8322. else
  8323. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8324. }
  8325. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8326. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8327. return result;
  8328. }
  8329. void createFirmwareVersionByDataTransfer(void)
  8330. {
  8331. json_object *FirmwareDataTransfer = json_object_new_object();
  8332. // AC & DC model
  8333. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8334. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8335. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8336. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8337. // DC model
  8338. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8339. {
  8340. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8341. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8342. (gunType[3] != GUN_TYPE_UNKNOWN))
  8343. {
  8344. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8345. }
  8346. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8347. {
  8348. // DS DM DW
  8349. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8350. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8351. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8352. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8353. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8354. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8355. }
  8356. else
  8357. {
  8358. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8359. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8360. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8361. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8362. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8363. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8364. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8365. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8366. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8367. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8368. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8369. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8370. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8371. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8372. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8373. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8374. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8375. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8376. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8377. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8378. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8379. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8380. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8381. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8382. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8383. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8384. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8385. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8386. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8387. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8388. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8389. }
  8390. }
  8391. // 4G model
  8392. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8393. {
  8394. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8395. }
  8396. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8397. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8398. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8399. json_object_put(FirmwareDataTransfer);
  8400. }
  8401. int handleDataTransferRequest(char *uuid, char *payload)
  8402. {
  8403. mtrace();
  8404. json_object *response = json_object_new_object();
  8405. int result = FAIL;
  8406. char tempvendorId[255]={0};
  8407. char tempmessageId[50]={0};
  8408. char tempdata[512]={0};
  8409. char message[2048]={0};
  8410. DEBUG_INFO("handleDataTransferRequest...\n");
  8411. if((uuid != NULL) && (payload != NULL))
  8412. {
  8413. json_object *DataTransfer;
  8414. DataTransfer = json_tokener_parse(payload);
  8415. if(!is_error(DataTransfer))
  8416. {
  8417. // Required data
  8418. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8419. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8420. // Optional data
  8421. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8422. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8423. if(json_object_object_get(DataTransfer, "data") != NULL)
  8424. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8425. result = PASS;
  8426. }
  8427. json_object_put(DataTransfer);
  8428. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8429. {
  8430. // Send all moudle firmware version on EVSE
  8431. createFirmwareVersionByDataTransfer();
  8432. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8433. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8434. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8435. json_object_put(response);
  8436. }
  8437. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8438. {
  8439. system("/usr/bin/run_tmate_restart.sh &");
  8440. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8441. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8442. json_object_put(response);
  8443. }
  8444. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8445. {
  8446. json_object *data;
  8447. data = json_tokener_parse(tempdata);
  8448. if(!is_error(data))
  8449. {
  8450. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8451. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8452. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8453. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8454. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8455. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8456. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8457. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8458. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8459. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8460. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8461. }
  8462. else
  8463. {
  8464. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8465. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8466. }
  8467. json_object_put(data);
  8468. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8469. json_object_put(response);
  8470. }
  8471. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8472. {
  8473. json_object *data;
  8474. data = json_tokener_parse(tempdata);
  8475. if(!is_error(data))
  8476. {
  8477. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8478. if(json_object_object_get(data, "idToken") != NULL)
  8479. {
  8480. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8481. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8482. }
  8483. if(json_object_object_get(data, "price") != NULL)
  8484. {
  8485. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8486. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8487. }
  8488. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8489. }
  8490. else
  8491. {
  8492. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8493. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8494. }
  8495. json_object_put(data);
  8496. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8497. json_object_put(response);
  8498. }
  8499. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8500. {
  8501. json_object *data;
  8502. data = json_tokener_parse(tempdata);
  8503. if(!is_error(data))
  8504. {
  8505. if(json_object_object_get(data, "txId") != NULL)
  8506. {
  8507. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8508. for(int idx = 0;idx<gunTotalNumber;idx++)
  8509. {
  8510. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8511. {
  8512. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8513. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8514. if(json_object_object_get(data, "description") != NULL)
  8515. {
  8516. // California pricing V1.0
  8517. DEBUG_INFO("California pricing V1.0\n");
  8518. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8519. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8520. }
  8521. else
  8522. {
  8523. // California pricing V1.1
  8524. DEBUG_INFO("California pricing V1.1\n");
  8525. if(json_object_object_get(data, "timestamp") != NULL)
  8526. {
  8527. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8528. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8529. }
  8530. if(json_object_object_get(data, "meterValue") != NULL)
  8531. {
  8532. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8533. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8534. }
  8535. if(json_object_object_get(data, "cost") != NULL)
  8536. {
  8537. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8538. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8539. }
  8540. if(json_object_object_get(data, "state") != NULL)
  8541. {
  8542. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8543. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8544. }
  8545. if(json_object_object_get(data, "chargingPrice") != NULL)
  8546. {
  8547. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8548. {
  8549. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8550. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8551. }
  8552. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8553. {
  8554. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8555. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8556. }
  8557. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8558. {
  8559. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8560. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8561. }
  8562. }
  8563. if(json_object_object_get(data, "idlePrice") != NULL)
  8564. {
  8565. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8566. {
  8567. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8568. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8569. }
  8570. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8571. {
  8572. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8573. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8574. }
  8575. }
  8576. if(json_object_object_get(data, "nextPeriod") != NULL)
  8577. {
  8578. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8579. {
  8580. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8581. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8582. }
  8583. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8584. {
  8585. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8586. {
  8587. 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")));
  8588. ShmOCPP16Data->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"));
  8589. }
  8590. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8591. {
  8592. 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")));
  8593. ShmOCPP16Data->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"));
  8594. }
  8595. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8596. {
  8597. 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")));
  8598. ShmOCPP16Data->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"));
  8599. }
  8600. }
  8601. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8602. {
  8603. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8604. {
  8605. 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")));
  8606. ShmOCPP16Data->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"));
  8607. }
  8608. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8609. {
  8610. 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")));
  8611. ShmOCPP16Data->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"));
  8612. }
  8613. }
  8614. }
  8615. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8616. {
  8617. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8618. {
  8619. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8620. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8621. }
  8622. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8623. {
  8624. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8625. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8626. }
  8627. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8628. {
  8629. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8630. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8631. }
  8632. }
  8633. }
  8634. }
  8635. }
  8636. }
  8637. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8638. }
  8639. else
  8640. {
  8641. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8642. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8643. }
  8644. json_object_put(data);
  8645. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8646. json_object_put(response);
  8647. }
  8648. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8649. {
  8650. json_object *data;
  8651. data = json_tokener_parse(tempdata);
  8652. if(!is_error(data))
  8653. {
  8654. if(json_object_object_get(data, "txId") != NULL)
  8655. {
  8656. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8657. for(int idx = 0;idx<gunTotalNumber;idx++)
  8658. {
  8659. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8660. {
  8661. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8662. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8663. if(json_object_object_get(data, "description") != NULL)
  8664. {
  8665. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8666. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8667. }
  8668. }
  8669. }
  8670. }
  8671. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8672. }
  8673. else
  8674. {
  8675. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8676. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8677. }
  8678. json_object_put(data);
  8679. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8680. json_object_put(response);
  8681. }
  8682. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8683. {
  8684. json_object *data;
  8685. data = json_tokener_parse(tempdata);
  8686. if(!is_error(data))
  8687. {
  8688. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8689. if(json_object_object_get(data, "Content_Type") != NULL)
  8690. {
  8691. 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))
  8692. {
  8693. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8694. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8695. {
  8696. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8697. }
  8698. }
  8699. else
  8700. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8701. }
  8702. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8703. }
  8704. else
  8705. {
  8706. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8707. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8708. }
  8709. json_object_put(data);
  8710. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8711. json_object_put(response);
  8712. }
  8713. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8714. {
  8715. json_object *data;
  8716. data = json_tokener_parse(tempdata);
  8717. if(!is_error(data))
  8718. {
  8719. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8720. if(json_object_object_get(data, "Page_Index") != NULL)
  8721. {
  8722. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8723. }
  8724. if(json_object_object_get(data, "Duration") != NULL)
  8725. {
  8726. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8727. }
  8728. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8729. }
  8730. else
  8731. {
  8732. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8733. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8734. }
  8735. json_object_put(data);
  8736. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8737. json_object_put(response);
  8738. }
  8739. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8740. {
  8741. json_object *data;
  8742. data = json_tokener_parse(tempdata);
  8743. if(!is_error(data))
  8744. {
  8745. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8746. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8747. {
  8748. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8749. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8750. else
  8751. {
  8752. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8753. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8754. }
  8755. }
  8756. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8757. {
  8758. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8759. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8760. else
  8761. {
  8762. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8763. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8764. }
  8765. }
  8766. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8767. {
  8768. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8769. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8770. else
  8771. {
  8772. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8773. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8774. }
  8775. }
  8776. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8777. {
  8778. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8779. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8780. else
  8781. {
  8782. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8783. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8784. }
  8785. }
  8786. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8787. {
  8788. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8789. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8790. else
  8791. {
  8792. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8793. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8794. }
  8795. }
  8796. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8797. {
  8798. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8799. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8800. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8801. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8802. else
  8803. {
  8804. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8805. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8806. }
  8807. }
  8808. if(json_object_object_get(data, "isAuthentication") != NULL)
  8809. {
  8810. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8811. {
  8812. case 0:
  8813. case 1:
  8814. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8815. break;
  8816. default:
  8817. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8818. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8819. break;
  8820. }
  8821. }
  8822. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8823. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8824. }
  8825. else
  8826. {
  8827. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8828. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8829. }
  8830. json_object_put(data);
  8831. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8832. json_object_put(response);
  8833. }
  8834. else
  8835. {
  8836. // Can not find valid message id
  8837. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8838. }
  8839. }
  8840. else
  8841. {
  8842. // Payload is null
  8843. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8844. }
  8845. LWS_Send(message);
  8846. return result;
  8847. }
  8848. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8849. {
  8850. mtrace();
  8851. int result = FAIL;
  8852. int connectorIdInt, durationInt;
  8853. char chargingRateUnitStr[4]={0};
  8854. char comfirmstr[20];
  8855. int confirmPeriods = 0;
  8856. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8857. json_object *GetCompositeSchedule;
  8858. GetCompositeSchedule = json_tokener_parse(payload);
  8859. if(!is_error(GetCompositeSchedule))
  8860. {
  8861. // Required data
  8862. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8863. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8864. else
  8865. connectorIdInt = -1;
  8866. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8867. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8868. else
  8869. durationInt = 86400;
  8870. // Optional data
  8871. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8872. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8873. }
  8874. json_object_put(GetCompositeSchedule);
  8875. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8876. if((connectorIdInt == 0) ||
  8877. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8878. {
  8879. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8880. struct StructChargingProfile tmpProfile[1];
  8881. if(strstr(chargingRateUnitStr, "W") != NULL)
  8882. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8883. else
  8884. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8885. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8886. {
  8887. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8888. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8889. }
  8890. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8891. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8892. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8893. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8894. {
  8895. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8896. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8897. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8898. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8899. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8900. {
  8901. confirmPeriods = idx;
  8902. break;
  8903. }
  8904. }
  8905. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8906. {
  8907. confirmPeriods += 1;
  8908. }
  8909. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8910. }
  8911. else
  8912. {
  8913. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8914. }
  8915. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8916. return result;
  8917. }
  8918. int handleGetConfigurationRequest(char *uuid, char *payload)
  8919. {
  8920. mtrace();
  8921. int result = FAIL;
  8922. int MaxKeySupported = 0;
  8923. int n_keys = 0;
  8924. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8925. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8926. json_object *GetConfiguration;
  8927. GetConfiguration = json_tokener_parse(payload);
  8928. if(!is_error(GetConfiguration))
  8929. {
  8930. // Optional data
  8931. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8932. {
  8933. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8934. {
  8935. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8936. n_keys = idx + 1;
  8937. }
  8938. }
  8939. }
  8940. json_object_put(GetConfiguration);
  8941. UnknownKeynum = 0;
  8942. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8943. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8944. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8945. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8946. if(n_keys != 0)
  8947. {
  8948. for(int i=0;i<n_keys;i++)
  8949. {
  8950. getKeyValue(requestKey[i]);
  8951. }
  8952. }
  8953. else
  8954. {
  8955. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8956. getKeyValue("");
  8957. }
  8958. processUnkownKey();
  8959. sendGetConfigurationConfirmation(uuid);
  8960. return result;
  8961. }
  8962. static char fnamePlusPath[100]={0};
  8963. static char fnamePWithNoPath[60]={0};
  8964. void checkUploadLog(void)
  8965. {
  8966. FILE *fp;
  8967. /* Open the command for reading. */
  8968. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8969. if (fp == NULL) {
  8970. DEBUG_WARN("Failed to run command\n" );
  8971. exit(1);
  8972. }
  8973. int ftppathlen = 0;
  8974. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8975. int i = 0;
  8976. /* Read the output a line at a time - output it. */
  8977. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8978. if(i==0)
  8979. {
  8980. ftppathlen = strlen(fnamePlusPath);
  8981. DEBUG_INFO("%s\n", fnamePlusPath);
  8982. fnamePlusPath[ftppathlen]='\0';
  8983. break;
  8984. }
  8985. i= i+1;
  8986. }
  8987. /* close */
  8988. pclose(fp);
  8989. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8990. {
  8991. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8992. {
  8993. fnamePlusPath[k]='\0';
  8994. }
  8995. }
  8996. i=1;
  8997. //char fname[60]={0};
  8998. while(i < ftppathlen)
  8999. {
  9000. int len=ftppathlen-i;
  9001. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9002. {
  9003. DEBUG_INFO("compare '/' all right\n");
  9004. break;
  9005. }
  9006. i=i+1;
  9007. }
  9008. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9009. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9010. fnamePWithNoPath[i+1] = '\0';
  9011. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9012. {
  9013. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9014. {
  9015. fnamePWithNoPath[j]='\0';
  9016. }
  9017. }
  9018. FILE* fp1 = fopen(fnamePlusPath, "r");
  9019. if (fp1)
  9020. {
  9021. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9022. // file exists
  9023. fclose(fp1);
  9024. }
  9025. else
  9026. {
  9027. // file doesn't exist
  9028. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9029. }
  9030. }
  9031. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9032. {
  9033. mtrace();
  9034. int result = FAIL;
  9035. time_t CurrentTime;
  9036. struct tm *tm;
  9037. pthread_t th_Status;
  9038. CurrentTime = time(NULL);
  9039. tm = localtime(&CurrentTime);
  9040. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9041. sprintf((char*)ShmOCPP16Data->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);
  9042. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9043. if(!interLock.isGetDiagnosticGoing)
  9044. {
  9045. interLock.isGetDiagnosticGoing = 1;
  9046. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9047. }
  9048. else
  9049. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9050. return result;
  9051. }
  9052. void* GetDiagnosticsProcess(void* data)
  9053. {
  9054. pthread_detach(pthread_self());
  9055. mtrace();
  9056. int retriesInt=0, retryIntervalInt=0;
  9057. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9058. char protocol[10]={0}, user[64]={0},password[64]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  9059. int port=0;
  9060. int isSuccess = FALSE;
  9061. char cmdBuf[2048];
  9062. struct tm *tmNow;
  9063. time_t CurrentTime;
  9064. struct tm tmStart;
  9065. struct tm tmStop;
  9066. CurrentTime = time(NULL);
  9067. tmNow=localtime(&CurrentTime);
  9068. uint16_t targetYear, targetMonth;
  9069. json_object *GetDiagnostics;
  9070. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9071. GetDiagnostics = json_tokener_parse(data);
  9072. if(!is_error(GetDiagnostics))
  9073. {
  9074. // Required data
  9075. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9076. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9077. // Optional data
  9078. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9079. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9080. else
  9081. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9082. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9083. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9084. else
  9085. retryIntervalInt = 30;
  9086. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9087. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9088. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9089. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9090. }
  9091. json_object_put(GetDiagnostics);
  9092. // Pack log to compress file
  9093. 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) &&
  9094. (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))
  9095. {
  9096. // Pack system log
  9097. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9098. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9099. targetYear = tmStart.tm_year;
  9100. targetMonth = tmStart.tm_mon;
  9101. do
  9102. {
  9103. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9104. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9105. if(targetMonth+1>=13)
  9106. {
  9107. targetYear += 1;
  9108. targetMonth = 1;
  9109. }
  9110. else
  9111. {
  9112. targetMonth += 1;
  9113. }
  9114. }while((targetYear < (tmNow->tm_year+1900)) ||
  9115. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9116. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9117. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9118. system(cmdBuf);
  9119. // Pack charging & event log
  9120. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9121. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9122. targetYear = tmStart.tm_year;
  9123. targetMonth = tmStart.tm_mon;
  9124. do
  9125. {
  9126. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9127. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9128. if(targetMonth+1>=13)
  9129. {
  9130. targetYear += 1;
  9131. targetMonth = 1;
  9132. }
  9133. else
  9134. {
  9135. targetMonth += 1;
  9136. }
  9137. }while((targetYear < (tmNow->tm_year+1900)) ||
  9138. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9139. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9140. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9141. system(cmdBuf);
  9142. // Combine log file
  9143. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9144. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9145. }
  9146. else
  9147. {
  9148. system("exec /root/logPackTools 'log' 6");
  9149. }
  9150. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9151. system(cmdBuf);
  9152. checkUploadLog();
  9153. //****************location*******************/
  9154. if(strcmp(locationstr,"")==0)
  9155. {
  9156. DEBUG_INFO("location is <Empty>!\n");
  9157. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9158. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9159. goto end;
  9160. }
  9161. memset(protocol, 0, ARRAY_SIZE(protocol));
  9162. memset(user, 0, ARRAY_SIZE(user) );
  9163. memset(password, 0, ARRAY_SIZE(password));
  9164. memset(host, 0, ARRAY_SIZE(host));
  9165. memset(path, 0, ARRAY_SIZE(path));
  9166. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9167. memset(host1, 0, ARRAY_SIZE(host1));
  9168. memset(path1, 0, ARRAY_SIZE(path1));
  9169. /*location: ftp://user:password@host:port/path*/
  9170. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9171. if((access(fnamePlusPath,F_OK))!=-1)
  9172. {
  9173. DEBUG_INFO("fnamePlusPath exist.\n");
  9174. }
  9175. else
  9176. {
  9177. DEBUG_INFO("fnamePlusPath not exist!\n");
  9178. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9179. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9180. goto end;
  9181. }
  9182. if(strchr(locationstr,'@')==NULL)
  9183. {
  9184. sscanf(locationstr,
  9185. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9186. protocol, host, &port, path);
  9187. strcpy(user,"anonymous");
  9188. strcpy(password,"");
  9189. }
  9190. else
  9191. {
  9192. //DEBUG_INFO("pch=%s\n", pch);
  9193. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9194. protocol, user, password, host, &port, path);
  9195. }
  9196. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9197. {
  9198. DEBUG_INFO("protocol is not ftp/http ! \n");
  9199. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9200. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9201. goto end;
  9202. }
  9203. if(strncmp(locationstr,"http", 4) == 0)
  9204. {
  9205. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9206. sprintf(ftppath,"/%s", path);
  9207. do
  9208. {
  9209. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9210. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9211. sleep(3);
  9212. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9213. if(!isSuccess)
  9214. {
  9215. DEBUG_INFO("Diagnostics fail.\n");
  9216. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9217. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9218. sleep(retryIntervalInt);
  9219. }
  9220. else
  9221. {
  9222. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9223. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9224. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9225. }
  9226. retriesInt--;
  9227. }while((isSuccess == 0)&&(retriesInt >= 0));
  9228. }
  9229. else
  9230. {
  9231. sscanf(host,"%[^/]%s",host1, path1);
  9232. if(strlen(path) > 0)
  9233. sprintf(ftppath,"/%s", path);
  9234. else
  9235. sprintf(ftppath,"/%s", path1);
  9236. int ftppathlen=strlen(ftppath);
  9237. int i=1;
  9238. char filenametemp[50];
  9239. while(i < ftppathlen)
  9240. {
  9241. int len=ftppathlen-i;
  9242. if(ftppath[len]== 47) // '/' ascll code: 47
  9243. {
  9244. DEBUG_INFO("find '/' all right\n");
  9245. break;
  9246. }
  9247. i=i+1;
  9248. }
  9249. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9250. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9251. filenametemp[i+1] = 0;
  9252. if(port == 0)
  9253. port = 21;
  9254. do
  9255. {
  9256. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9257. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9258. sleep(3);
  9259. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9260. if(!isSuccess)
  9261. {
  9262. DEBUG_INFO("Diagnostics fail.\n");
  9263. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9264. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9265. sleep(retryIntervalInt);
  9266. }
  9267. else
  9268. {
  9269. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9270. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9271. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9272. }
  9273. retriesInt--;
  9274. }while((!isSuccess)&&(retriesInt >= 0));
  9275. }
  9276. end:
  9277. system("rm -f /mnt/*");
  9278. sleep(5);
  9279. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9280. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9281. interLock.isGetDiagnosticGoing = 0;
  9282. pthread_exit(NULL);
  9283. }
  9284. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9285. {
  9286. mtrace();
  9287. int result = FAIL;
  9288. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9289. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9290. {
  9291. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9292. locallistVersion = -1;
  9293. }
  9294. else
  9295. {
  9296. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9297. OCPP_getListVerion();
  9298. }
  9299. //from db.OCPP_getListVerion
  9300. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9301. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9302. sendGetLocalListVersionConfirmation(uuid,"");
  9303. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9304. return result;
  9305. }
  9306. int handleRemoteStartRequest(char *uuid, char *payload)
  9307. {
  9308. mtrace();
  9309. int result = FAIL;
  9310. int connectorIdInt=-1;
  9311. int tempIndex = 0;
  9312. int connectorIdIsNULL, chargingProfileIsNULL;
  9313. char comfirmstr[20]={0};
  9314. char cmdBuf[512];
  9315. json_object *RemoteStartTransaction;
  9316. FILE *fp;
  9317. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9318. if(server_pending == TRUE)
  9319. {
  9320. return 0;
  9321. }
  9322. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9323. RemoteStartTransaction = json_tokener_parse(payload);
  9324. if(!is_error(RemoteStartTransaction))
  9325. {
  9326. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9327. {
  9328. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9329. }
  9330. else
  9331. {
  9332. connectorIdIsNULL = TRUE;
  9333. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9334. {
  9335. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9336. {
  9337. connectorIdIsNULL = FALSE;
  9338. connectorIdInt = (gun_index+1);
  9339. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9340. break;
  9341. }
  9342. }
  9343. }
  9344. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9345. {
  9346. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9347. // Required data
  9348. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9349. // Optional data
  9350. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9351. {
  9352. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9353. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9354. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9355. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9356. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9357. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9358. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9359. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9360. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9361. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9362. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9363. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9364. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9365. {
  9366. sprintf((char*)ShmOCPP16Data->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")));
  9367. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9368. ShmOCPP16Data->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"));
  9369. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9370. ShmOCPP16Data->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"));
  9371. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9372. sprintf((char*)ShmOCPP16Data->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")));
  9373. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9374. {
  9375. 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++)
  9376. {
  9377. ShmOCPP16Data->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"));
  9378. ShmOCPP16Data->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"));
  9379. 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)
  9380. ShmOCPP16Data->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"));
  9381. }
  9382. }
  9383. }
  9384. }
  9385. else
  9386. {
  9387. chargingProfileIsNULL = TRUE;
  9388. }
  9389. }
  9390. }
  9391. else
  9392. {
  9393. connectorIdIsNULL = TRUE;
  9394. }
  9395. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9396. {
  9397. DEBUG_WARN("Connector id is NULL\n.");
  9398. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9399. goto end;
  9400. }
  9401. /*
  9402. enum _SYSTEM_STATUS
  9403. {
  9404. S_BOOTING = 0,
  9405. S_IDLE, = 1
  9406. S_AUTHORIZING, = 2
  9407. S_REASSIGN_CHECK, = 3
  9408. S_REASSIGN, = 4
  9409. S_PRECHARGE, = 5
  9410. S_PREPARING_FOR_EV, = 6
  9411. S_PREPARING_FOR_EVSE, = 7
  9412. S_CHARGING, = 8
  9413. S_TERMINATING, = 9
  9414. S_COMPLETE, = 10
  9415. S_ALARM, = 11
  9416. S_FAULT = 12
  9417. }
  9418. */
  9419. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9420. {
  9421. //check Transaction active
  9422. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9423. {
  9424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9425. {
  9426. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9427. }
  9428. else
  9429. {
  9430. tempIndex = connectorIdInt -1;
  9431. }
  9432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9433. {
  9434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9435. {
  9436. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9437. {
  9438. //Reserved
  9439. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9440. }
  9441. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9442. {
  9443. //Reserved
  9444. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9445. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9446. goto end;
  9447. }
  9448. else
  9449. {
  9450. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9451. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9452. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9453. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9454. {
  9455. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9456. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9457. goto end;
  9458. }
  9459. }//END FOR ELSE
  9460. }
  9461. }// END FOR CHAdeMO_QUANTITY
  9462. }
  9463. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9464. {
  9465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9466. {
  9467. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9468. }
  9469. else
  9470. {
  9471. tempIndex = connectorIdInt -1;
  9472. }
  9473. for (int index = 0; index < CCS_QUANTITY; index++)
  9474. {
  9475. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9476. {
  9477. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9478. {
  9479. //Reserved
  9480. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9481. }
  9482. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9483. {
  9484. //Reserved
  9485. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9486. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9487. goto end;
  9488. }
  9489. else
  9490. {
  9491. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9492. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9493. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9494. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9495. {
  9496. DEBUG_WARN("CCS connector not allow start\n.");
  9497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9498. goto end;
  9499. }
  9500. }// END FOR ELSE
  9501. }
  9502. }// END FOR CCS_QUANTITY
  9503. }
  9504. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9505. {
  9506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9507. {
  9508. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9509. }
  9510. else
  9511. {
  9512. tempIndex = connectorIdInt -1;
  9513. }
  9514. for (int index = 0; index < GB_QUANTITY; index++)
  9515. {
  9516. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9517. {
  9518. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9519. {
  9520. //Reserved
  9521. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9522. }
  9523. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9524. {
  9525. //Reserved
  9526. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9527. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9528. goto end;
  9529. }
  9530. else
  9531. {
  9532. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9533. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9534. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9535. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9536. {
  9537. DEBUG_WARN("GB connector not allow start\n.");
  9538. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9539. goto end;
  9540. }
  9541. }// END FOR ELSE
  9542. }
  9543. } // END FOR GB_QUANTITY
  9544. }
  9545. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9546. {
  9547. tempIndex = connectorIdInt -1;
  9548. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9549. {
  9550. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9551. {
  9552. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9553. {
  9554. //Reserved
  9555. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9556. }
  9557. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9558. {
  9559. //Reserved
  9560. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9561. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9562. goto end;
  9563. }
  9564. else
  9565. {
  9566. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9567. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9568. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9569. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9570. {
  9571. DEBUG_WARN("GB connector not allow start\n.");
  9572. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9573. goto end;
  9574. }
  9575. }// END FOR ELSE
  9576. }
  9577. } // END FOR GB_QUANTITY
  9578. }
  9579. else
  9580. {
  9581. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9582. {
  9583. tempIndex = 2;
  9584. }
  9585. else
  9586. {
  9587. tempIndex = connectorIdInt -1;
  9588. }
  9589. for (int index = 0; index < AC_QUANTITY; index++)
  9590. {
  9591. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9592. {
  9593. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9594. {
  9595. //Reserved
  9596. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9597. }
  9598. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9599. {
  9600. //Reserved
  9601. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9602. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9603. goto end;
  9604. }
  9605. else
  9606. {
  9607. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9608. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9609. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9610. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9611. {
  9612. DEBUG_WARN("AC connector not allow start\n.");
  9613. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9614. goto end;
  9615. }
  9616. }//END FOR ELSE
  9617. }
  9618. }// END FOR AC_QUANTITY
  9619. }
  9620. if(chargingProfileIsNULL == FALSE)
  9621. {
  9622. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9623. {
  9624. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9625. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9626. //memset idTag
  9627. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9628. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9629. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9630. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9631. // Save profile to file
  9632. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9633. system(cmdBuf);
  9634. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9635. fp = fopen(cmdBuf, "w");
  9636. 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));
  9637. fclose(fp);
  9638. }
  9639. else
  9640. {
  9641. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9642. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9643. }
  9644. }
  9645. else
  9646. {
  9647. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9648. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9649. //memset idTag
  9650. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9651. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9652. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9653. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9654. }
  9655. }
  9656. else
  9657. {
  9658. DEBUG_WARN("Connector id over\n.");
  9659. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9660. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9661. }
  9662. end:
  9663. json_object_put(RemoteStartTransaction);
  9664. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9665. {
  9666. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9667. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9668. }
  9669. //OCPP send RemoteStartConfirmation by first.
  9670. sendRemoteStartConfirmation(uuid, comfirmstr);
  9671. return result;
  9672. }
  9673. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9674. {
  9675. mtrace();
  9676. int result = FAIL;
  9677. int match = FALSE;
  9678. int GunNO = 0;
  9679. int tempIndex = 0;
  9680. int transactionIdInt=0;
  9681. int transactionIdIsNULL= TRUE;
  9682. char comfirmstr[20];
  9683. json_object *RemoteStopTransaction;
  9684. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9685. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9686. if(server_pending == TRUE)
  9687. {
  9688. return 0;
  9689. }
  9690. RemoteStopTransaction = json_tokener_parse(payload);
  9691. if(!is_error(RemoteStopTransaction))
  9692. {
  9693. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9694. {
  9695. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9696. transactionIdIsNULL = FALSE;
  9697. }
  9698. }
  9699. json_object_put(RemoteStopTransaction);
  9700. if(transactionIdIsNULL == FALSE)
  9701. {
  9702. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9703. {
  9704. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9705. {
  9706. //check Transaction active
  9707. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9708. {
  9709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9710. {
  9711. tempIndex = ((gun_index==2) ? 1: 0);
  9712. }
  9713. else
  9714. {
  9715. tempIndex = gun_index;
  9716. }
  9717. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9718. {
  9719. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9720. {
  9721. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9722. {
  9723. match = TRUE;
  9724. GunNO = gun_index;
  9725. }
  9726. }
  9727. }// END FOR CHAdeMO_QUANTITY
  9728. }
  9729. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9730. {
  9731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9732. {
  9733. tempIndex = ((gun_index==2) ? 1: 0);
  9734. }
  9735. else
  9736. {
  9737. tempIndex = gun_index;
  9738. }
  9739. for (int index = 0; index < CCS_QUANTITY; index++)
  9740. {
  9741. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9742. {
  9743. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9744. {
  9745. match = TRUE;
  9746. GunNO = gun_index;
  9747. }
  9748. }
  9749. }// END FOR CCS_QUANTITY
  9750. }
  9751. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9752. {
  9753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9754. {
  9755. tempIndex = ((gun_index==2) ? 1: 0);
  9756. }
  9757. else
  9758. {
  9759. tempIndex = gun_index;
  9760. }
  9761. for (int index = 0; index < GB_QUANTITY; index++)
  9762. {
  9763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9764. {
  9765. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9766. {
  9767. match = TRUE;
  9768. GunNO = gun_index;
  9769. }
  9770. }
  9771. }// END FOR GB_QUANTITY
  9772. }
  9773. else if(gunType[gun_index] == GUN_TYPE_DO)
  9774. {
  9775. tempIndex = gun_index;
  9776. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9777. {
  9778. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9779. {
  9780. 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
  9781. {
  9782. match = TRUE;
  9783. GunNO = gun_index;
  9784. }
  9785. }
  9786. }// END FOR GB_QUANTITY
  9787. }
  9788. else
  9789. {
  9790. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9791. {
  9792. tempIndex = 2;
  9793. }
  9794. else
  9795. {
  9796. tempIndex = gun_index;
  9797. }
  9798. for (int index = 0; index < AC_QUANTITY; index++)
  9799. {
  9800. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9801. {
  9802. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9803. {
  9804. match = TRUE;
  9805. GunNO = gun_index;
  9806. }
  9807. }
  9808. }// END FOR CHAdeMO_QUANTITY
  9809. } // END FOR AC ELSE
  9810. }// CHECK IF ResponseTransactionId == transactionIdInt
  9811. }//END FOR
  9812. if( match == TRUE)
  9813. {
  9814. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9815. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9816. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9817. }
  9818. else
  9819. {
  9820. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9821. }
  9822. }
  9823. else
  9824. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9825. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9826. return result;
  9827. }
  9828. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9829. {
  9830. mtrace();
  9831. int result = FAIL;
  9832. int connectorIdInt=0, reservationIdInt=0;
  9833. int tempIndex = 0;
  9834. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9835. char comfirmstr[20]={0};
  9836. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9837. int c = 0;
  9838. char *loc;
  9839. //char *ptr;
  9840. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9841. strcpy(sstrtemp, stringtrimspace(payload));
  9842. //***(1)connectorId ****/
  9843. c=0;
  9844. loc = strstr(sstrtemp, "connectorId");
  9845. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9846. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9847. {
  9848. sstr[c] = loc[strlen("connectorId")+2+c];
  9849. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9850. c++;
  9851. }
  9852. sstr[c] = '\0';
  9853. connectorIdInt = atoi(sstr);
  9854. //***(2)expiryDate ****/
  9855. loc = strstr(sstrtemp, "expiryDate");
  9856. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9857. c = 0;
  9858. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9859. {
  9860. sstr[c] = loc[3+strlen("expiryDate")+c];
  9861. c++;
  9862. }
  9863. sstr[c] = '\0';
  9864. strcpy(expiryDatestr, sstr);
  9865. //***(3)idTag ****/
  9866. loc = strstr(sstrtemp, "idTag");
  9867. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9868. c = 0;
  9869. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9870. {
  9871. sstr[c] = loc[3+strlen("idTag")+c];
  9872. c++;
  9873. }
  9874. sstr[c] = '\0';
  9875. strcpy(idTagstr, sstr);
  9876. //***(4)parentIdTag ****/
  9877. loc = strstr(sstrtemp, "parentIdTag");
  9878. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9879. c = 0;
  9880. if(loc == NULL)
  9881. {
  9882. strcpy(parentIdTagstr, "");
  9883. }
  9884. else
  9885. {
  9886. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9887. {
  9888. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9889. c++;
  9890. }
  9891. sstr[c] = '\0';
  9892. strcpy(parentIdTagstr, sstr);
  9893. }
  9894. //***(5)reservationId ****/
  9895. c=0;
  9896. loc = strstr(sstrtemp, "reservationId");
  9897. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9898. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9899. {
  9900. sstr[c] = loc[strlen("reservationId")+2+c];
  9901. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9902. c++;
  9903. }
  9904. sstr[c] = '\0';
  9905. reservationIdInt = atoi(sstr);
  9906. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9907. /*
  9908. enum SYSTEM_STATUS
  9909. {
  9910. SYS_MODE_BOOTING = 0,
  9911. SYS_MODE_IDLE = 1,
  9912. SYS_MODE_AUTHORIZING = 2,
  9913. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9914. SYS_MODE_REASSIGN = 4,
  9915. SYS_MODE_PREPARING = 5,
  9916. SYS_MODE_PREPARE_FOR_EV = 6,
  9917. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9918. SYS_MODE_CHARGING = 8,
  9919. SYS_MODE_TERMINATING = 9,
  9920. SYS_MODE_COMPLETE = 10,
  9921. SYS_MODE_ALARM = 11,
  9922. SYS_MODE_FAULT = 12,
  9923. SYS_MODE_RESERVATION = 13,
  9924. SYS_MODE_BOOKING = 14,
  9925. SYS_MODE_MAINTAIN = 15,
  9926. SYS_MODE_DEBUG = 16,
  9927. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9928. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9929. SYS_MODE_UPDATE = 19
  9930. };
  9931. */
  9932. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9933. {
  9934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9935. goto end;
  9936. }
  9937. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9938. {
  9939. //check Transaction active
  9940. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9941. {
  9942. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9943. {
  9944. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9945. }
  9946. else
  9947. {
  9948. tempIndex = connectorIdInt -1;
  9949. }
  9950. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9951. {
  9952. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9953. {
  9954. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9955. {
  9956. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9957. {
  9958. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9959. {
  9960. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9961. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9962. }
  9963. 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'))
  9964. {
  9965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9966. }
  9967. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9968. {
  9969. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9970. }
  9971. else
  9972. {
  9973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9974. }
  9975. }
  9976. 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
  9977. {
  9978. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9979. }
  9980. }
  9981. else
  9982. {
  9983. //replace reservation
  9984. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9986. }
  9987. }
  9988. } // END FOR CHAdeMO_QUANTITY
  9989. }
  9990. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9991. {
  9992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9993. {
  9994. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9995. }
  9996. else
  9997. {
  9998. tempIndex = connectorIdInt -1;
  9999. }
  10000. for (int index = 0; index < CCS_QUANTITY; index++)
  10001. {
  10002. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10003. {
  10004. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10005. {
  10006. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10007. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10008. {
  10009. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10010. {
  10011. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10013. }
  10014. 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'))
  10015. {
  10016. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10017. }
  10018. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10019. {
  10020. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10021. }
  10022. else
  10023. {
  10024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10025. }
  10026. }
  10027. 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
  10028. {
  10029. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10030. }
  10031. }
  10032. else
  10033. {
  10034. //replace reservation
  10035. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10037. }
  10038. }
  10039. } // END FOR CCS_QUANTITY
  10040. }
  10041. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10042. {
  10043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10044. {
  10045. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10046. }
  10047. else
  10048. {
  10049. tempIndex = connectorIdInt -1;
  10050. }
  10051. for (int index = 0; index < GB_QUANTITY; index++)
  10052. {
  10053. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10054. {
  10055. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10056. {
  10057. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10058. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10059. {
  10060. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10061. {
  10062. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10064. }
  10065. 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'))
  10066. {
  10067. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10068. }
  10069. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10070. {
  10071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10072. }
  10073. else
  10074. {
  10075. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10076. }
  10077. }
  10078. 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
  10079. {
  10080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10081. }
  10082. }
  10083. else
  10084. {
  10085. //replace reservation
  10086. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10087. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10088. }
  10089. }
  10090. }// END FOR GB_QUANTITY
  10091. }
  10092. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10093. {
  10094. tempIndex = connectorIdInt -1;
  10095. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10096. {
  10097. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10098. {
  10099. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10100. {
  10101. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10102. 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
  10103. {
  10104. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10105. {
  10106. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10108. }
  10109. 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'))
  10110. {
  10111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10112. }
  10113. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10114. {
  10115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10116. }
  10117. else
  10118. {
  10119. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10120. }
  10121. }
  10122. 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
  10123. {
  10124. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10125. }
  10126. }
  10127. else
  10128. {
  10129. //replace reservation
  10130. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10131. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10132. }
  10133. }
  10134. }// END FOR GB_QUANTITY
  10135. }
  10136. else
  10137. {
  10138. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10139. {
  10140. tempIndex = 2;
  10141. }
  10142. else
  10143. {
  10144. tempIndex = (connectorIdInt -1);
  10145. }
  10146. for (int index = 0; index < AC_QUANTITY; index++)
  10147. {
  10148. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10149. {
  10150. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10151. {
  10152. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10153. {
  10154. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10155. {
  10156. 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))
  10157. {
  10158. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10159. }
  10160. else
  10161. {
  10162. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10163. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10164. }
  10165. }
  10166. 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'))
  10167. {
  10168. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10169. }
  10170. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10171. {
  10172. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10173. }
  10174. else
  10175. {
  10176. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10177. }
  10178. }
  10179. 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
  10180. {
  10181. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10182. }
  10183. }
  10184. else
  10185. {
  10186. //replace reservation
  10187. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10189. }
  10190. }
  10191. } // END FOR AC_QUANTITY
  10192. }
  10193. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10194. }
  10195. else if(connectorIdInt == 0)
  10196. {
  10197. //check Transaction active
  10198. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10199. {
  10200. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10201. {
  10202. 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'))
  10203. {
  10204. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10205. goto end;
  10206. }
  10207. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10208. {
  10209. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10210. goto end;
  10211. }
  10212. 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
  10213. {
  10214. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10215. goto end;
  10216. }
  10217. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10218. {
  10219. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10220. goto end;
  10221. }
  10222. }
  10223. }// END FOR CHAdeMO_QUANTITY
  10224. for (int index = 0; index < CCS_QUANTITY; index++)
  10225. {
  10226. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10227. {
  10228. 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'))
  10229. {
  10230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10231. goto end;
  10232. }
  10233. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10234. {
  10235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10236. goto end;
  10237. }
  10238. 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
  10239. {
  10240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10241. goto end;
  10242. }
  10243. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10244. {
  10245. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10246. goto end;
  10247. }
  10248. }
  10249. } // END FOR CCS_QUANTITY
  10250. for (int index = 0; index < GB_QUANTITY; index++)
  10251. {
  10252. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10253. {
  10254. 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'))
  10255. {
  10256. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10257. goto end;
  10258. }
  10259. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10260. {
  10261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10262. goto end;
  10263. }
  10264. 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
  10265. {
  10266. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10267. goto end;
  10268. }
  10269. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10270. {
  10271. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10272. goto end;
  10273. }
  10274. }
  10275. } // END FOR GB_QUANTITY
  10276. for (int index = 0; index < AC_QUANTITY; index++)
  10277. {
  10278. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10279. {
  10280. 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'))
  10281. {
  10282. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10283. goto end;
  10284. }
  10285. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10286. {
  10287. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10288. goto end;
  10289. }
  10290. 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
  10291. {
  10292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10293. goto end;
  10294. }
  10295. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10296. {
  10297. 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))
  10298. {
  10299. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10300. goto end;
  10301. }
  10302. }
  10303. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10304. {
  10305. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10306. goto end;
  10307. }
  10308. }
  10309. }// END FOR AC_QUANTITY
  10310. //The connectorId is 0
  10311. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10312. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10313. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10314. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10315. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10316. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10317. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10318. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10319. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10320. result = TRUE;
  10321. return result;
  10322. }
  10323. else
  10324. {
  10325. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10326. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10327. }
  10328. if(strcmp(comfirmstr,"Accepted") == 0)
  10329. {
  10330. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10331. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10332. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10333. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10334. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10335. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10336. result = TRUE;
  10337. return result;
  10338. }
  10339. end:
  10340. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10341. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10342. return result;
  10343. }
  10344. int handleResetRequest(char *uuid, char *payload)
  10345. {
  10346. mtrace();
  10347. int result = FAIL;
  10348. char sstr[10]={0},sstrtemp[30]={ 0 };
  10349. char typestr[10]={0};
  10350. char comfirmstr[20]={0};
  10351. int c = 0;
  10352. char *loc;
  10353. DEBUG_INFO("handleResetRequest...\n");
  10354. strcpy(sstrtemp, stringtrimspace(payload));
  10355. loc = strstr(sstrtemp, "type");
  10356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10357. c = 0;
  10358. while (loc[3+strlen("type")+c] != '\"')
  10359. {
  10360. sstr[c] = loc[3+strlen("type")+c];
  10361. c++;
  10362. }
  10363. sstr[c] = '\0';
  10364. strcpy(typestr,sstr);
  10365. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10366. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10367. {
  10368. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10369. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10370. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10371. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10372. }
  10373. else
  10374. {
  10375. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10376. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10377. result = PASS;
  10378. }
  10379. sendResetConfirmation(uuid, comfirmstr);
  10380. return result;
  10381. }
  10382. int handleSendLocalListRequest(char *uuid, char *payload)
  10383. {
  10384. mtrace();
  10385. int result = FAIL;
  10386. char comfirmstr[20];
  10387. int checkState_Faulted = FALSE;
  10388. json_object *SendLocalList;
  10389. DEBUG_INFO("handleSendLocalListRequest...\n");
  10390. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10391. {
  10392. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10393. goto end;
  10394. }
  10395. //check Charge Point state
  10396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10397. {
  10398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10399. {
  10400. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10401. }
  10402. }
  10403. for (int index = 0; index < CCS_QUANTITY; index++)
  10404. {
  10405. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10406. {
  10407. checkState_Faulted = TRUE; //OCPP Status
  10408. }
  10409. }
  10410. for (int index = 0; index < GB_QUANTITY; index++)
  10411. {
  10412. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10413. {
  10414. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10415. }
  10416. }
  10417. //check Charge Point state
  10418. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10419. {
  10420. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10421. {
  10422. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10423. }
  10424. }
  10425. //check Charge Point state
  10426. for (int index = 0; index < AC_QUANTITY; index++)
  10427. {
  10428. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10429. {
  10430. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10431. }
  10432. }
  10433. if(checkState_Faulted == TRUE)
  10434. {
  10435. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10436. goto end;
  10437. }
  10438. // Parsing payload
  10439. SendLocalList = json_tokener_parse(payload);
  10440. if(!is_error(SendLocalList))
  10441. {
  10442. // Required data
  10443. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10444. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10445. // Optional data
  10446. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10447. {
  10448. //Check UpdateType
  10449. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10450. {
  10451. //Local list full update
  10452. DEBUG_INFO("Local list full update.\n");
  10453. OCPP_getListVerion();
  10454. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10455. {
  10456. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10457. goto end;
  10458. }
  10459. OCPP_cleanLocalList();
  10460. }
  10461. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10462. {
  10463. //Local list different update
  10464. DEBUG_INFO("Local list different update.\n");
  10465. OCPP_getListVerion();
  10466. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10467. {
  10468. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10469. goto end;
  10470. }
  10471. }
  10472. else
  10473. {
  10474. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10475. goto end;
  10476. }
  10477. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10478. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10479. {
  10480. sprintf((char*)ShmOCPP16Data->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")));
  10481. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10482. {
  10483. sprintf((char*)ShmOCPP16Data->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")));
  10484. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10485. sprintf((char*)ShmOCPP16Data->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")));
  10486. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10487. sprintf((char*)ShmOCPP16Data->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")));
  10488. }
  10489. // Add to db
  10490. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10491. {
  10492. //Local list full update
  10493. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10494. idx,
  10495. ShmOCPP16Data->SendLocalList.ListVersion,
  10496. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10497. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10498. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10499. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10500. // update list
  10501. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10502. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10503. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10504. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10505. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10506. }
  10507. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10508. {
  10509. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10510. idx,
  10511. ShmOCPP16Data->SendLocalList.ListVersion,
  10512. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10513. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10514. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10515. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10516. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10517. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10518. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10519. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10520. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10521. }
  10522. }
  10523. }
  10524. else
  10525. {
  10526. //Check UpdateType
  10527. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10528. {
  10529. //Local list full update
  10530. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10531. OCPP_cleanLocalList();
  10532. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10533. goto end;
  10534. }
  10535. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10536. {
  10537. //Local list different update
  10538. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10539. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10540. goto end;
  10541. }
  10542. }
  10543. result = PASS;
  10544. }
  10545. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10546. end:
  10547. json_object_put(SendLocalList);
  10548. sendSendLocalListConfirmation(uuid, comfirmstr);
  10549. return result;
  10550. }
  10551. #define MAX 200
  10552. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10553. {
  10554. mtrace();
  10555. int result = FAIL;
  10556. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10557. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10558. char chargingProfilePurposeStr[30]={0};
  10559. char chargingProfileKindStr[16]={0};
  10560. char recurrencyKindStr[10]={0};
  10561. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10562. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10563. int chargingSchedulePeriodCount = 0;
  10564. char comfirmstr[20]={0};
  10565. int meet= FALSE;
  10566. FILE *fptr1;
  10567. char filename[MAX]={0};
  10568. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10569. char rmFileCmd[50]={0};
  10570. char tempchargingProfilePurposeStr[30]={0};
  10571. char word[1600]={0};
  10572. int n_chargingProfile = 0;
  10573. json_object *SetChargingProfile;
  10574. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10575. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10576. SetChargingProfile = json_tokener_parse(payload);
  10577. if(!is_error(SetChargingProfile))
  10578. {
  10579. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10580. {
  10581. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10582. if(connectorIdInt == 0)
  10583. {
  10584. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10585. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10586. }
  10587. else
  10588. {
  10589. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10590. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10591. }
  10592. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10593. }
  10594. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10595. {
  10596. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10597. {
  10598. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10599. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10600. {
  10601. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10602. }
  10603. else
  10604. {
  10605. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10606. }
  10607. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10608. }
  10609. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10610. {
  10611. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10612. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10613. {
  10614. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10615. }
  10616. else
  10617. {
  10618. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10619. }
  10620. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10621. }
  10622. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10623. {
  10624. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10625. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10626. {
  10627. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10628. }
  10629. else
  10630. {
  10631. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10632. }
  10633. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10634. }
  10635. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10636. {
  10637. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10638. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10639. {
  10640. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10641. }
  10642. else
  10643. {
  10644. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10645. }
  10646. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10647. }
  10648. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10649. {
  10650. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10651. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10652. {
  10653. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10654. }
  10655. else
  10656. {
  10657. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10658. }
  10659. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10660. }
  10661. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10662. {
  10663. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10664. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10665. {
  10666. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10667. }
  10668. else
  10669. {
  10670. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10671. }
  10672. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10673. }
  10674. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10675. {
  10676. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10677. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10678. {
  10679. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10680. }
  10681. else
  10682. {
  10683. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10684. }
  10685. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10686. }
  10687. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10688. {
  10689. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10690. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10691. {
  10692. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10693. }
  10694. else
  10695. {
  10696. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10697. }
  10698. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10699. }
  10700. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10701. {
  10702. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10703. {
  10704. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10705. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10706. {
  10707. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10708. }
  10709. else
  10710. {
  10711. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10712. }
  10713. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10714. }
  10715. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10716. {
  10717. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10718. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10719. {
  10720. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10721. }
  10722. else
  10723. {
  10724. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10725. }
  10726. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10727. }
  10728. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10729. {
  10730. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10731. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10732. {
  10733. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10734. }
  10735. else
  10736. {
  10737. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10738. }
  10739. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10740. }
  10741. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10742. {
  10743. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10744. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10745. {
  10746. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10747. }
  10748. else
  10749. {
  10750. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10751. }
  10752. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10753. }
  10754. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10755. {
  10756. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10757. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10758. if(chargingSchedulePeriodCount <= 10)
  10759. {
  10760. 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++)
  10761. {
  10762. 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)
  10763. {
  10764. startPeriodInt[idxPeriod] = 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"));
  10765. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10766. {
  10767. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10768. }
  10769. else
  10770. {
  10771. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10772. }
  10773. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10774. }
  10775. 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)
  10776. {
  10777. limitflaot[idxPeriod] = 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"));
  10778. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10779. {
  10780. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10781. }
  10782. else
  10783. {
  10784. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10785. }
  10786. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10787. }
  10788. 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)
  10789. {
  10790. numberPhasesInt[idxPeriod] = 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"));
  10791. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10792. {
  10793. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10794. }
  10795. else
  10796. {
  10797. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10798. }
  10799. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10800. }
  10801. }
  10802. }
  10803. }
  10804. }
  10805. }
  10806. }
  10807. json_object_put(SetChargingProfile);
  10808. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10809. {
  10810. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10811. goto end;
  10812. }
  10813. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10814. {
  10815. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10816. if(connectorIdInt != 0)
  10817. {
  10818. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10819. goto end;
  10820. }
  10821. strcpy(filename, ChargePointMaxProfile_JSON );
  10822. fptr1 = fopen(filename, "r");
  10823. if (!fptr1)
  10824. {
  10825. //file not exist
  10826. DEBUG_INFO("Unable to open the input file!!\n");
  10827. fptr1 = fopen(filename, "w+");
  10828. }
  10829. else
  10830. {
  10831. //Check Charging Profile Count
  10832. while(fscanf(fptr1, "%s", word) != EOF)
  10833. {
  10834. //DEBUG_INFO("word=%s\n",word);
  10835. if(strstr(word, "chargingProfileId")!= NULL)
  10836. {
  10837. //DEBUG_INFO("test chargingProfileId \n");
  10838. n_chargingProfile = n_chargingProfile + 1;
  10839. //DEBUG_INFO("chargingProfileId Found\n");
  10840. }
  10841. }
  10842. }
  10843. fclose(fptr1);
  10844. }
  10845. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10846. {
  10847. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10848. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10849. {
  10850. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10851. goto end;
  10852. }
  10853. memset(filename, 0, ARRAY_SIZE(filename));
  10854. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10855. fptr1 = fopen(filename, "r");
  10856. if (!fptr1)
  10857. {
  10858. //file not exist
  10859. //DEBUG_INFO("Unable to open the input file!!\n");
  10860. fptr1 = fopen(filename, "w+");
  10861. }
  10862. else
  10863. {
  10864. //Check Charging Profile Count
  10865. while(fscanf(fptr1, "%s", word) != EOF)
  10866. {
  10867. //DEBUG_INFO("word=%s\n",word);
  10868. if(strstr(word, "chargingProfileId")!= NULL)
  10869. {
  10870. //DEBUG_INFO("test chargingProfileId \n");
  10871. n_chargingProfile = n_chargingProfile + 1;
  10872. //DEBUG_INFO("chargingProfileId Found\n");
  10873. }
  10874. }
  10875. }
  10876. fclose(fptr1);
  10877. }
  10878. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10879. {
  10880. //printf("set chargingProfile 1-4\n");
  10881. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10882. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10883. if(connectorIdInt == 0)
  10884. {
  10885. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10886. goto end;
  10887. }
  10888. int tempIndex = 0;
  10889. //check Transaction active
  10890. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10891. {
  10892. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10893. {
  10894. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10895. }
  10896. else
  10897. {
  10898. tempIndex = connectorIdInt -1;
  10899. }
  10900. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10901. {
  10902. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10903. {
  10904. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10905. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10906. {
  10907. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10908. {
  10909. meet = TRUE;
  10910. break;
  10911. }
  10912. }
  10913. }
  10914. }
  10915. }
  10916. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10917. {
  10918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10919. {
  10920. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10921. }
  10922. else
  10923. {
  10924. tempIndex = connectorIdInt -1;
  10925. }
  10926. for (int index = 0; index < CCS_QUANTITY; index++)
  10927. {
  10928. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10929. {
  10930. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10931. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10932. {
  10933. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10934. {
  10935. meet = TRUE;
  10936. break;
  10937. }
  10938. }
  10939. }
  10940. }
  10941. }
  10942. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10943. {
  10944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10945. {
  10946. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10947. }
  10948. else
  10949. {
  10950. tempIndex = connectorIdInt -1;
  10951. }
  10952. for (int index = 0; index < GB_QUANTITY; index++)
  10953. {
  10954. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10955. {
  10956. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10957. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10958. {
  10959. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10960. {
  10961. meet = TRUE;
  10962. break;
  10963. }
  10964. }
  10965. }
  10966. }
  10967. }
  10968. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10969. {
  10970. tempIndex = connectorIdInt -1;
  10971. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10972. {
  10973. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10974. {
  10975. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10976. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10977. {
  10978. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10979. {
  10980. meet = TRUE;
  10981. break;
  10982. }
  10983. }
  10984. }
  10985. }
  10986. }
  10987. else
  10988. {
  10989. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10990. {
  10991. tempIndex = 2;
  10992. }
  10993. else
  10994. {
  10995. tempIndex = (connectorIdInt -1);
  10996. }
  10997. for (int index = 0; index < AC_QUANTITY; index++)
  10998. {
  10999. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11000. {
  11001. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11002. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11003. {
  11004. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  11005. {
  11006. meet = TRUE;
  11007. break;
  11008. }
  11009. }
  11010. }
  11011. }
  11012. }
  11013. //check Transaction active
  11014. if(meet == FALSE)
  11015. {
  11016. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11017. goto end;
  11018. }
  11019. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  11020. {
  11021. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11022. goto end;
  11023. }
  11024. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11025. fptr1 = fopen(filename, "r");
  11026. if (!fptr1)
  11027. {
  11028. //file not exist
  11029. DEBUG_INFO("Unable to open the input file!!\n");
  11030. fptr1 = fopen(filename, "w+");
  11031. }
  11032. else
  11033. {
  11034. //Check Charging Profile Count
  11035. while(fscanf(fptr1, "%s", word) != EOF)
  11036. {
  11037. //DEBUG_INFO("word=%s\n",word);
  11038. if(strstr(word, "chargingProfileId")!= NULL)
  11039. {
  11040. //DEBUG_INFO("test chargingProfileId \n");
  11041. n_chargingProfile = n_chargingProfile + 1;
  11042. //DEBUG_INFO("chargingProfileId Found\n");
  11043. }
  11044. }
  11045. }
  11046. fclose(fptr1);
  11047. }
  11048. // Check ChargeProfileMaxStackLevel
  11049. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11050. {
  11051. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11052. goto end;
  11053. }
  11054. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11055. {
  11056. int i = 0;
  11057. char fnametemp[200]={0};
  11058. n_chargingProfile = 0;
  11059. //Check ChargePointMaxProfile.json exit
  11060. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11061. {
  11062. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11063. //Check Charging Profile Count
  11064. while(fscanf(fptr1, "%s", word) != EOF)
  11065. {
  11066. //DEBUG_INFO("word=%s\n",word);
  11067. if(strstr(word, "chargingProfileId")!= NULL)
  11068. {
  11069. //DEBUG_INFO("test chargingProfileId \n");
  11070. n_chargingProfile = n_chargingProfile + 1;
  11071. i = i + 1;
  11072. //DEBUG_INFO("chargingProfileId Found\n");
  11073. }
  11074. memset(word, 0, ARRAY_SIZE(word));
  11075. }
  11076. fclose(fptr1);
  11077. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  11078. }
  11079. //Check TxDefaultProfile_0.json exit
  11080. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  11081. {
  11082. i = 0;
  11083. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  11084. //Check Charging Profile Count
  11085. while(fscanf(fptr1, "%s", word) != EOF)
  11086. {
  11087. //DEBUG_INFO("word=%s\n",word);
  11088. if(strstr(word, "chargingProfileId")!= NULL)
  11089. {
  11090. //DEBUG_INFO("test chargingProfileId \n");
  11091. n_chargingProfile = n_chargingProfile + 1;
  11092. i = i + 1;
  11093. //DEBUG_INFO("chargingProfileId Found\n");
  11094. }
  11095. memset(word, 0, ARRAY_SIZE(word));
  11096. }
  11097. fclose(fptr1);
  11098. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  11099. }
  11100. //Check TxDefaultProfile_%d.json
  11101. for(int j=1; j <= gunTotalNumber; j++)
  11102. {
  11103. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11104. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  11105. if((access(fnametemp,F_OK))!=-1)
  11106. {
  11107. i = 0;
  11108. fptr1 = fopen(fnametemp, "r");
  11109. //Check Charging Profile Count
  11110. while(fscanf(fptr1, "%s", word) != EOF)
  11111. {
  11112. //DEBUG_INFO("word=%s\n",word);
  11113. if(strstr(word, "chargingProfileId")!= NULL)
  11114. {
  11115. //DEBUG_INFO("test chargingProfileId \n");
  11116. n_chargingProfile = n_chargingProfile + 1;
  11117. i = i + 1;
  11118. //DEBUG_INFO("chargingProfileId Found\n");
  11119. }
  11120. memset(word, 0, ARRAY_SIZE(word));
  11121. }
  11122. fclose(fptr1);
  11123. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11124. }
  11125. }
  11126. //Check TxProfile_%d.json
  11127. for(int j=1; j <= gunTotalNumber; j++)
  11128. {
  11129. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11130. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  11131. if((access(fnametemp,F_OK))!=-1)
  11132. {
  11133. i = 0;
  11134. fptr1 = fopen(fnametemp, "r");
  11135. //Check Charging Profile Count
  11136. while(fscanf(fptr1, "%s", word) != EOF)
  11137. {
  11138. //DEBUG_INFO("word=%s\n",word);
  11139. if(strstr(word, "chargingProfileId")!= NULL)
  11140. {
  11141. //DEBUG_INFO("test chargingProfileId \n");
  11142. n_chargingProfile = n_chargingProfile + 1;
  11143. i = i + 1;
  11144. //DEBUG_INFO("chargingProfileId Found\n");
  11145. }
  11146. memset(word, 0, ARRAY_SIZE(word));
  11147. }
  11148. fclose(fptr1);
  11149. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11150. }
  11151. }
  11152. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11153. {
  11154. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11155. goto end;
  11156. }
  11157. }
  11158. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11159. //**********************************Write to File********************************************************/
  11160. FILE *infile;
  11161. FILE *outfile;
  11162. infile = fopen (filename, "r");
  11163. outfile = fopen (tempfile, "w");
  11164. int d =0;
  11165. d = fgetc(infile);
  11166. rewind(infile);
  11167. if(d == EOF)
  11168. {
  11169. // Profile is empty
  11170. fprintf(outfile,"%s\n",payload);
  11171. fclose(infile);
  11172. fclose(outfile);
  11173. sprintf(rmFileCmd,"rm -f %s",filename);
  11174. system(rmFileCmd);
  11175. rename(tempfile, filename);
  11176. }
  11177. else
  11178. {
  11179. // Profile is not empty
  11180. char buf[2048]={0};
  11181. int ChargingProfileAdded = FALSE;
  11182. while (fgets(buf, sizeof(buf), infile) != NULL)
  11183. {
  11184. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  11185. json_object *tmpChargingProfile;
  11186. tmpChargingProfile = json_tokener_parse(buf);
  11187. if(!is_error(SetChargingProfile))
  11188. {
  11189. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  11190. {
  11191. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  11192. }
  11193. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11194. {
  11195. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11196. {
  11197. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11198. }
  11199. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11200. {
  11201. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  11202. }
  11203. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11204. {
  11205. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11206. }
  11207. }
  11208. }
  11209. json_object_put(tmpChargingProfile);
  11210. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  11211. {
  11212. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11213. {
  11214. //DEBUG_INFO("update set chargingProfile to file -0\n");
  11215. if(ChargingProfileAdded == FALSE)
  11216. {
  11217. fprintf(outfile,"%s\n",payload);
  11218. ChargingProfileAdded = TRUE;
  11219. }
  11220. }
  11221. else
  11222. {
  11223. if(tempstackLevelInt < stackLevelInt)
  11224. {
  11225. if(ChargingProfileAdded == FALSE)
  11226. {
  11227. fprintf(outfile,"%s\n",buf);
  11228. fprintf(outfile,"%s\n",payload);
  11229. ChargingProfileAdded = TRUE;
  11230. }
  11231. else
  11232. {
  11233. fprintf(outfile,"%s\n",buf);
  11234. }
  11235. }
  11236. else
  11237. {
  11238. if(ChargingProfileAdded == FALSE)
  11239. {
  11240. fprintf(outfile,"%s\n",buf);
  11241. fprintf(outfile,"%s\n",payload);
  11242. ChargingProfileAdded = TRUE;
  11243. }
  11244. else
  11245. {
  11246. fprintf(outfile,"%s\n",buf);
  11247. }
  11248. }
  11249. }
  11250. }
  11251. else
  11252. {
  11253. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11254. {
  11255. if(ChargingProfileAdded == FALSE)
  11256. {
  11257. fprintf(outfile,"%s\n",buf);
  11258. fprintf(outfile,"%s\n",payload);
  11259. ChargingProfileAdded = TRUE;
  11260. }
  11261. else
  11262. {
  11263. fprintf(outfile,"%s\n",buf);
  11264. }
  11265. }
  11266. else if(tempstackLevelInt < stackLevelInt)
  11267. {
  11268. if(ChargingProfileAdded == FALSE)
  11269. {
  11270. fprintf(outfile,"%s\n",buf);
  11271. fprintf(outfile,"%s\n",payload);
  11272. ChargingProfileAdded = TRUE;
  11273. }
  11274. else
  11275. {
  11276. fprintf(outfile,"%s\n",buf);
  11277. }
  11278. }
  11279. else
  11280. {
  11281. if(ChargingProfileAdded == FALSE)
  11282. {
  11283. fprintf(outfile,"%s\n",buf);
  11284. fprintf(outfile,"%s\n",payload);
  11285. ChargingProfileAdded = TRUE;
  11286. }
  11287. else
  11288. {
  11289. fprintf(outfile,"%s\n",buf);
  11290. }
  11291. }
  11292. }
  11293. } // end of while loop
  11294. fclose(infile);
  11295. fclose(outfile);
  11296. sprintf(rmFileCmd,"rm -f %s",filename);
  11297. system(rmFileCmd);
  11298. rename(tempfile, filename);
  11299. }
  11300. sleep(1);
  11301. result = TRUE;
  11302. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11303. end:
  11304. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11305. {
  11306. if(connectorIdInt == 0)
  11307. {
  11308. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11309. {
  11310. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11311. }
  11312. }
  11313. else
  11314. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11315. }
  11316. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11317. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11318. return result;
  11319. }
  11320. int handleTriggerMessageRequest(char *uuid, char *payload)
  11321. {
  11322. mtrace();
  11323. int result = FAIL;
  11324. int connectorIdIsNULL = FALSE;
  11325. int connectorIdInt =0;
  11326. char sstr[40]={0},sstrtemp[100]={ 0 };
  11327. char requestedMessagestr[40]={0};
  11328. char comfirmstr[20]={0};
  11329. int c = 0;
  11330. char *loc;
  11331. DEBUG_INFO("handleTriggerMessageRequest\n");
  11332. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11333. strcpy(sstrtemp, stringtrimspace(payload));
  11334. c = 0;
  11335. loc = strstr(sstrtemp, "requestedMessage");
  11336. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11337. {
  11338. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11339. c++;
  11340. }
  11341. sstr[c] = '\0';
  11342. strcpy(requestedMessagestr, sstr);
  11343. c = 0;
  11344. loc = strstr(sstrtemp, "connectorId");
  11345. if(loc == NULL)
  11346. {
  11347. connectorIdIsNULL = TRUE;
  11348. }
  11349. else
  11350. {
  11351. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11352. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11353. {
  11354. sstr[c] = loc[strlen("connectorId")+2+c];
  11355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11356. c++;
  11357. }
  11358. sstr[c] = '\0';
  11359. connectorIdInt = atoi(sstr);
  11360. }
  11361. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11362. {
  11363. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11364. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11365. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11366. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11367. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11368. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11369. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11370. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11371. {
  11372. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11373. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11374. return TRUE;
  11375. }
  11376. else
  11377. {
  11378. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11379. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11380. }
  11381. }
  11382. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11383. {
  11384. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11385. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11386. return TRUE;
  11387. }
  11388. //==========================
  11389. // Trigger message
  11390. //==========================
  11391. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11392. {
  11393. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11394. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11395. {
  11396. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11397. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11398. }
  11399. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11400. }
  11401. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11402. {
  11403. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11404. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11405. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11406. }
  11407. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11408. {
  11409. //sendBootNotificationRequest();
  11410. server_sign = FALSE;
  11411. }
  11412. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11413. {
  11414. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11415. }
  11416. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11417. {
  11418. if(connectorIdIsNULL == FALSE)
  11419. {
  11420. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11421. {
  11422. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11423. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11424. }
  11425. }
  11426. else
  11427. {
  11428. for(int idx=0;idx< gunTotalNumber;idx++)
  11429. {
  11430. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11431. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11432. }
  11433. }
  11434. }
  11435. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11436. {
  11437. if(connectorIdIsNULL == FALSE)
  11438. {
  11439. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11440. {
  11441. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11442. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11443. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11444. }
  11445. }
  11446. else
  11447. {
  11448. for(int idx=0;idx< gunTotalNumber;idx++)
  11449. {
  11450. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11451. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11452. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11453. }
  11454. }
  11455. }
  11456. return result;
  11457. }
  11458. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11459. {
  11460. mtrace();
  11461. int result = FAIL;
  11462. int connectorIdInt =0;
  11463. char comfirmstr[20]={0};
  11464. int tempIndex = 0;
  11465. json_object *UnlockConnector;
  11466. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11467. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11468. UnlockConnector = json_tokener_parse(payload);
  11469. if(!is_error(UnlockConnector))
  11470. {
  11471. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11472. {
  11473. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11474. }
  11475. }
  11476. json_object_put(UnlockConnector);
  11477. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11478. if(gunTotalNumber == 0)
  11479. {
  11480. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11481. goto end;
  11482. }
  11483. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11484. {
  11485. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11486. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11487. goto end;
  11488. }
  11489. else
  11490. {
  11491. //check Transaction active
  11492. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11493. {
  11494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11495. {
  11496. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11497. }
  11498. else
  11499. {
  11500. tempIndex = connectorIdInt -1;
  11501. }
  11502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11503. {
  11504. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11505. {
  11506. //stop Transaction
  11507. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11508. }
  11509. }
  11510. }
  11511. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11512. {
  11513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11514. {
  11515. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11516. }
  11517. else
  11518. {
  11519. tempIndex = connectorIdInt -1;
  11520. }
  11521. for (int index = 0; index < CCS_QUANTITY; index++)
  11522. {
  11523. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11524. {
  11525. //stop Transaction
  11526. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11527. }
  11528. }
  11529. }
  11530. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11531. {
  11532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11533. {
  11534. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11535. }
  11536. else
  11537. {
  11538. tempIndex = connectorIdInt -1;
  11539. }
  11540. for (int index = 0; index < GB_QUANTITY; index++)
  11541. {
  11542. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11543. {
  11544. //stop Transaction
  11545. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11546. }
  11547. }
  11548. }
  11549. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11550. {
  11551. tempIndex = connectorIdInt -1;
  11552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11553. {
  11554. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  11555. {
  11556. //stop Transaction
  11557. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11558. }
  11559. }
  11560. }
  11561. else
  11562. {
  11563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11564. {
  11565. tempIndex = 2;
  11566. }
  11567. else
  11568. {
  11569. tempIndex = connectorIdInt-1;
  11570. }
  11571. for (int index = 0; index < AC_QUANTITY; index++)
  11572. {
  11573. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11574. {
  11575. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11576. }
  11577. }
  11578. }
  11579. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11580. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11581. result = TRUE;
  11582. return result;
  11583. }
  11584. end:
  11585. //json_object_put(obj); --- remove temporally
  11586. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11587. return result;
  11588. }
  11589. static char UpdateFirmwarepayloadData[300]={0};
  11590. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11591. {
  11592. mtrace();
  11593. int result = FAIL;
  11594. pthread_t t;
  11595. sendUpdateFirmwareConfirmation(uuid);
  11596. memset(UpdateFirmwarepayloadData, 0, 300);
  11597. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11598. if(!interLock.isUpdateFirmwareGoing)
  11599. {
  11600. interLock.isUpdateFirmwareGoing = 1;
  11601. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11602. }
  11603. else
  11604. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11605. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11606. return result;
  11607. }
  11608. void *UpdateFirmwareProcess(void *data)
  11609. {
  11610. pthread_detach(pthread_self());
  11611. mtrace();
  11612. int retriesInt =0, retryIntervalInt=0;
  11613. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11614. int port=0;
  11615. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11616. int isSuccess = 0;
  11617. char ftpbuf[1024];
  11618. char temp[1024];
  11619. char * pch;
  11620. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11621. json_object *UpdateFirmware;
  11622. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11623. if(!is_error(UpdateFirmware))
  11624. {
  11625. // Required data
  11626. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11627. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11628. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11629. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11630. // Optional data
  11631. if(json_object_object_get(UpdateFirmware, "retries"))
  11632. {
  11633. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11634. }
  11635. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11636. {
  11637. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11638. }
  11639. }
  11640. json_object_put(UpdateFirmware);
  11641. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11642. memset(path, 0, ARRAY_SIZE(path));
  11643. // Wait retrieveData
  11644. if(strlen(retrieveDatestr) > 10)
  11645. {
  11646. do
  11647. {
  11648. sleep(1);
  11649. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11650. }
  11651. // Ready to download
  11652. system("rm -f /mnt/*");
  11653. if(strncmp(locationstr,"http", 4) == 0)
  11654. {
  11655. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11656. sprintf(ftppath,"/%s", path);
  11657. DEBUG_INFO("locationstr: %s\n", locationstr);
  11658. DEBUG_INFO("protocol: %s\n",protocol);
  11659. DEBUG_INFO("host: %s\n",host);
  11660. DEBUG_INFO("path: %s\n",path);
  11661. DEBUG_INFO("ftppath: %s\n",ftppath);
  11662. int ftppathlen=strlen(ftppath);
  11663. int i=1;
  11664. char filenametemp[50];
  11665. while(i < ftppathlen)
  11666. {
  11667. int len=ftppathlen-i;
  11668. if(ftppath[len]== 47) // '/' ascll code: 47
  11669. {
  11670. DEBUG_INFO("compare '/' all right\n");
  11671. break;
  11672. }
  11673. i=i+1;
  11674. }
  11675. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11676. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11677. filenametemp[i+1] = 0;
  11678. do
  11679. {
  11680. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11681. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11682. sleep(1);
  11683. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11684. if(!isSuccess)
  11685. {
  11686. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11687. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11688. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11689. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11690. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11691. }
  11692. else
  11693. {
  11694. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11695. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11696. }
  11697. retriesInt--;
  11698. }while((isSuccess == 0)&&(retriesInt >= 0));
  11699. }
  11700. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11701. {
  11702. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11703. memset(temp, 0, ARRAY_SIZE(temp));
  11704. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11705. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11706. int ftppathlen=strlen(ftpbuf);
  11707. int i=1;
  11708. char filenametemp[50];
  11709. while(i < ftppathlen)
  11710. {
  11711. int len=ftppathlen-i;
  11712. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11713. {
  11714. DEBUG_INFO(" compare '/' all right\n");
  11715. break;
  11716. }
  11717. i=i+1;
  11718. }
  11719. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11720. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11721. filenametemp[i+1] = 0;
  11722. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11723. pch=strchr(temp,'@');
  11724. if(pch==NULL)
  11725. {
  11726. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11727. protocol, host, &port, path);
  11728. strcpy(user,"anonymous");
  11729. strcpy(password,"");
  11730. }
  11731. else
  11732. {
  11733. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11734. protocol, user, password, host, &port, path);
  11735. }
  11736. sscanf(host,"%[^/]%s",host1, path1);
  11737. sprintf(ftppath,"%s", path1);
  11738. //DEBUG_INFO("protocol =%s\n",protocol);
  11739. //DEBUG_INFO("user =%s\n",user);
  11740. //DEBUG_INFO("password =%s\n",password);
  11741. //DEBUG_INFO("host1 =%s\n",host1);
  11742. //DEBUG_INFO("port =%d\n",port);
  11743. //DEBUG_INFO("path1 =%s\n",path1);
  11744. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11745. //ftpFile(host, user, password, port, ftppath, fname);
  11746. //download firmware pthred
  11747. if(port == 0)
  11748. {
  11749. port = 21;
  11750. }
  11751. do
  11752. {
  11753. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11754. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11755. sleep(1);
  11756. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11757. if(!isSuccess)
  11758. {
  11759. //BulldogUtil.sleepMs(interval*1000);
  11760. DEBUG_INFO("Update firmware request and download file fail.\n");
  11761. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11762. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11763. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11764. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11765. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11766. }
  11767. else
  11768. {
  11769. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11770. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11771. }
  11772. retriesInt--;
  11773. }while((!isSuccess)&&(retriesInt >= 0));
  11774. }
  11775. else
  11776. {
  11777. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11778. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11779. sleep(1);
  11780. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11781. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11782. }
  11783. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11784. interLock.isUpdateFirmwareGoing = 0;
  11785. pthread_exit(NULL);
  11786. }
  11787. int handleCertificateSignedRequest(char *uuid, char *payload)
  11788. {
  11789. mtrace();
  11790. int result = PASS;
  11791. json_object *CertificateSigned;
  11792. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11793. CertificateSigned = json_tokener_parse(payload);
  11794. if(!is_error(CertificateSigned))
  11795. {
  11796. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11797. }
  11798. json_object_put(CertificateSigned);
  11799. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11800. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11801. fclose(fp);
  11802. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11803. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11804. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11805. sendCertificateSignedConfirmation(uuid);
  11806. return result;
  11807. }
  11808. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11809. {
  11810. mtrace();
  11811. int result = PASS;
  11812. json_object *DeleteCertificate;
  11813. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11814. DeleteCertificate = json_tokener_parse(payload);
  11815. if(!is_error(DeleteCertificate))
  11816. {
  11817. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11818. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11819. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11820. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11821. }
  11822. json_object_put(DeleteCertificate);
  11823. /*
  11824. * TODO: Delete certificateSigned process
  11825. */
  11826. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11827. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11828. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11829. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11830. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11831. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11832. sendDeleteCertificateConfirmation(uuid);
  11833. return result;
  11834. }
  11835. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11836. {
  11837. mtrace();
  11838. int result = PASS;
  11839. json_object *ExtendedTriggerMessage;
  11840. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11841. ExtendedTriggerMessage = json_tokener_parse(payload);
  11842. if(!is_error(ExtendedTriggerMessage))
  11843. {
  11844. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11845. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11846. {
  11847. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11848. }
  11849. else
  11850. {
  11851. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11852. }
  11853. }
  11854. json_object_put(ExtendedTriggerMessage);
  11855. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11856. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11857. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11858. {
  11859. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11860. }
  11861. else
  11862. {
  11863. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11864. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11865. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11866. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11867. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11868. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11869. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11870. {
  11871. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11872. }
  11873. else
  11874. {
  11875. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11876. }
  11877. }
  11878. sendExtendedTriggerMessageConfirmation(uuid);
  11879. //==========================
  11880. // Trigger message
  11881. //==========================
  11882. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11883. {
  11884. //sendBootNotificationRequest();
  11885. server_sign = FALSE;
  11886. }
  11887. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11888. {
  11889. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11890. }
  11891. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11892. {
  11893. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11894. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11895. {
  11896. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11897. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11898. }
  11899. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11900. }
  11901. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11902. {
  11903. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11904. }
  11905. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11906. {
  11907. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11908. {
  11909. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11910. }
  11911. else
  11912. {
  11913. for(int idx=0;idx< gunTotalNumber;idx++)
  11914. {
  11915. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11916. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11917. }
  11918. }
  11919. }
  11920. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11921. {
  11922. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11923. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11924. {
  11925. system("openssl req -newkey rsa:2048 -out /Storage/OCPP/certCP.csr -nodes -keyout /Storage/OCPP/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  11926. }
  11927. }
  11928. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11929. {
  11930. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11931. {
  11932. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11933. }
  11934. else
  11935. {
  11936. for(int idx=0;idx< gunTotalNumber;idx++)
  11937. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11938. }
  11939. }
  11940. return result;
  11941. }
  11942. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11943. {
  11944. mtrace();
  11945. int result = PASS;
  11946. json_object *GetInstalledCertificateIds;
  11947. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11948. GetInstalledCertificateIds = json_tokener_parse(payload);
  11949. if(!is_error(GetInstalledCertificateIds))
  11950. {
  11951. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11952. }
  11953. json_object_put(GetInstalledCertificateIds);
  11954. /*
  11955. * TODO: Return installed certificate process
  11956. */
  11957. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11958. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11959. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11960. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11961. sendGetInstalledCertificateIdsConfirmation(uuid);
  11962. return result;
  11963. }
  11964. int handleGetLogRequest(char *uuid, char *payload)
  11965. {
  11966. mtrace();
  11967. int result = PASS;
  11968. json_object *GetLog;
  11969. DEBUG_INFO("handleGetLogRequest...\n");
  11970. GetLog = json_tokener_parse(payload);
  11971. if(!is_error(GetLog))
  11972. {
  11973. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11974. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11975. if(json_object_object_get(GetLog, "retries") != NULL)
  11976. {
  11977. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11978. }
  11979. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11980. {
  11981. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11982. }
  11983. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11984. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11985. {
  11986. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11987. }
  11988. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11989. {
  11990. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11991. }
  11992. }
  11993. json_object_put(GetLog);
  11994. /*
  11995. * TODO: Upload log process
  11996. */
  11997. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11998. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11999. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  12000. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  12001. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  12002. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  12003. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  12004. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  12005. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  12006. sendGetLogConfirmation(uuid);
  12007. return result;
  12008. }
  12009. int handleInstallCertificateRequest(char *uuid, char *payload)
  12010. {
  12011. mtrace();
  12012. int result = PASS;
  12013. json_object *InstallCertificate;
  12014. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12015. InstallCertificate = json_tokener_parse(payload);
  12016. if(!is_error(InstallCertificate))
  12017. {
  12018. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12019. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12020. /*
  12021. * TODO: Install certificate process
  12022. */
  12023. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12024. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12025. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12026. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12027. sendInstallCertificateConfirmation(uuid);
  12028. }
  12029. json_object_put(InstallCertificate);
  12030. return result;
  12031. }
  12032. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12033. {
  12034. mtrace();
  12035. int result = PASS;
  12036. json_object *SignedUpdateFirmware;
  12037. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12038. SignedUpdateFirmware = json_tokener_parse(payload);
  12039. if(!is_error(SignedUpdateFirmware))
  12040. {
  12041. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12042. {
  12043. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12044. }
  12045. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12046. {
  12047. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12048. }
  12049. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12050. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12051. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12052. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12053. {
  12054. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12055. }
  12056. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12057. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12058. }
  12059. json_object_put(SignedUpdateFirmware);
  12060. /*
  12061. * TODO: Upgrade firmware process
  12062. */
  12063. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12064. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12065. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12066. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12067. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12068. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12069. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12070. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12071. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12072. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12073. sendInstallCertificateConfirmation(uuid);
  12074. return result;
  12075. }
  12076. int handleUnknownRequest(char *uuid, char *payload)
  12077. {
  12078. mtrace();
  12079. int result = PASS;
  12080. DEBUG_INFO("handleUnknownRequest...\n");
  12081. sendUnknownConfirmation(uuid);
  12082. result = PASS;
  12083. return result;
  12084. }
  12085. //==========================================
  12086. // Handle server response routine
  12087. //==========================================
  12088. void handleAuthorizeResponse(char *payload, int gun_index)
  12089. {
  12090. mtrace();
  12091. char expiryDatestr[30]={0};
  12092. char parentIdTagstr[20]={0};
  12093. char statusstr[20]={0};
  12094. int expiryDateISNULL=FALSE;
  12095. int parentIdTagISNULL=FALSE;
  12096. DEBUG_INFO("handleAuthorizeResponse...\n");
  12097. json_object *Authorize;
  12098. Authorize = json_tokener_parse(payload);
  12099. if(!is_error(Authorize))
  12100. {
  12101. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12102. {
  12103. // Required data
  12104. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12105. // Optional data
  12106. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12107. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12108. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12109. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12110. }
  12111. }
  12112. json_object_put(Authorize);
  12113. if(expiryDateISNULL == FALSE)
  12114. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12115. if(parentIdTagISNULL == FALSE)
  12116. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12117. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12118. //Update idTag information to authorization cache if supproted
  12119. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12120. {
  12121. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12122. }
  12123. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12124. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12125. authorizeRetryTimes = 0;
  12126. }
  12127. void handleBootNotificationResponse(char *payload, int gun_index)
  12128. {
  12129. mtrace();
  12130. char statusStr[12]={0};
  12131. char currentTimeStr[30]={0};
  12132. int intervalInt = 0;
  12133. DEBUG_INFO("handleBootNotificationResponse...\n");
  12134. json_object *BootNotification;
  12135. BootNotification = json_tokener_parse(payload);
  12136. if(!is_error(BootNotification))
  12137. {
  12138. // Required data
  12139. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12140. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12141. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12142. }
  12143. json_object_put(BootNotification);
  12144. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12145. BootNotificationInterval = intervalInt;
  12146. HeartBeatWaitTime = intervalInt;
  12147. //write back to ShmOCPP16Data->BootNotification
  12148. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12149. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12150. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12151. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12152. {
  12153. server_sign = TRUE;
  12154. server_pending =FALSE;
  12155. }
  12156. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12157. {
  12158. server_pending = TRUE;
  12159. }
  12160. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12161. srand(time(NULL));
  12162. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12163. SetOcppConnStatus(TRUE);
  12164. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12165. }
  12166. void handleDataTransferResponse(char *payload, int gun_index)
  12167. {
  12168. char sstr[160]={0};//sstr[200]={ 0 };
  12169. int c = 0;
  12170. char *loc;
  12171. DEBUG_INFO("handleDataTransferResponse ...\n");
  12172. loc = strstr(payload, "status");
  12173. c = 0;
  12174. while (loc[3+strlen("status")+c] != '\"')
  12175. {
  12176. sstr[c] = loc[3+strlen("status")+c];
  12177. c++;
  12178. }
  12179. sstr[c] = '\0';
  12180. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12181. }
  12182. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12183. {
  12184. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12185. //struct json_object *obj;
  12186. // obj = json_tokener_parse(payload);
  12187. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12188. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12189. //No fields are defined.
  12190. }
  12191. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12192. {
  12193. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12194. //struct json_object *obj;
  12195. // obj = json_tokener_parse(payload);
  12196. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12197. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12198. //No fields are defined.
  12199. }
  12200. void handleHeartbeatResponse(char *payload, int gun_index)
  12201. {
  12202. mtrace();
  12203. DEBUG_INFO("handleHeartbeatResponse...\n");
  12204. json_object *Heartbeat;
  12205. Heartbeat = json_tokener_parse(payload);
  12206. if(!is_error(Heartbeat))
  12207. {
  12208. // Required data
  12209. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12210. }
  12211. json_object_put(Heartbeat);
  12212. if(FirstHeartBeat == 0)
  12213. {
  12214. FirstHeartBeat = 1;
  12215. DEBUG_INFO("FirstHeartBeat \n");
  12216. }
  12217. HeartBeatWithNOResponse = 0;
  12218. clientTime.Heartbeat=time((time_t*)NULL);
  12219. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12220. }
  12221. void handleMeterValuesResponse(char *payload, int gun_index)
  12222. {
  12223. mtrace();
  12224. DEBUG_INFO("handleMeterValuesResponse...\n");
  12225. }
  12226. void handleStartTransactionResponse(char *payload, int gun_index)
  12227. {
  12228. mtrace();
  12229. //int transactionIdInt = 0;
  12230. FILE *outfile;
  12231. char data[100]={0};
  12232. DEBUG_INFO("handleStartTransactionResponse...\n");
  12233. json_object *StartTransaction;
  12234. StartTransaction = json_tokener_parse(payload);
  12235. if(!is_error(StartTransaction))
  12236. {
  12237. // Required data
  12238. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12239. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12240. // Optional data
  12241. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12242. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12243. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12244. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12245. }
  12246. json_object_put(StartTransaction);
  12247. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12248. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12249. //-----------Start : write to the Queue TransactionId file -----------------//
  12250. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12251. {}
  12252. else
  12253. {
  12254. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12255. if(log == NULL)
  12256. {
  12257. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12258. return ;
  12259. }
  12260. else
  12261. {
  12262. fclose(log);
  12263. }
  12264. }
  12265. // open file for writing
  12266. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12267. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12268. {
  12269. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12270. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12271. fputs(data, outfile);
  12272. fclose (outfile);
  12273. }
  12274. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12275. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12276. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12277. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12278. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12279. }
  12280. void handleStatusNotificationResponse(char *payload, int gun_index)
  12281. {
  12282. mtrace();
  12283. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12284. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12285. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12286. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12287. }
  12288. void handleStopTransactionnResponse(char *payload, int gun_index)
  12289. {
  12290. mtrace();
  12291. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12292. json_object *StopTransaction;
  12293. StopTransaction = json_tokener_parse(payload);
  12294. if(!is_error(StopTransaction))
  12295. {
  12296. // Optional data
  12297. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12298. {
  12299. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12300. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12302. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12304. }
  12305. }
  12306. json_object_put(StopTransaction);
  12307. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12308. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12309. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12310. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12311. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12312. }
  12313. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12314. {
  12315. mtrace();
  12316. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12317. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12318. }
  12319. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12320. {
  12321. mtrace();
  12322. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12323. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12324. }
  12325. void handleSignCertificateResponse(char *payload, int gun_index)
  12326. {
  12327. mtrace();
  12328. DEBUG_INFO("handleSignCertificateResponse...\n");
  12329. json_object *SignCertificate;
  12330. SignCertificate = json_tokener_parse(payload);
  12331. if(!is_error(SignCertificate))
  12332. {
  12333. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12334. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12335. }
  12336. json_object_put(SignCertificate);
  12337. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12338. }
  12339. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12340. {
  12341. mtrace();
  12342. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12343. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12344. }
  12345. //==========================================
  12346. // Handle Error routine
  12347. //==========================================
  12348. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12349. {
  12350. mtrace();
  12351. #ifdef SystemLogMessage
  12352. DEBUG_INFO("errorCode: %s\n", errorCode);
  12353. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12354. DEBUG_INFO("errorDetails: %s\n", payload);
  12355. #endif
  12356. }
  12357. //===============================================
  12358. // Common routine
  12359. //===============================================
  12360. int initialConfigurationTable(void)
  12361. {
  12362. //clock_t start_t, end_t, total_t;
  12363. FILE *fp;
  12364. FILE *outfile;
  12365. char str[512]={0};
  12366. char sstr[256]={0};
  12367. int c = 0;
  12368. char *loc;
  12369. int confVersion = 8;
  12370. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12371. //start_t = clock();
  12372. //printf("Starting of the program, start_t = %ld\n", start_t);
  12373. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12374. // Check configuration file size is correct
  12375. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12376. {
  12377. struct stat st;
  12378. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12379. if(st.st_size < 3100)
  12380. {
  12381. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12382. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12383. }
  12384. }
  12385. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12386. {
  12387. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12388. if(outfile == NULL)
  12389. {
  12390. DEBUG_INFO("Error opening file\n");
  12391. return FALSE;
  12392. }
  12393. /*Core Profile*/
  12394. //AllowOfflineTxForUnknownId
  12395. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12399. //AuthorizationCacheEnabled
  12400. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12404. //AuthorizeRemoteTxRequests
  12405. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12409. //BlinkRepeat
  12410. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12414. //ClockAlignedDataInterval
  12415. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12419. //ConnectionTimeOut
  12420. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12424. //GetConfigurationMaxKeys
  12425. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12429. // HeartbeatInterval
  12430. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12432. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12434. // LightIntensity
  12435. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12439. // LocalAuthorizeOffline
  12440. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12444. // LocalPreAuthorize
  12445. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12446. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12448. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12449. // MaxEnergyOnInvalidId
  12450. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12452. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12454. // MeterValuesAlignedData
  12455. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12457. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12459. else
  12460. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12462. // MeterValuesAlignedDataMaxLength
  12463. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12467. else
  12468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12470. // MeterValuesSampledData
  12471. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12473. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12475. else
  12476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12477. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12478. // MeterValuesSampledDataMaxLength
  12479. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12480. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12483. else
  12484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12486. // MeterValueSampleInterval
  12487. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12488. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12491. // MinimumStatusDuration
  12492. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12494. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12495. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12497. // NumberOfConnectors
  12498. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12500. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12501. {
  12502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12503. }
  12504. else
  12505. {
  12506. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12507. }
  12508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12509. // ResetRetries
  12510. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12513. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12514. // ConnectorPhaseRotation
  12515. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12518. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12519. // ConnectorPhaseRotationMaxLength
  12520. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12522. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12524. // StopTransactionOnEVSideDisconnect
  12525. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12529. // StopTransactionOnInvalidId
  12530. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12534. // StopTxnAlignedData
  12535. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12539. // StopTxnAlignedDataMaxLength
  12540. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12543. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12544. // StopTxnSampledData
  12545. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12549. else
  12550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12552. // StopTxnSampledDataMaxLength
  12553. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12555. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12556. {
  12557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12558. }
  12559. else
  12560. {
  12561. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12562. }
  12563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12564. // SupportedFeatureProfiles
  12565. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12569. // SupportedFeatureProfilesMaxLength
  12570. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12574. // TransactionMessageAttempts
  12575. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12578. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12580. // TransactionMessageRetryInterval
  12581. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12584. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12586. // UnlockConnectorOnEVSideDisconnect
  12587. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12591. // WebSocketPingInterval
  12592. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12596. // QueueOffLineMeterValues
  12597. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12601. // AuthorizationKey
  12602. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12606. // SecurityProfile
  12607. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12611. // DefaultPrice
  12612. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12615. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12616. // CustomDisplayCostAndPrice
  12617. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12620. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12621. // CustomIdleFeeAfterStop
  12622. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12626. // TimeOffset
  12627. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12631. // NextTimeOffsetTransitionDateTime
  12632. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12636. // TimeOffsetNextTransition
  12637. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12641. // Configuration Version
  12642. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12646. //* Local Auth List Management Profile*/
  12647. #if 0
  12648. //For OCTT Test Case
  12649. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12652. #endif
  12653. #if 1
  12654. //LocalAuthListEnabled
  12655. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12659. #endif
  12660. //LocalAuthListMaxLength
  12661. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12665. //SendLocalListMaxLength
  12666. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12670. //ReserveConnectorZeroSupported
  12671. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12675. //* Smart Charging Profile */
  12676. //ChargeProfileMaxStackLevel
  12677. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12681. // ChargingScheduleAllowedChargingRateUnit
  12682. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12686. // ChargingScheduleMaxPeriods
  12687. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12691. // ConnectorSwitch3to1PhaseSupported
  12692. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12696. // MaxChargingProfilesInstalled
  12697. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12701. fclose(outfile);
  12702. }
  12703. else
  12704. {
  12705. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12706. char keystr[60]={0};
  12707. char readonlystr[10]={0};
  12708. char valuestr[256]={0};
  12709. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12710. if(fp == NULL) {
  12711. DEBUG_INFO("Error opening file");
  12712. return FALSE;
  12713. }
  12714. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12715. {
  12716. //DEBUG_INFO("Get Configuration \n");
  12717. if(strlen(str) > 0)
  12718. {
  12719. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12720. //*************************key*********************************/
  12721. if(strstr(str, "key") != NULL)
  12722. {
  12723. loc = strstr(str, "key");
  12724. c = 0;
  12725. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12726. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12727. {
  12728. sstr[c] = loc[strlen("key")+3+c];
  12729. c++;
  12730. }
  12731. sstr[c] = '\0';
  12732. strcpy(keystr,sstr);
  12733. }
  12734. //*************************readonly*********************************/
  12735. if(strstr(str, "readonly") != NULL)
  12736. {
  12737. loc = strstr(str, "readonly");
  12738. c = 0;
  12739. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12740. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12741. {
  12742. sstr[c] = loc[strlen("readonly")+2+c];
  12743. c++;
  12744. }
  12745. sstr[c] = '\0';
  12746. strcpy(readonlystr,sstr);
  12747. }
  12748. //*************************value*********************************/
  12749. if(strstr(str, "value") != NULL)
  12750. {
  12751. loc = strstr(str, "value");
  12752. c = 0;
  12753. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12754. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12755. {
  12756. sstr[c] = loc[strlen("value")+3+c];
  12757. c++;
  12758. }
  12759. sstr[c] = '\0';
  12760. strcpy(valuestr,sstr);
  12761. }
  12762. // DEBUG_INFO("keystr=%s\n",keystr);
  12763. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12764. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12765. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12766. {
  12767. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12768. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12770. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12771. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12772. }
  12773. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12774. {
  12775. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12776. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12778. }
  12779. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12780. {
  12781. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12783. }
  12784. if(strcmp(keystr, "BlinkRepeat") == 0)
  12785. {
  12786. //Charger.BlinkRepeat = Integer.parseInt(value);
  12787. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12789. }
  12790. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12791. {
  12792. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12793. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12794. }
  12795. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12796. {
  12797. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12799. }
  12800. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12801. {
  12802. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12804. }
  12805. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12806. {
  12807. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12809. HeartBeatWaitTime = atoi(valuestr);
  12810. }
  12811. if(strcmp(keystr, "LightIntensity") == 0)
  12812. {
  12813. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12815. }
  12816. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12817. {
  12818. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12820. }
  12821. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12822. {
  12823. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12825. }
  12826. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12827. {
  12828. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12829. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12830. }
  12831. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12832. {
  12833. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12835. }
  12836. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12837. {
  12838. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12840. }
  12841. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12842. {
  12843. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12845. }
  12846. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12847. {
  12848. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12849. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12850. }
  12851. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12852. {
  12853. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12855. }
  12856. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12857. {
  12858. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12860. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12861. }
  12862. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12863. {
  12864. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12866. }
  12867. if(strcmp(keystr, "ResetRetries") == 0)
  12868. {
  12869. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12871. }
  12872. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12873. {
  12874. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12876. }
  12877. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12878. {
  12879. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12881. }
  12882. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12883. {
  12884. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12886. }
  12887. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12888. {
  12889. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12891. }
  12892. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12893. {
  12894. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12896. }
  12897. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12898. {
  12899. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12901. }
  12902. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12903. {
  12904. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12906. }
  12907. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12908. {
  12909. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12910. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12911. }
  12912. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12913. {
  12914. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12916. }
  12917. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12918. {
  12919. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12921. }
  12922. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12923. {
  12924. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12926. TransactionMessageAttemptsValue = atoi(valuestr);
  12927. }
  12928. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12929. {
  12930. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12932. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12933. }
  12934. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12935. {
  12936. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12938. }
  12939. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12940. {
  12941. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12943. }
  12944. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12945. {
  12946. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12948. }
  12949. if(strcmp(keystr, "AuthorizationKey") == 0)
  12950. {
  12951. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12952. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12954. }
  12955. if(strcmp(keystr, "SecurityProfile") == 0)
  12956. {
  12957. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12959. }
  12960. if(strcmp(keystr, "DefaultPrice") == 0)
  12961. {
  12962. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12964. }
  12965. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12966. {
  12967. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12969. }
  12970. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12971. {
  12972. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12974. }
  12975. if(strcmp(keystr, "TimeOffset") == 0)
  12976. {
  12977. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12979. }
  12980. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12981. {
  12982. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12984. }
  12985. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12986. {
  12987. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12989. }
  12990. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12991. {
  12992. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12994. }
  12995. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12996. {
  12997. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12999. }
  13000. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13001. {
  13002. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13004. }
  13005. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13006. {
  13007. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13009. }
  13010. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13011. {
  13012. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13014. }
  13015. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13016. {
  13017. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13019. }
  13020. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13021. {
  13022. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13024. }
  13025. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13026. {
  13027. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13029. }
  13030. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13031. {
  13032. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13034. }
  13035. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13036. {
  13037. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13039. }
  13040. }
  13041. }
  13042. fclose(fp);
  13043. }
  13044. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13045. {
  13046. return PASS;
  13047. }
  13048. else
  13049. {
  13050. return FAIL;
  13051. }
  13052. }
  13053. void StoreConfigurationTable(void)
  13054. {
  13055. FILE *outfile;
  13056. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13057. if(outfile == NULL)
  13058. {
  13059. DEBUG_INFO("Error opening file");
  13060. return ;
  13061. }
  13062. /*Core Profile*/
  13063. //AllowOfflineTxForUnknownId
  13064. /*
  13065. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13066. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13069. */
  13070. //DEBUG_INFO("data=%s\n",data);
  13071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13072. //AuthorizationCacheEnabled
  13073. /*
  13074. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13077. */
  13078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13079. //AuthorizeRemoteTxRequests
  13080. /*
  13081. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13084. */
  13085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13086. //BlinkRepeat
  13087. /*
  13088. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13091. */
  13092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13093. //ClockAlignedDataInterval
  13094. /*
  13095. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13098. */
  13099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13100. //ConnectionTimeOut
  13101. /*
  13102. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13105. */
  13106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13107. //GetConfigurationMaxKeys
  13108. /*
  13109. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13112. */
  13113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13114. // HeartbeatInterval
  13115. /*
  13116. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13119. */
  13120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13121. // LightIntensity
  13122. /*
  13123. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13126. */
  13127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13128. // LocalAuthorizeOffline
  13129. /*
  13130. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13133. */
  13134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13135. // LocalPreAuthorize
  13136. /*
  13137. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13140. */
  13141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13142. // MaxEnergyOnInvalidId
  13143. /*
  13144. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13147. */
  13148. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13150. // MeterValuesAlignedData
  13151. /*
  13152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13155. */
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13157. // MeterValuesAlignedDataMaxLength
  13158. /*
  13159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13162. */
  13163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13164. // MeterValuesSampledData
  13165. /*
  13166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13169. */
  13170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13171. // MeterValuesSampledDataMaxLength
  13172. /*
  13173. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13176. */
  13177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13178. // MeterValueSampleInterval
  13179. /*
  13180. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13183. */
  13184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13185. // MinimumStatusDuration
  13186. /*
  13187. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13190. */
  13191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13192. // NumberOfConnectors
  13193. /*
  13194. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13196. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13197. {
  13198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13199. }
  13200. else
  13201. {
  13202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13203. }
  13204. */
  13205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13206. // ResetRetries
  13207. /*
  13208. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13211. */
  13212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13213. // ConnectorPhaseRotation
  13214. /*
  13215. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13218. */
  13219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13220. // ConnectorPhaseRotationMaxLength
  13221. /*
  13222. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13225. */
  13226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13227. // StopTransactionOnEVSideDisconnect
  13228. /*
  13229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13232. */
  13233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13234. // StopTransactionOnInvalidId
  13235. /*
  13236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13239. */
  13240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13241. // StopTxnAlignedData
  13242. /*
  13243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13246. */
  13247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13248. // StopTxnAlignedDataMaxLength
  13249. /*
  13250. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13253. */
  13254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13255. // StopTxnSampledData
  13256. /*
  13257. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13260. */
  13261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13262. // StopTxnSampledDataMaxLength
  13263. /*
  13264. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13267. */
  13268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13269. // SupportedFeatureProfiles
  13270. /*
  13271. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13274. */
  13275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13276. // SupportedFeatureProfilesMaxLength
  13277. /*
  13278. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13281. */
  13282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13283. // TransactionMessageAttempts
  13284. /*
  13285. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13288. */
  13289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13290. // TransactionMessageRetryInterval
  13291. /*
  13292. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13295. */
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13297. // UnlockConnectorOnEVSideDisconnect
  13298. /*
  13299. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13302. */
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13304. // WebSocketPingInterval
  13305. /*
  13306. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13309. */
  13310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13311. // QueueOffLineMeterValues
  13312. /*
  13313. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13316. */
  13317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13318. // AuthorizationKey
  13319. /*
  13320. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13323. */
  13324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13325. // SecurityProfile
  13326. /*
  13327. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13330. */
  13331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13332. // DefaultPrice
  13333. /*
  13334. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13337. */
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13339. // CustomDisplayCostAndPrice
  13340. /*
  13341. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13344. */
  13345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13346. // CustomIdleFeeAfterStop
  13347. /*
  13348. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13351. */
  13352. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13353. // TimeOffset
  13354. /*
  13355. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13358. */
  13359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13360. // NextTimeOffsetTransitionDateTime
  13361. /*
  13362. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13365. */
  13366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13367. // TimeOffsetNextTransition
  13368. /*
  13369. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13372. */
  13373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13374. // ConfigurationVersion
  13375. /*
  13376. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13378. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13379. */
  13380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13381. //* Local Auth List Management Profile*/
  13382. //LocalAuthListEnabled
  13383. /*
  13384. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13387. */
  13388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13389. //LocalAuthListMaxLength
  13390. /*
  13391. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13394. */
  13395. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13396. //SendLocalListMaxLength
  13397. /*
  13398. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13401. */
  13402. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13403. //ReserveConnectorZeroSupported
  13404. /*
  13405. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13408. */
  13409. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13410. //* Smart Charging Profile */
  13411. //ChargeProfileMaxStackLevel
  13412. /*
  13413. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13416. */
  13417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13418. // ChargingScheduleAllowedChargingRateUnit
  13419. /*
  13420. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13423. */
  13424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13425. // ChargingScheduleMaxPeriods
  13426. /*
  13427. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13430. */
  13431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13432. // ConnectorSwitch3to1PhaseSupported
  13433. /*
  13434. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13437. */
  13438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13439. // MaxChargingProfilesInstalled
  13440. /*
  13441. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13444. */
  13445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13446. fclose(outfile);
  13447. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13448. }
  13449. void getKeyValue(char *keyReq)
  13450. {
  13451. int isEmpty = FALSE;
  13452. int isKnowKey = FALSE;
  13453. DEBUG_INFO("keyReq = %s\n", keyReq);
  13454. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13455. isEmpty = TRUE;
  13456. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13457. {
  13458. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13461. {
  13462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13463. }
  13464. else
  13465. {
  13466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13467. }
  13468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13469. isKnowKey = TRUE;
  13470. }
  13471. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13472. {
  13473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13476. {
  13477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13478. }
  13479. else
  13480. {
  13481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13482. }
  13483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13484. isKnowKey = TRUE;
  13485. }
  13486. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13487. {
  13488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13491. {
  13492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13493. }
  13494. else
  13495. {
  13496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13497. }
  13498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13499. isKnowKey = TRUE;
  13500. }
  13501. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13502. {
  13503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13506. {
  13507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13508. }
  13509. else
  13510. {
  13511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13512. }
  13513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13514. isKnowKey = TRUE;
  13515. }
  13516. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13517. {
  13518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13521. {
  13522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13523. }
  13524. else
  13525. {
  13526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13527. }
  13528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13529. isKnowKey = TRUE;
  13530. }
  13531. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13532. {
  13533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13536. {
  13537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13538. }
  13539. else
  13540. {
  13541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13542. }
  13543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13544. isKnowKey = TRUE;
  13545. }
  13546. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13547. {
  13548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13551. {
  13552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13553. }
  13554. else
  13555. {
  13556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13557. }
  13558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13559. isKnowKey = TRUE;
  13560. }
  13561. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13562. {
  13563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13566. {
  13567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13568. }
  13569. else
  13570. {
  13571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13572. }
  13573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13574. isKnowKey = TRUE;
  13575. }
  13576. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13577. {
  13578. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13580. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13581. {
  13582. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13583. }
  13584. else
  13585. {
  13586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13587. }
  13588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13589. isKnowKey = TRUE;
  13590. }
  13591. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13592. {
  13593. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13596. {
  13597. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13598. }
  13599. else
  13600. {
  13601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13602. }
  13603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13604. isKnowKey = TRUE;
  13605. }
  13606. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13607. {
  13608. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13611. {
  13612. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13613. }
  13614. else
  13615. {
  13616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13617. }
  13618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13619. isKnowKey = TRUE;
  13620. }
  13621. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13622. {
  13623. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13626. {
  13627. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13628. }
  13629. else
  13630. {
  13631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13632. }
  13633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13634. isKnowKey = TRUE;
  13635. }
  13636. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13637. {
  13638. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13641. {
  13642. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13643. }
  13644. else
  13645. {
  13646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13647. }
  13648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13649. isKnowKey = TRUE;
  13650. }
  13651. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13652. {
  13653. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13655. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13656. {
  13657. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13658. }
  13659. else
  13660. {
  13661. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13662. }
  13663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13664. isKnowKey = TRUE;
  13665. }
  13666. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13667. {
  13668. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13670. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13671. {
  13672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13673. }
  13674. else
  13675. {
  13676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13677. }
  13678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13679. isKnowKey = TRUE;
  13680. }
  13681. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13682. {
  13683. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13685. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13686. {
  13687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13688. }
  13689. else
  13690. {
  13691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13692. }
  13693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13694. isKnowKey = TRUE;
  13695. }
  13696. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13697. {
  13698. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13700. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13701. {
  13702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13703. }
  13704. else
  13705. {
  13706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13707. }
  13708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13709. isKnowKey = TRUE;
  13710. }
  13711. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13712. {
  13713. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13715. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13716. {
  13717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13718. }
  13719. else
  13720. {
  13721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13722. }
  13723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13724. isKnowKey = TRUE;
  13725. }
  13726. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13727. {
  13728. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13730. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13731. {
  13732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13733. }
  13734. else
  13735. {
  13736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13737. }
  13738. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13740. isKnowKey = TRUE;
  13741. }
  13742. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13743. {
  13744. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13747. {
  13748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13749. }
  13750. else
  13751. {
  13752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13753. }
  13754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13755. isKnowKey = TRUE;
  13756. }
  13757. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13758. {
  13759. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13762. {
  13763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13764. }
  13765. else
  13766. {
  13767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13768. }
  13769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13770. isKnowKey = TRUE;
  13771. }
  13772. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13773. {
  13774. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13777. {
  13778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13779. }
  13780. else
  13781. {
  13782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13783. }
  13784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13785. isKnowKey = TRUE;
  13786. }
  13787. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13788. {
  13789. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13792. {
  13793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13794. }
  13795. else
  13796. {
  13797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13798. }
  13799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13800. isKnowKey = TRUE;
  13801. }
  13802. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13803. {
  13804. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13807. {
  13808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13809. }
  13810. else
  13811. {
  13812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13813. }
  13814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13815. isKnowKey = TRUE;
  13816. }
  13817. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13818. {
  13819. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13822. {
  13823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13824. }
  13825. else
  13826. {
  13827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13828. }
  13829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13830. isKnowKey = TRUE;
  13831. }
  13832. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13833. {
  13834. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13837. {
  13838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13839. }
  13840. else
  13841. {
  13842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13843. }
  13844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13845. isKnowKey = TRUE;
  13846. }
  13847. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13848. {
  13849. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13852. {
  13853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13854. }
  13855. else
  13856. {
  13857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13858. }
  13859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13860. isKnowKey = TRUE;
  13861. }
  13862. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13863. {
  13864. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13867. {
  13868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13869. }
  13870. else
  13871. {
  13872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13873. }
  13874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13875. isKnowKey = TRUE;
  13876. }
  13877. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13878. {
  13879. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13882. {
  13883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13884. }
  13885. else
  13886. {
  13887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13888. }
  13889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13890. isKnowKey = TRUE;
  13891. }
  13892. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13893. {
  13894. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13897. {
  13898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13899. }
  13900. else
  13901. {
  13902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13903. }
  13904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13905. isKnowKey = TRUE;
  13906. }
  13907. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13908. {
  13909. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13911. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13912. {
  13913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13914. }
  13915. else
  13916. {
  13917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13918. }
  13919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13920. isKnowKey = TRUE;
  13921. }
  13922. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13923. {
  13924. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13926. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13927. {
  13928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13929. }
  13930. else
  13931. {
  13932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13933. }
  13934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13935. isKnowKey = TRUE;
  13936. }
  13937. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13938. {
  13939. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13942. {
  13943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13944. }
  13945. else
  13946. {
  13947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13948. }
  13949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13950. isKnowKey = TRUE;
  13951. }
  13952. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13953. {
  13954. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13957. {
  13958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13959. }
  13960. else
  13961. {
  13962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13963. }
  13964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13965. isKnowKey = TRUE;
  13966. }
  13967. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13968. {
  13969. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13972. {
  13973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13974. }
  13975. else
  13976. {
  13977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13978. }
  13979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13980. isKnowKey = TRUE;
  13981. }
  13982. /*
  13983. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13984. {
  13985. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13988. {
  13989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13990. }
  13991. else
  13992. {
  13993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13994. }
  13995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13996. isKnowKey = TRUE;
  13997. }*/
  13998. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13999. {
  14000. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14003. {
  14004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14005. }
  14006. else
  14007. {
  14008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14009. }
  14010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14011. isKnowKey = TRUE;
  14012. }
  14013. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14014. {
  14015. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14018. {
  14019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14020. }
  14021. else
  14022. {
  14023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14024. }
  14025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14026. isKnowKey = TRUE;
  14027. }
  14028. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14029. {
  14030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14033. {
  14034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14035. }
  14036. else
  14037. {
  14038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14039. }
  14040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14041. isKnowKey = TRUE;
  14042. }
  14043. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14044. {
  14045. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14048. {
  14049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14050. }
  14051. else
  14052. {
  14053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14054. }
  14055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14056. isKnowKey = TRUE;
  14057. }
  14058. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14059. {
  14060. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14063. {
  14064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14065. }
  14066. else
  14067. {
  14068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14069. }
  14070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14071. isKnowKey = TRUE;
  14072. }
  14073. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14074. {
  14075. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14078. {
  14079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14080. }
  14081. else
  14082. {
  14083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14084. }
  14085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14086. isKnowKey = TRUE;
  14087. }
  14088. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14089. {
  14090. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14093. {
  14094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14095. }
  14096. else
  14097. {
  14098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14099. }
  14100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14101. isKnowKey = TRUE;
  14102. }
  14103. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14104. {
  14105. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14108. {
  14109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14110. }
  14111. else
  14112. {
  14113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14114. }
  14115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14116. isKnowKey = TRUE;
  14117. }
  14118. #if 1
  14119. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14120. {
  14121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14123. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14124. {
  14125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14126. }
  14127. else
  14128. {
  14129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14130. }
  14131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14132. isKnowKey = TRUE;
  14133. }
  14134. #endif
  14135. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14136. {
  14137. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14139. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14140. {
  14141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14142. }
  14143. else
  14144. {
  14145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14146. }
  14147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14148. isKnowKey = TRUE;
  14149. }
  14150. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14151. {
  14152. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14154. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14155. {
  14156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14157. }
  14158. else
  14159. {
  14160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14161. }
  14162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14163. isKnowKey = TRUE;
  14164. }
  14165. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14166. {
  14167. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14169. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14170. {
  14171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14172. }
  14173. else
  14174. {
  14175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14176. }
  14177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14178. isKnowKey = TRUE;
  14179. }
  14180. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14181. {
  14182. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14184. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14185. {
  14186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14187. }
  14188. else
  14189. {
  14190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14191. }
  14192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14193. isKnowKey = TRUE;
  14194. }
  14195. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14196. {
  14197. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14199. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14200. {
  14201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14202. }
  14203. else
  14204. {
  14205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14206. }
  14207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14208. isKnowKey = TRUE;
  14209. }
  14210. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14211. {
  14212. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14214. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14215. {
  14216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14217. }
  14218. else
  14219. {
  14220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14221. }
  14222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14223. isKnowKey = TRUE;
  14224. }
  14225. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14226. {
  14227. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14229. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14230. {
  14231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14232. }
  14233. else
  14234. {
  14235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14236. }
  14237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14238. isKnowKey = TRUE;
  14239. }
  14240. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14241. {
  14242. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14244. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14245. {
  14246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14247. }
  14248. else
  14249. {
  14250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14251. }
  14252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14253. isKnowKey = TRUE;
  14254. }
  14255. //=========================================================
  14256. if(!isEmpty && !isKnowKey)
  14257. {
  14258. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14259. strcpy(unknownkey[UnknownKeynum], keyReq);
  14260. UnknownKeynum = UnknownKeynum + 1;
  14261. }
  14262. }
  14263. void processUnkownKey(void)
  14264. {
  14265. DEBUG_INFO("processUnkownKey...\n");
  14266. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14267. for(int index=0; index < UnknownKeynum; index++)
  14268. {
  14269. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14270. {
  14271. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14272. }
  14273. }
  14274. }
  14275. int setKeyValue(char *key, char *value)
  14276. {
  14277. int isSuccess = NotSupported;
  14278. int check_ascii=0;
  14279. char str[256]={0};
  14280. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14281. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14282. {
  14283. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14285. {
  14286. strcpy(str, (const char*)value);
  14287. for(int i = 0; str[i]; i++){
  14288. str[i] = tolower(str[i]);
  14289. }
  14290. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14291. isSuccess = ConfigurationStatus_Accepted;
  14292. }
  14293. else
  14294. {
  14295. isSuccess = ConfigurationStatus_Rejected;
  14296. }
  14297. }
  14298. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14299. {
  14300. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14302. {
  14303. strcpy(str, (const char*)value);
  14304. for(int i = 0; str[i]; i++){
  14305. str[i] = tolower(str[i]);
  14306. }
  14307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14308. isSuccess = ConfigurationStatus_Accepted;
  14309. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14310. }
  14311. else
  14312. {
  14313. isSuccess = ConfigurationStatus_Rejected;
  14314. }
  14315. }
  14316. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14317. {
  14318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14319. {
  14320. strcpy(str, (const char*)value);
  14321. for(int i = 0; str[i]; i++)
  14322. {
  14323. str[i] = tolower(str[i]);
  14324. }
  14325. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14327. isSuccess = ConfigurationStatus_Accepted;
  14328. }
  14329. else
  14330. {
  14331. isSuccess = ConfigurationStatus_Rejected;
  14332. }
  14333. }
  14334. if(strcmp(key, "BlinkRepeat") == 0)
  14335. {
  14336. //Charger.BlinkRepeat = Integer.parseInt(value);
  14337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14338. {
  14339. check_ascii = value[0];
  14340. if( (check_ascii < 48) || (check_ascii > 57) )
  14341. {
  14342. isSuccess = ConfigurationStatus_Rejected;
  14343. }
  14344. else
  14345. {
  14346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14347. isSuccess = ConfigurationStatus_Accepted;
  14348. }
  14349. }
  14350. else
  14351. {
  14352. isSuccess = ConfigurationStatus_Rejected;
  14353. }
  14354. }
  14355. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14356. {
  14357. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14358. {
  14359. check_ascii = value[0];
  14360. if( (check_ascii < 48) || (check_ascii > 57) )
  14361. {
  14362. isSuccess = ConfigurationStatus_Rejected;
  14363. }
  14364. else
  14365. {
  14366. if((atoi(value) == 0) || (atoi(value) >= 10))
  14367. {
  14368. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14370. isSuccess = ConfigurationStatus_Accepted;
  14371. }
  14372. else
  14373. isSuccess = ConfigurationStatus_Rejected;
  14374. }
  14375. }
  14376. else
  14377. {
  14378. isSuccess = ConfigurationStatus_Rejected;
  14379. }
  14380. }
  14381. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14382. {
  14383. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14384. {
  14385. check_ascii = value[0];
  14386. if( (check_ascii < 48) || (check_ascii > 57) )
  14387. {
  14388. isSuccess = ConfigurationStatus_Rejected;
  14389. }
  14390. else
  14391. {
  14392. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14394. isSuccess = ConfigurationStatus_Accepted;
  14395. }
  14396. }
  14397. else
  14398. {
  14399. isSuccess = ConfigurationStatus_Rejected;
  14400. }
  14401. }
  14402. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14403. {
  14404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14405. {
  14406. check_ascii = value[0];
  14407. if( (check_ascii < 48) || (check_ascii > 57) )
  14408. {
  14409. isSuccess = ConfigurationStatus_Rejected;
  14410. }
  14411. else
  14412. {
  14413. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14415. isSuccess = ConfigurationStatus_Accepted;
  14416. }
  14417. }
  14418. else
  14419. {
  14420. isSuccess = ConfigurationStatus_Rejected;
  14421. }
  14422. }
  14423. if(strcmp(key, "HeartbeatInterval") == 0)
  14424. {
  14425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14426. {
  14427. check_ascii = value[0];
  14428. if( (check_ascii < 48) || (check_ascii > 57) )
  14429. {
  14430. isSuccess = ConfigurationStatus_Rejected;
  14431. }
  14432. else
  14433. {
  14434. if((atoi(value) == 0) || (atoi(value) >= 10))
  14435. {
  14436. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14438. HeartBeatWaitTime = atoi(value);
  14439. isSuccess = ConfigurationStatus_Accepted;
  14440. }
  14441. else
  14442. {
  14443. isSuccess = ConfigurationStatus_Rejected;
  14444. }
  14445. }
  14446. }
  14447. else
  14448. {
  14449. isSuccess = ConfigurationStatus_Rejected;
  14450. }
  14451. }
  14452. if(strcmp(key, "LightIntensity") == 0)
  14453. {
  14454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14455. {
  14456. check_ascii = value[0];
  14457. if( (check_ascii < 48) || (check_ascii > 57) )
  14458. {
  14459. isSuccess = ConfigurationStatus_Rejected;
  14460. }
  14461. else
  14462. {
  14463. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14464. isSuccess = ConfigurationStatus_Accepted;
  14465. }
  14466. }
  14467. else
  14468. {
  14469. isSuccess = ConfigurationStatus_Rejected;
  14470. }
  14471. }
  14472. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14473. {
  14474. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14475. {
  14476. strcpy(str, (const char*)value);
  14477. for(int i = 0; str[i]; i++)
  14478. {
  14479. str[i] = tolower(str[i]);
  14480. }
  14481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14482. isSuccess = ConfigurationStatus_Accepted;
  14483. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14484. }
  14485. else
  14486. {
  14487. isSuccess = ConfigurationStatus_Rejected;
  14488. }
  14489. }
  14490. if(strcmp(key, "LocalPreAuthorize") == 0)
  14491. {
  14492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14493. {
  14494. strcpy(str, (const char*)value);
  14495. for(int i = 0; str[i]; i++)
  14496. {
  14497. str[i] = tolower(str[i]);
  14498. }
  14499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14500. isSuccess = ConfigurationStatus_Accepted;
  14501. }
  14502. else
  14503. {
  14504. isSuccess = ConfigurationStatus_Rejected;
  14505. }
  14506. }
  14507. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14508. {
  14509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14510. {
  14511. check_ascii = value[0];
  14512. if( (check_ascii < 48) || (check_ascii > 57) )
  14513. {
  14514. isSuccess = ConfigurationStatus_Rejected;
  14515. }
  14516. else
  14517. {
  14518. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14519. isSuccess = ConfigurationStatus_Accepted;
  14520. }
  14521. }
  14522. else
  14523. {
  14524. isSuccess = ConfigurationStatus_Rejected;
  14525. }
  14526. }
  14527. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14528. {
  14529. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14530. {
  14531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14532. isSuccess = ConfigurationStatus_Accepted;
  14533. }
  14534. else
  14535. {
  14536. isSuccess = ConfigurationStatus_Rejected;
  14537. }
  14538. }
  14539. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14540. {
  14541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14542. {
  14543. check_ascii = value[0];
  14544. if( (check_ascii < 48) || (check_ascii > 57) )
  14545. {
  14546. isSuccess = ConfigurationStatus_Rejected;
  14547. }
  14548. else
  14549. {
  14550. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14551. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14552. isSuccess = ConfigurationStatus_Accepted;
  14553. }
  14554. }
  14555. else
  14556. {
  14557. isSuccess = ConfigurationStatus_Rejected;
  14558. }
  14559. }
  14560. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14561. {
  14562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14563. {
  14564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14565. isSuccess = ConfigurationStatus_Accepted;
  14566. }
  14567. else
  14568. {
  14569. isSuccess = ConfigurationStatus_Rejected;
  14570. }
  14571. }
  14572. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14573. {
  14574. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14575. {
  14576. check_ascii = value[0];
  14577. if( (check_ascii < 48) || (check_ascii > 57) )
  14578. {
  14579. isSuccess = ConfigurationStatus_Rejected;
  14580. }
  14581. else
  14582. {
  14583. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14585. isSuccess = ConfigurationStatus_Accepted;
  14586. }
  14587. }
  14588. else
  14589. {
  14590. isSuccess = ConfigurationStatus_Rejected;
  14591. }
  14592. }
  14593. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14594. {
  14595. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14596. {
  14597. check_ascii = value[0];
  14598. if( (check_ascii < 48) || (check_ascii > 57) )
  14599. {
  14600. isSuccess = ConfigurationStatus_Rejected;
  14601. }
  14602. else
  14603. {
  14604. if((atoi(value) == 0) || (atoi(value) >= 10))
  14605. {
  14606. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14608. isSuccess = ConfigurationStatus_Accepted;
  14609. }
  14610. else
  14611. {
  14612. isSuccess = ConfigurationStatus_Rejected;
  14613. }
  14614. }
  14615. }
  14616. else
  14617. {
  14618. isSuccess = ConfigurationStatus_Rejected;
  14619. }
  14620. }
  14621. if(strcmp(key, "MinimumStatusDuration") == 0)
  14622. {
  14623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14624. {
  14625. check_ascii = value[0];
  14626. if( (check_ascii < 48) || (check_ascii > 57) )
  14627. {
  14628. isSuccess = ConfigurationStatus_Rejected;
  14629. }
  14630. else
  14631. {
  14632. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14633. {
  14634. isSuccess = ConfigurationStatus_Rejected;
  14635. }
  14636. else
  14637. {
  14638. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14640. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14641. isSuccess = ConfigurationStatus_Accepted;
  14642. }
  14643. }
  14644. }
  14645. else
  14646. {
  14647. isSuccess = ConfigurationStatus_Rejected;
  14648. }
  14649. }
  14650. if(strcmp(key, "NumberOfConnectors") == 0)
  14651. {
  14652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14653. {
  14654. check_ascii = value[0];
  14655. if( (check_ascii < 48) || (check_ascii > 57) )
  14656. {
  14657. isSuccess = ConfigurationStatus_Rejected;
  14658. }
  14659. else
  14660. {
  14661. //Charger.ResetRetries = Integer.parseInt(value);
  14662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14663. isSuccess = ConfigurationStatus_Accepted;
  14664. }
  14665. }
  14666. else
  14667. {
  14668. isSuccess = ConfigurationStatus_Rejected;
  14669. }
  14670. }
  14671. if(strcmp(key, "ResetRetries") == 0)
  14672. {
  14673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14674. {
  14675. check_ascii = value[0];
  14676. if( (check_ascii < 48) || (check_ascii > 57) )
  14677. {
  14678. isSuccess = ConfigurationStatus_Rejected;
  14679. }
  14680. else
  14681. {
  14682. //Charger.ResetRetries = Integer.parseInt(value);
  14683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14684. isSuccess = ConfigurationStatus_Accepted;
  14685. }
  14686. }
  14687. else
  14688. {
  14689. isSuccess = ConfigurationStatus_Rejected;
  14690. }
  14691. }
  14692. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14693. {
  14694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14695. {
  14696. strcpy(str, (const char*)value);
  14697. for(int i = 0; str[i]; i++)
  14698. {
  14699. str[i] = tolower(str[i]);
  14700. }
  14701. if(strcmp(str, "notapplicable")== 0)
  14702. {
  14703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14704. isSuccess = ConfigurationStatus_Accepted;
  14705. }
  14706. else if(strcmp(str, "unknown")== 0)
  14707. {
  14708. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14709. isSuccess = ConfigurationStatus_Accepted;
  14710. }
  14711. else if(strcmp(str, "rst")== 0)
  14712. {
  14713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14714. isSuccess = ConfigurationStatus_Accepted;
  14715. }
  14716. else if(strcmp(str, "rts")== 0)
  14717. {
  14718. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14719. isSuccess = ConfigurationStatus_Accepted;
  14720. }
  14721. else if(strcmp(str, "srt")== 0)
  14722. {
  14723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14724. isSuccess = ConfigurationStatus_Accepted;
  14725. }
  14726. else if(strcmp(str, "str")== 0)
  14727. {
  14728. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14729. isSuccess = ConfigurationStatus_Accepted;
  14730. }
  14731. else if(strcmp(str, "trs")== 0)
  14732. {
  14733. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14734. isSuccess = ConfigurationStatus_Accepted;
  14735. }
  14736. else if(strcmp(str, "tsr")== 0)
  14737. {
  14738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14739. isSuccess = ConfigurationStatus_Accepted;
  14740. }
  14741. else
  14742. {
  14743. isSuccess = ConfigurationStatus_Rejected;
  14744. }
  14745. }
  14746. else
  14747. {
  14748. isSuccess = ConfigurationStatus_Rejected;
  14749. }
  14750. }
  14751. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14752. {
  14753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14754. {
  14755. check_ascii = value[0];
  14756. if( (check_ascii < 48) || (check_ascii > 57) )
  14757. {
  14758. isSuccess = ConfigurationStatus_Rejected;
  14759. }
  14760. else
  14761. {
  14762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14763. isSuccess = ConfigurationStatus_Accepted;
  14764. }
  14765. }
  14766. else
  14767. {
  14768. isSuccess = ConfigurationStatus_Rejected;
  14769. }
  14770. }
  14771. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14772. {
  14773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14774. {
  14775. strcpy(str, (const char*)value);
  14776. for(int i = 0; str[i]; i++)
  14777. {
  14778. str[i] = tolower(str[i]);
  14779. }
  14780. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14781. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14782. isSuccess = ConfigurationStatus_Accepted;
  14783. }
  14784. else
  14785. {
  14786. isSuccess = ConfigurationStatus_Rejected;
  14787. }
  14788. }
  14789. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14790. {
  14791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14792. {
  14793. strcpy(str, (const char*)value);
  14794. for(int i = 0; str[i]; i++)
  14795. {
  14796. str[i] = tolower(str[i]);
  14797. }
  14798. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14800. isSuccess = ConfigurationStatus_Accepted;
  14801. }
  14802. else
  14803. {
  14804. isSuccess = ConfigurationStatus_Rejected;
  14805. }
  14806. }
  14807. if(strcmp(key, "StopTxnAlignedData") == 0)
  14808. {
  14809. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14810. {
  14811. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14812. isSuccess = ConfigurationStatus_Accepted;
  14813. }
  14814. else
  14815. {
  14816. isSuccess = ConfigurationStatus_Rejected;
  14817. }
  14818. }
  14819. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14820. {
  14821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14822. {
  14823. check_ascii = value[0];
  14824. if( (check_ascii < 48) || (check_ascii > 57) )
  14825. {
  14826. isSuccess = ConfigurationStatus_Rejected;
  14827. }
  14828. else
  14829. {
  14830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14831. isSuccess = ConfigurationStatus_Accepted;
  14832. }
  14833. }
  14834. else
  14835. {
  14836. isSuccess = ConfigurationStatus_Rejected;
  14837. }
  14838. }
  14839. if(strcmp(key, "StopTxnSampledData") == 0)
  14840. {
  14841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14842. {
  14843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14844. isSuccess = ConfigurationStatus_Accepted;
  14845. }
  14846. else
  14847. {
  14848. isSuccess = ConfigurationStatus_Rejected;
  14849. }
  14850. }
  14851. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14852. {
  14853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14854. {
  14855. check_ascii = value[0];
  14856. if( (check_ascii < 48) || (check_ascii > 57) )
  14857. {
  14858. isSuccess = ConfigurationStatus_Rejected;
  14859. }
  14860. else
  14861. {
  14862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14863. isSuccess = ConfigurationStatus_Accepted;
  14864. }
  14865. }
  14866. else
  14867. {
  14868. isSuccess = ConfigurationStatus_Rejected;
  14869. }
  14870. }
  14871. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14872. {
  14873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14874. {
  14875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14876. isSuccess = ConfigurationStatus_Accepted;
  14877. }
  14878. else
  14879. {
  14880. isSuccess = ConfigurationStatus_Rejected;
  14881. }
  14882. }
  14883. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14884. {
  14885. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14886. {
  14887. check_ascii = value[0];
  14888. if( (check_ascii < 48) || (check_ascii > 57) )
  14889. {
  14890. isSuccess = ConfigurationStatus_Rejected;
  14891. }
  14892. else
  14893. {
  14894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14895. isSuccess = ConfigurationStatus_Accepted;
  14896. }
  14897. }
  14898. else
  14899. {
  14900. isSuccess = ConfigurationStatus_Rejected;
  14901. }
  14902. }
  14903. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14904. {
  14905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14906. {
  14907. check_ascii = value[0];
  14908. if( (check_ascii < 48) || (check_ascii > 57) )
  14909. {
  14910. isSuccess = ConfigurationStatus_Rejected;
  14911. }
  14912. else
  14913. {
  14914. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14915. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14916. TransactionMessageAttemptsValue = atoi(value);
  14917. isSuccess = ConfigurationStatus_Accepted;
  14918. }
  14919. }
  14920. else
  14921. {
  14922. isSuccess = ConfigurationStatus_Rejected;
  14923. }
  14924. }
  14925. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14926. {
  14927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14928. {
  14929. check_ascii = value[0];
  14930. if( (check_ascii < 48) || (check_ascii > 57) )
  14931. {
  14932. isSuccess = ConfigurationStatus_Rejected;
  14933. }
  14934. else
  14935. {
  14936. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14938. TransactionMessageRetryIntervalValue = atoi(value);
  14939. isSuccess = ConfigurationStatus_Accepted;
  14940. }
  14941. }
  14942. else
  14943. {
  14944. isSuccess = ConfigurationStatus_Rejected;
  14945. }
  14946. }
  14947. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14948. {
  14949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14950. {
  14951. strcpy(str, (const char*)value);
  14952. for(int i = 0; str[i]; i++)
  14953. {
  14954. str[i] = tolower(str[i]);
  14955. }
  14956. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14958. isSuccess = ConfigurationStatus_Accepted;
  14959. }
  14960. else
  14961. {
  14962. isSuccess = ConfigurationStatus_Rejected;
  14963. }
  14964. }
  14965. if(strcmp(key, "WebSocketPingInterval") == 0)
  14966. {
  14967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14968. {
  14969. check_ascii = value[0];
  14970. if( (check_ascii < 48) || (check_ascii > 57) )
  14971. {
  14972. isSuccess = ConfigurationStatus_Rejected;
  14973. }
  14974. else
  14975. {
  14976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14977. isSuccess = ConfigurationStatus_Accepted;
  14978. }
  14979. }
  14980. else
  14981. {
  14982. isSuccess = ConfigurationStatus_Rejected;
  14983. }
  14984. }
  14985. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14986. {
  14987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14988. {
  14989. strcpy(str, (const char*)value);
  14990. for(int i = 0; str[i]; i++)
  14991. {
  14992. str[i] = tolower(str[i]);
  14993. }
  14994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14995. isSuccess = ConfigurationStatus_Accepted;
  14996. }
  14997. else
  14998. {
  14999. isSuccess = ConfigurationStatus_Rejected;
  15000. }
  15001. }
  15002. if(strcmp(key, "AuthorizationKey") == 0)
  15003. {
  15004. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15005. {
  15006. strcpy(str, (const char*)value);
  15007. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15008. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15009. isSuccess = ConfigurationStatus_Accepted;
  15010. }
  15011. else
  15012. {
  15013. isSuccess = ConfigurationStatus_Rejected;
  15014. }
  15015. }
  15016. if(strcmp(key, "SecurityProfile") == 0)
  15017. {
  15018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15019. {
  15020. check_ascii = value[0];
  15021. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15022. {
  15023. isSuccess = ConfigurationStatus_Rejected;
  15024. }
  15025. else if(check_ascii == 0x33)
  15026. {
  15027. isSuccess = NotSupported;
  15028. }
  15029. else
  15030. {
  15031. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15032. {
  15033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15034. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15035. isSuccess = ConfigurationStatus_Accepted;
  15036. }
  15037. else
  15038. isSuccess = ConfigurationStatus_Rejected;
  15039. }
  15040. }
  15041. else
  15042. {
  15043. isSuccess = ConfigurationStatus_Rejected;
  15044. }
  15045. }
  15046. if(strcmp(key, "DefaultPrice") == 0)
  15047. {
  15048. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15049. {
  15050. strcpy(str, (const char*)value);
  15051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15052. isSuccess = ConfigurationStatus_Accepted;
  15053. }
  15054. else
  15055. {
  15056. isSuccess = ConfigurationStatus_Rejected;
  15057. }
  15058. }
  15059. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15060. {
  15061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15062. {
  15063. strcpy(str, (const char*)value);
  15064. for(int i = 0; str[i]; i++)
  15065. {
  15066. str[i] = tolower(str[i]);
  15067. }
  15068. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15069. isSuccess = ConfigurationStatus_Accepted;
  15070. }
  15071. else
  15072. {
  15073. isSuccess = ConfigurationStatus_Rejected;
  15074. }
  15075. }
  15076. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15077. {
  15078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15079. {
  15080. strcpy(str, (const char*)value);
  15081. for(int i = 0; str[i]; i++)
  15082. {
  15083. str[i] = tolower(str[i]);
  15084. }
  15085. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15086. isSuccess = ConfigurationStatus_Accepted;
  15087. }
  15088. else
  15089. {
  15090. isSuccess = ConfigurationStatus_Rejected;
  15091. }
  15092. }
  15093. if(strcmp(key, "TimeOffset") == 0)
  15094. {
  15095. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15096. {
  15097. strcpy(str, (const char*)value);
  15098. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15099. isSuccess = ConfigurationStatus_Accepted;
  15100. }
  15101. else
  15102. {
  15103. isSuccess = ConfigurationStatus_Rejected;
  15104. }
  15105. }
  15106. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15107. {
  15108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15109. {
  15110. strcpy(str, (const char*)value);
  15111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15112. isSuccess = ConfigurationStatus_Accepted;
  15113. }
  15114. else
  15115. {
  15116. isSuccess = ConfigurationStatus_Rejected;
  15117. }
  15118. }
  15119. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15120. {
  15121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15122. {
  15123. strcpy(str, (const char*)value);
  15124. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15125. isSuccess = ConfigurationStatus_Accepted;
  15126. }
  15127. else
  15128. {
  15129. isSuccess = ConfigurationStatus_Rejected;
  15130. }
  15131. }
  15132. #if 0
  15133. //For OCPP Test Case
  15134. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15135. {
  15136. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15137. {
  15138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  15139. isSuccess = ConfigurationStatus_Accepted;
  15140. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15141. }
  15142. else
  15143. {
  15144. isSuccess = ConfigurationStatus_Rejected;
  15145. }
  15146. }
  15147. #endif
  15148. #if 1
  15149. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15150. {
  15151. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15152. {
  15153. strcpy(str, (const char*)value);
  15154. for(int i = 0; str[i]; i++)
  15155. {
  15156. str[i] = tolower(str[i]);
  15157. }
  15158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15159. isSuccess = ConfigurationStatus_Accepted;
  15160. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15161. }
  15162. else
  15163. {
  15164. isSuccess = ConfigurationStatus_Rejected;
  15165. }
  15166. }
  15167. #endif
  15168. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15169. {
  15170. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15171. {
  15172. check_ascii = value[0];
  15173. if( (check_ascii < 48) || (check_ascii > 57) )
  15174. {
  15175. isSuccess = ConfigurationStatus_Rejected;
  15176. }
  15177. else
  15178. {
  15179. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15180. isSuccess = ConfigurationStatus_Accepted;
  15181. }
  15182. }
  15183. else
  15184. {
  15185. isSuccess = ConfigurationStatus_Rejected;
  15186. }
  15187. }
  15188. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15189. {
  15190. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15191. {
  15192. check_ascii = value[0];
  15193. if( (check_ascii < 48) || (check_ascii > 57) )
  15194. {
  15195. isSuccess = ConfigurationStatus_Rejected;
  15196. }
  15197. else
  15198. {
  15199. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15200. isSuccess = ConfigurationStatus_Accepted;
  15201. }
  15202. }
  15203. else
  15204. {
  15205. isSuccess = ConfigurationStatus_Rejected;
  15206. }
  15207. }
  15208. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15209. {
  15210. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15211. {
  15212. strcpy(str, (const char*)value);
  15213. for(int i = 0; str[i]; i++)
  15214. {
  15215. str[i] = tolower(str[i]);
  15216. }
  15217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15218. isSuccess = ConfigurationStatus_Accepted;
  15219. }
  15220. else
  15221. {
  15222. isSuccess = ConfigurationStatus_Rejected;
  15223. }
  15224. }
  15225. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15226. {
  15227. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15228. {
  15229. check_ascii = value[0];
  15230. if( (check_ascii < 48) || (check_ascii > 57) )
  15231. {
  15232. isSuccess = ConfigurationStatus_Rejected;
  15233. }
  15234. else
  15235. {
  15236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15237. isSuccess = ConfigurationStatus_Accepted;
  15238. }
  15239. }
  15240. else
  15241. {
  15242. isSuccess = ConfigurationStatus_Rejected;
  15243. }
  15244. }
  15245. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15246. {
  15247. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15248. {
  15249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15250. isSuccess = ConfigurationStatus_Accepted;
  15251. }
  15252. else
  15253. {
  15254. isSuccess = ConfigurationStatus_Rejected;
  15255. }
  15256. }
  15257. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15258. {
  15259. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15260. {
  15261. check_ascii = value[0];
  15262. if( (check_ascii < 48) || (check_ascii > 57) )
  15263. {
  15264. isSuccess = ConfigurationStatus_Rejected;
  15265. }
  15266. else
  15267. {
  15268. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15269. isSuccess = ConfigurationStatus_Accepted;
  15270. }
  15271. }
  15272. else
  15273. {
  15274. isSuccess = ConfigurationStatus_Rejected;
  15275. }
  15276. }
  15277. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15278. {
  15279. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15280. {
  15281. strcpy(str, (const char*)value);
  15282. for(int i = 0; str[i]; i++)
  15283. {
  15284. str[i] = tolower(str[i]);
  15285. }
  15286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15287. isSuccess = ConfigurationStatus_Accepted;
  15288. }
  15289. else
  15290. {
  15291. isSuccess = ConfigurationStatus_Rejected;
  15292. }
  15293. }
  15294. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15295. {
  15296. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15297. {
  15298. check_ascii = value[0];
  15299. if( (check_ascii < 48) || (check_ascii > 57) )
  15300. {
  15301. isSuccess = ConfigurationStatus_Rejected;
  15302. }
  15303. else
  15304. {
  15305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15306. isSuccess = ConfigurationStatus_Accepted;
  15307. }
  15308. }
  15309. else
  15310. {
  15311. isSuccess = ConfigurationStatus_Rejected;
  15312. }
  15313. }
  15314. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15315. return isSuccess;
  15316. }
  15317. int TransactionMessageAttemptsGet(void)
  15318. {
  15319. return TransactionMessageAttemptsValue;
  15320. }
  15321. int FirstHeartBeatResponse(void)
  15322. {
  15323. return FirstHeartBeat;
  15324. }
  15325. int TransactionMessageRetryIntervalGet(void)
  15326. {
  15327. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15328. }
  15329. int ReadHttpStatus(int sock)
  15330. {
  15331. //char c;
  15332. char buff[1024]="",*ptr=buff+1;
  15333. int bytes_received, status;
  15334. DEBUG_INFO("Begin Response ..\n");
  15335. while((bytes_received = recv(sock, ptr, 1, 0))){
  15336. if(bytes_received==-1){
  15337. perror("ReadHttpStatus");
  15338. exit(1);
  15339. }
  15340. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15341. ptr++;
  15342. }
  15343. *ptr=0;
  15344. ptr=buff+1;
  15345. sscanf(ptr,"%*s %d ", &status);
  15346. DEBUG_INFO("%s\n",ptr);
  15347. DEBUG_INFO("status=%d\n",status);
  15348. DEBUG_INFO("End Response ..\n");
  15349. return (bytes_received>0)?status:0;
  15350. }
  15351. //the only filed that it parsed is 'Content-Length'
  15352. int ParseHeader(int sock)
  15353. {
  15354. //char c;
  15355. char buff[1024]="",*ptr=buff+4;
  15356. int bytes_received;
  15357. DEBUG_INFO("Begin HEADER ..\n");
  15358. while((bytes_received = recv(sock, ptr, 1, 0))){
  15359. if(bytes_received==-1){
  15360. perror("Parse Header");
  15361. exit(1);
  15362. }
  15363. if(
  15364. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15365. (ptr[-1]=='\r') && (*ptr=='\n' )
  15366. ) break;
  15367. ptr++;
  15368. }
  15369. *ptr=0;
  15370. ptr=buff+4;
  15371. //printf("%s",ptr);
  15372. if(bytes_received){
  15373. ptr=strstr(ptr,"Content-Length:");
  15374. if(ptr){
  15375. sscanf(ptr,"%*s %d",&bytes_received);
  15376. }else
  15377. bytes_received=-1; //unknown size
  15378. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15379. }
  15380. DEBUG_INFO("End HEADER ..\n");
  15381. return bytes_received ;
  15382. }
  15383. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15384. {
  15385. int result = TRUE;
  15386. char rmFileCmd[100]={0};
  15387. char FilePath[100]={0};
  15388. char ftpbuf[200];
  15389. int systemresult;
  15390. sprintf(FilePath,"/mnt/%s",filename);
  15391. system("ping 8.8.8.8 &");
  15392. if((access(FilePath,F_OK))!=-1)
  15393. {
  15394. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15395. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15396. system(rmFileCmd);
  15397. }
  15398. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15399. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15400. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15401. systemresult = system(ftpbuf);
  15402. if(systemresult != 0)
  15403. {
  15404. DEBUG_INFO("http DownLoad error!\n");
  15405. result = FALSE;
  15406. }
  15407. system("pkill ping");
  15408. return result;
  15409. }
  15410. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15411. {
  15412. int result = TRUE;
  15413. char rmFileCmd[100]={0};
  15414. char FilePath[100]={0};
  15415. char ftpbuf[200];
  15416. int systemresult;
  15417. sprintf(FilePath,"/mnt/%s",filename);
  15418. system("ping 8.8.8.8 &");
  15419. if((access(FilePath,F_OK))!=-1)
  15420. {
  15421. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15422. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15423. system(rmFileCmd);
  15424. }
  15425. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15426. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15427. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15428. systemresult = system(ftpbuf);
  15429. if(systemresult != 0)
  15430. {
  15431. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15432. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15433. systemresult = system(ftpbuf);
  15434. if(systemresult != 0)
  15435. {
  15436. DEBUG_WARN("wget error!\n");
  15437. result = FALSE;
  15438. }
  15439. }
  15440. system("pkill ping");
  15441. return result;
  15442. }
  15443. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15444. {
  15445. char rmFileCmd[100]={0};
  15446. char FilePath[100]={0};
  15447. char buf[512];
  15448. int systemresult = 0;
  15449. //DEBUG_INFO("filename=%s\n",filename);
  15450. //DEBUG_INFO("url=%s\n",url);
  15451. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15452. if((access(FilePath,F_OK))!=-1)
  15453. {
  15454. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15455. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15456. system(rmFileCmd);
  15457. }
  15458. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15459. if(fp == NULL)
  15460. {
  15461. DEBUG_INFO("log is NULL\n");
  15462. return FALSE;
  15463. }
  15464. else
  15465. {
  15466. fprintf(fp, "%s\n", url);
  15467. fprintf(fp, "%s\n", filename);
  15468. fclose(fp);
  15469. }
  15470. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15471. if(phpFP == NULL)
  15472. {
  15473. DEBUG_INFO("PHP upload fail.\n");
  15474. return FALSE;
  15475. }
  15476. else
  15477. {
  15478. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15479. {
  15480. if(strstr(buf, "result") != NULL)
  15481. {
  15482. sscanf(buf, "result: %d", &systemresult);
  15483. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15484. }
  15485. }
  15486. pclose(phpFP);
  15487. }
  15488. if(systemresult != 1)
  15489. {
  15490. DEBUG_INFO("HTTP upload error!\n");
  15491. return FALSE;
  15492. }
  15493. return TRUE;
  15494. }
  15495. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15496. {
  15497. struct hostent* server;
  15498. char *IPbuffer;
  15499. char ftpbuf[200];
  15500. int systemresult;
  15501. // To retrieve host information
  15502. server = gethostbyname(location);
  15503. // To convert an Internet network
  15504. // address into ASCII string
  15505. IPbuffer = inet_ntoa(*((struct in_addr*)
  15506. server->h_addr_list[0]));
  15507. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15508. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15509. /* format : ftpput -u username -p passwd IP target source*/
  15510. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15511. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15512. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15513. systemresult = system(ftpbuf);
  15514. DEBUG_INFO("systemresult=%d\n",systemresult);
  15515. if(systemresult != 0)
  15516. {
  15517. DEBUG_INFO("ftpput error!\n");
  15518. return FALSE;
  15519. }
  15520. return TRUE;
  15521. }
  15522. int GetOcppServerURL()
  15523. {
  15524. int result = FALSE;
  15525. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15526. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15527. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15528. struct yuarel url;
  15529. char urlStr[512];
  15530. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15531. {
  15532. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15533. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15534. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15535. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15536. if(yuarel_parse(&url, urlStr) != -1)
  15537. {
  15538. sprintf(OcppProtocol, "%s", url.scheme);
  15539. sprintf(OcppHost, "%s", url.host);
  15540. if(url.path == NULL)
  15541. OcppTempPath[0] = '\0';
  15542. else
  15543. {
  15544. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15545. {
  15546. sprintf(OcppTempPath, "%s/", url.path);
  15547. }
  15548. else
  15549. {
  15550. sprintf(OcppTempPath, "%s", url.path);
  15551. }
  15552. }
  15553. if(url.port == 0)
  15554. {
  15555. if(strcmp(OcppProtocol, "wss") == 0)
  15556. OcppPort = 443;
  15557. else
  15558. OcppPort = 80;
  15559. }
  15560. else
  15561. OcppPort = url.port;
  15562. result = TRUE;
  15563. }
  15564. }
  15565. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15566. {
  15567. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15568. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15569. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15570. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15571. if(yuarel_parse(&url, urlStr) != -1)
  15572. {
  15573. sprintf(OcppProtocol, "%s", url.scheme);
  15574. sprintf(OcppHost, "%s", url.host);
  15575. if(url.path == NULL)
  15576. OcppTempPath[0] = '\0';
  15577. else
  15578. sprintf(OcppTempPath, "%s", url.path);
  15579. if(url.port == 0)
  15580. {
  15581. if(strcmp(OcppProtocol, "wss") == 0)
  15582. OcppPort = 443;
  15583. else
  15584. OcppPort = 80;
  15585. }
  15586. else
  15587. OcppPort = url.port;
  15588. result = TRUE;
  15589. }
  15590. }
  15591. else
  15592. {
  15593. strcpy(OcppHost,"");
  15594. }
  15595. return result;
  15596. }
  15597. int GetOcppPath()
  15598. {
  15599. int result = FALSE;
  15600. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15601. {
  15602. if(OcppTempPath == NULL)
  15603. {
  15604. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15605. }
  15606. else
  15607. {
  15608. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15609. }
  15610. result = TRUE;
  15611. goto End;
  15612. }
  15613. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15614. {
  15615. if(OcppTempPath == NULL)
  15616. {
  15617. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15618. }
  15619. else
  15620. {
  15621. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15622. }
  15623. result = TRUE;
  15624. goto End;
  15625. }
  15626. else
  15627. {
  15628. strcpy(OcppPath,"");
  15629. }
  15630. End:
  15631. return result;
  15632. }
  15633. int GetOcppPort()
  15634. {
  15635. return OcppPort;
  15636. }
  15637. int GetOcppConnStatus(void)
  15638. {
  15639. return ShmOCPP16Data->OcppConnStatus;
  15640. }
  15641. void SetOcppConnStatus(uint8_t status)
  15642. {
  15643. ShmOCPP16Data->OcppConnStatus = status;
  15644. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15645. }
  15646. int GetHeartBeatWithNOResponse(void)
  15647. {
  15648. return HeartBeatWithNOResponse;
  15649. }
  15650. void SetHeartBeatWithNOResponse(void)
  15651. {
  15652. HeartBeatWithNOResponse = 0;
  15653. }
  15654. void GetStartTransactionIdTag(int gun_index)
  15655. {
  15656. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15657. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15658. }
  15659. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15660. {
  15661. char ch;
  15662. FILE *fptr1;
  15663. int temptransactionId;
  15664. char str[100]={0};
  15665. temptransactionId = 0;
  15666. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15667. {
  15668. DEBUG_INFO("IdTag is empty.\n");
  15669. return temptransactionId;
  15670. }
  15671. /*------ Read the file ----------------*/
  15672. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15673. if (!fptr1)
  15674. {
  15675. DEBUG_INFO("QueueTransactionId file open error.\n");
  15676. //printf(" File not found or unable to open the input file!!\n");
  15677. return temptransactionId;
  15678. }
  15679. ch=fgetc(fptr1);
  15680. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15681. rewind(fptr1);
  15682. if(ch!=EOF)
  15683. {
  15684. // printf("%c",ch);
  15685. while (fgets(str, 100, fptr1) != NULL)
  15686. {
  15687. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15688. if(str[0]=='\0')
  15689. {
  15690. break;
  15691. }
  15692. char *revbuf[8] = {0}; // Variable store string split
  15693. int num = 0;// Quantity after string split
  15694. DEBUG_INFO("Transaction queue data= %s\n", str);
  15695. splitstring(str,",",revbuf,&num); // String split
  15696. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15697. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15698. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15699. DEBUG_INFO("------------------------------\n");
  15700. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15701. {
  15702. if(isStopTransaction)
  15703. {
  15704. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15705. {
  15706. temptransactionId = atoi(revbuf[2]);
  15707. //break;
  15708. }
  15709. }
  15710. else
  15711. {
  15712. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15713. {
  15714. temptransactionId = atoi(revbuf[2]);
  15715. //break;
  15716. }
  15717. }
  15718. }
  15719. }
  15720. }
  15721. else
  15722. DEBUG_INFO("EOF\n");
  15723. fclose(fptr1);
  15724. /*------- End of reading ---------------*/
  15725. return temptransactionId;
  15726. }
  15727. void SetTransactionIdZero(int transactionId)
  15728. {
  15729. char ch;
  15730. FILE *fptr1, *fptr2;
  15731. int temptransactionId = 0;
  15732. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15733. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15734. if (!fptr1)
  15735. {
  15736. //printf(" File not found or unable to open the input file!!\n");
  15737. return ;
  15738. }
  15739. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15740. if (!fptr2)
  15741. {
  15742. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15743. fclose(fptr1);
  15744. return ;
  15745. }
  15746. ch=fgetc(fptr1);
  15747. rewind(fptr1);
  15748. if(ch!=EOF)
  15749. {
  15750. // copy all contents to the temporary file except the specific line
  15751. while (fgets(str, 100, fptr1) != NULL)
  15752. {
  15753. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15754. if(str[0]=='\0')
  15755. {
  15756. break;
  15757. }
  15758. char *revbuf[8] = {0};
  15759. int num = 0;
  15760. strcpy(strtemp, str);
  15761. splitstring(str,",",revbuf,&num);
  15762. if(revbuf[2][0] != '\0')
  15763. {
  15764. temptransactionId = atoi(revbuf[2]);
  15765. if(transactionId != temptransactionId)
  15766. {
  15767. fprintf(fptr2, "%s\n", strtemp);
  15768. }
  15769. }
  15770. }
  15771. }
  15772. fclose(fptr1);
  15773. fclose(fptr2);
  15774. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15775. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15776. /*------ Read the file ----------------*/
  15777. }
  15778. int InternetDisconnect(void)
  15779. {
  15780. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15781. }
  15782. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15783. void storeTempStopTransaction(int gun_index)
  15784. {
  15785. char guid[37]={0};
  15786. int tempIndex = 0;
  15787. char TempStopTransaction[256];
  15788. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15789. DEBUG_INFO("storeTempStopTransaction...\n");
  15790. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15791. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15792. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15793. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15794. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15795. {
  15796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15797. {
  15798. tempIndex = ((gun_index==2) ? 1: 0);
  15799. }
  15800. else
  15801. {
  15802. tempIndex = gun_index;
  15803. }
  15804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15805. {
  15806. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15807. {
  15808. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15809. }
  15810. }// END OF CHAdeMO_QUANTITY
  15811. }
  15812. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15813. {
  15814. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15815. {
  15816. tempIndex = ((gun_index==2) ? 1: 0);
  15817. }
  15818. else
  15819. {
  15820. tempIndex = gun_index;
  15821. }
  15822. for (int index = 0; index < CCS_QUANTITY; index++)
  15823. {
  15824. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15825. {
  15826. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15827. }
  15828. }// END OF CCS_QUANTITY
  15829. }
  15830. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15831. {
  15832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15833. {
  15834. tempIndex = ((gun_index==2) ? 1: 0);
  15835. }
  15836. else
  15837. {
  15838. tempIndex = gun_index;
  15839. }
  15840. for (int index = 0; index < GB_QUANTITY; index++)
  15841. {
  15842. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15843. {
  15844. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15845. }
  15846. }// END OF GB_QUANTITY
  15847. }
  15848. else if(gunType[gun_index] == GUN_TYPE_DO)
  15849. {
  15850. tempIndex = gun_index;
  15851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15852. {
  15853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15854. {
  15855. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15856. }
  15857. }
  15858. }
  15859. else
  15860. {
  15861. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15862. {
  15863. tempIndex = 2;
  15864. }
  15865. else
  15866. {
  15867. tempIndex = gun_index;
  15868. }
  15869. for (int index = 0; index < AC_QUANTITY; index++)
  15870. {
  15871. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15872. {
  15873. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15874. }
  15875. }// END OF AC_QUANTITY
  15876. }
  15877. //Stop Transaction Time
  15878. struct timeval tmnow;
  15879. struct tm *tm;
  15880. char buf[28];//, usec_buf[6];
  15881. gettimeofday(&tmnow, NULL);
  15882. time_t t;
  15883. t = time(NULL);
  15884. /*UTC time and date*/
  15885. tm = gmtime(&t);
  15886. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15888. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15890. random_uuid(guid);
  15891. /***********************************transactionData******************************************************/
  15892. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15893. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15894. //=================================
  15895. //1. Transaction_Begin
  15896. //=================================
  15897. //============================== Energy.Active.Import.Interval ===========================================
  15898. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15899. {
  15900. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  15904. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15905. 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))
  15906. {
  15907. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15908. }
  15909. else
  15910. {
  15911. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15912. }
  15913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15914. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15915. }
  15916. //=================================
  15917. //2. Transaction_End
  15918. //=================================
  15919. //2.1====================================== Current.Import L1 ==============================================
  15920. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15921. {
  15922. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15923. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15924. {
  15925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15926. {
  15927. tempIndex = ((gun_index==2) ? 1: 0);
  15928. }
  15929. else
  15930. {
  15931. tempIndex = gun_index;
  15932. }
  15933. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15934. {
  15935. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15936. {
  15937. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15938. }
  15939. }// End of for CHAdeMO_QUANTITY
  15940. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15941. }
  15942. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15943. {
  15944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15945. {
  15946. tempIndex = ((gun_index==2) ? 1: 0);
  15947. }
  15948. else
  15949. {
  15950. tempIndex = gun_index;
  15951. }
  15952. for (int index = 0; index < CCS_QUANTITY; index++)
  15953. {
  15954. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15955. {
  15956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15957. }
  15958. }// End of for CCS_QUANTITY
  15959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15960. }
  15961. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15962. {
  15963. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15964. {
  15965. tempIndex = ((gun_index==2) ? 1: 0);
  15966. }
  15967. else
  15968. {
  15969. tempIndex = gun_index;
  15970. }
  15971. for (int index = 0; index < GB_QUANTITY; index++)
  15972. {
  15973. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15974. {
  15975. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15976. }
  15977. }// End of for GB_QUANTITY
  15978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15979. }
  15980. else if(gunType[gun_index] == GUN_TYPE_DO)
  15981. {
  15982. tempIndex = gun_index;
  15983. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15984. {
  15985. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15986. {
  15987. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15988. }
  15989. }
  15990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15991. }
  15992. else
  15993. {
  15994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15995. {
  15996. tempIndex = 2;
  15997. }
  15998. else
  15999. {
  16000. tempIndex = gun_index;
  16001. }
  16002. for (int index = 0; index < AC_QUANTITY; index++)
  16003. {
  16004. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16005. {
  16006. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16007. }
  16008. }// End of for AC_QUANTITY
  16009. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16010. }
  16011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16014. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16017. }
  16018. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16019. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16020. {
  16021. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16022. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16023. {
  16024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16025. {
  16026. tempIndex = ((gun_index==2) ? 1: 0);
  16027. }
  16028. else
  16029. {
  16030. tempIndex = gun_index;
  16031. }
  16032. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16033. {
  16034. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16035. {
  16036. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16037. }
  16038. }// END OF CHAdeMO_QUANTITY
  16039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16040. }
  16041. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16042. {
  16043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16044. {
  16045. tempIndex = ((gun_index==2) ? 1: 0);
  16046. }
  16047. else
  16048. {
  16049. tempIndex = gun_index;
  16050. }
  16051. for (int index = 0; index < CCS_QUANTITY; index++)
  16052. {
  16053. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16054. {
  16055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16056. }
  16057. }// END OF CCS_QUANTITY
  16058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16059. }
  16060. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16061. {
  16062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16063. {
  16064. tempIndex = ((gun_index==2) ? 1: 0);
  16065. }
  16066. else
  16067. {
  16068. tempIndex = gun_index;
  16069. }
  16070. for (int index = 0; index < GB_QUANTITY; index++)
  16071. {
  16072. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16073. {
  16074. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16075. }
  16076. }// END OF GB_QUANTITY
  16077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16078. }
  16079. else if(gunType[gun_index] == GUN_TYPE_DO)
  16080. {
  16081. tempIndex = gun_index;
  16082. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16083. {
  16084. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16085. {
  16086. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16087. }
  16088. }
  16089. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16090. }
  16091. else
  16092. {
  16093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16094. {
  16095. tempIndex = 2;
  16096. }
  16097. else
  16098. {
  16099. tempIndex = gun_index;
  16100. }
  16101. for (int index = 0; index < AC_QUANTITY; index++)
  16102. {
  16103. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16104. {
  16105. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16106. }
  16107. }// END OF AC_QUANTITY
  16108. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16109. }
  16110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16111. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16113. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16115. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16116. }
  16117. //2.3====================================== Power.Active.Import =========================================
  16118. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16119. {
  16120. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16121. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16122. {
  16123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16124. {
  16125. tempIndex = ((gun_index==2) ? 1: 0);
  16126. }
  16127. else
  16128. {
  16129. tempIndex = gun_index;
  16130. }
  16131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16132. {
  16133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16134. {
  16135. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16136. }
  16137. } // End for CHAdeMO_QUANTITY
  16138. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16139. }
  16140. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16141. {
  16142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16143. {
  16144. tempIndex = ((gun_index==2) ? 1: 0);
  16145. }
  16146. else
  16147. {
  16148. tempIndex = gun_index;
  16149. }
  16150. for (int index = 0; index < CCS_QUANTITY; index++)
  16151. {
  16152. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16153. {
  16154. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16155. }
  16156. } // END for CCS_QUANTITY
  16157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16158. }
  16159. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16160. {
  16161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16162. {
  16163. tempIndex = ((gun_index==2) ? 1: 0);
  16164. }
  16165. else
  16166. {
  16167. tempIndex = gun_index;
  16168. }
  16169. for (int index = 0; index < GB_QUANTITY; index++)
  16170. {
  16171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16172. {
  16173. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16174. }
  16175. }// END for GB_QUANTITY
  16176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16177. }
  16178. else if(gunType[gun_index] == GUN_TYPE_DO)
  16179. {
  16180. tempIndex = gun_index;
  16181. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16182. {
  16183. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16184. {
  16185. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16186. }
  16187. }
  16188. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16189. }
  16190. else
  16191. {
  16192. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16193. {
  16194. tempIndex = 2;
  16195. }
  16196. else
  16197. {
  16198. tempIndex = gun_index;
  16199. }
  16200. for (int index = 0; index < AC_QUANTITY; index++)
  16201. {
  16202. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16203. {
  16204. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16205. }
  16206. } // END for AC_QUANTITY
  16207. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16208. }
  16209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16210. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16212. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16215. }
  16216. //2.4====================================== Voltage L1 ====================================================
  16217. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16218. {
  16219. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16220. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16221. {
  16222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16223. {
  16224. tempIndex = ((gun_index==2) ? 1: 0);
  16225. }
  16226. else
  16227. {
  16228. tempIndex = gun_index;
  16229. }
  16230. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16231. {
  16232. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16233. {
  16234. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16235. }
  16236. } // END OF FOR CHAdeMO_QUANTITY
  16237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16238. }
  16239. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16240. {
  16241. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16242. {
  16243. tempIndex = ((gun_index==2) ? 1: 0);
  16244. }
  16245. else
  16246. {
  16247. tempIndex = gun_index;
  16248. }
  16249. for (int index = 0; index < CCS_QUANTITY; index++)
  16250. {
  16251. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16252. {
  16253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16254. }
  16255. } // END OF FOR CCS_QUANTITY
  16256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16257. }
  16258. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16259. {
  16260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16261. {
  16262. tempIndex = ((gun_index==2) ? 1: 0);
  16263. }
  16264. else
  16265. {
  16266. tempIndex = gun_index;
  16267. }
  16268. for (int index = 0; index < GB_QUANTITY; index++)
  16269. {
  16270. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16271. {
  16272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16273. }
  16274. } // END OF FOR GB_QUANTITY
  16275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16276. }
  16277. else if(gunType[gun_index] == GUN_TYPE_DO)
  16278. {
  16279. tempIndex = gun_index;
  16280. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16281. {
  16282. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16283. {
  16284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16285. }
  16286. }
  16287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16288. }
  16289. else
  16290. {
  16291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16292. {
  16293. tempIndex = 2;
  16294. }
  16295. else
  16296. {
  16297. tempIndex = gun_index;
  16298. }
  16299. for (int index = 0; index < AC_QUANTITY; index++)
  16300. {
  16301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16302. {
  16303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  16304. }
  16305. } // END OF FOR AC_QUANTITY
  16306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16307. }
  16308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16311. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16314. }
  16315. //2.5============================================== End SoC =========================================================
  16316. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16317. {
  16318. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16319. 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))
  16320. {
  16321. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16322. {
  16323. tempIndex = ((gun_index==2) ? 1: 0);
  16324. }
  16325. else
  16326. {
  16327. tempIndex = gun_index;
  16328. }
  16329. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16330. {
  16331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16332. {
  16333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16334. {
  16335. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16336. }
  16337. }
  16338. }
  16339. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16340. {
  16341. for (int index = 0; index < CCS_QUANTITY; index++)
  16342. {
  16343. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16344. {
  16345. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16346. }
  16347. }
  16348. }
  16349. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16350. {
  16351. for (int index = 0; index < GB_QUANTITY; index++)
  16352. {
  16353. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16354. {
  16355. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16356. }
  16357. }
  16358. }
  16359. else if(gunType[gun_index] == GUN_TYPE_DO)
  16360. {
  16361. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16362. {
  16363. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16364. {
  16365. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16366. }
  16367. }
  16368. }
  16369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16375. } // END FOR DC CASE
  16376. }
  16377. //2.6====================================== Current.Import L2 ==============================================
  16378. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16379. {
  16380. // AC 3 phase L2 current
  16381. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16382. {
  16383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16384. {
  16385. tempIndex = 2;
  16386. }
  16387. else
  16388. {
  16389. tempIndex = gun_index;
  16390. }
  16391. for (int index = 0; index < AC_QUANTITY; index++)
  16392. {
  16393. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16394. {
  16395. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16396. }
  16397. }// End of for AC_QUANTITY
  16398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16399. }
  16400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16405. }
  16406. //2.7====================================== Current.Import L3 ==============================================
  16407. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16408. {
  16409. // AC 3 phase L3 current
  16410. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16411. {
  16412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16413. {
  16414. tempIndex = 2;
  16415. }
  16416. else
  16417. {
  16418. tempIndex = gun_index;
  16419. }
  16420. for (int index = 0; index < AC_QUANTITY; index++)
  16421. {
  16422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16423. {
  16424. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16425. }
  16426. }// End of for AC_QUANTITY
  16427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16428. }
  16429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16434. }
  16435. //2.9====================================== Voltage L2 ====================================================
  16436. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16437. {
  16438. // AC 3 phase L2 volatge
  16439. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16440. {
  16441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16442. {
  16443. tempIndex = 2;
  16444. }
  16445. else
  16446. {
  16447. tempIndex = gun_index;
  16448. }
  16449. for (int index = 0; index < AC_QUANTITY; index++)
  16450. {
  16451. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16452. {
  16453. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  16454. }
  16455. } // END OF FOR AC_QUANTITY
  16456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16457. }
  16458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16463. }
  16464. //2.10====================================== Voltage L3 ====================================================
  16465. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16466. {
  16467. // AC 3 phase L3 volatge
  16468. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16469. {
  16470. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16471. {
  16472. tempIndex = 2;
  16473. }
  16474. else
  16475. {
  16476. tempIndex = gun_index;
  16477. }
  16478. for (int index = 0; index < AC_QUANTITY; index++)
  16479. {
  16480. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16481. {
  16482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  16483. }
  16484. } // END OF FOR AC_QUANTITY
  16485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16486. }
  16487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16492. }
  16493. //====================== Start SoC ================================
  16494. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16495. {
  16496. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16497. 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))
  16498. {
  16499. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16500. {
  16501. tempIndex = ((gun_index==2) ? 1: 0);
  16502. }
  16503. else
  16504. {
  16505. tempIndex = gun_index;
  16506. }
  16507. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16508. {
  16509. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16510. {
  16511. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16512. {
  16513. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16514. }
  16515. }
  16516. }
  16517. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16518. {
  16519. for (int index = 0; index < CCS_QUANTITY; index++)
  16520. {
  16521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16522. {
  16523. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16524. }
  16525. }
  16526. }
  16527. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16528. {
  16529. for (int index = 0; index < GB_QUANTITY; index++)
  16530. {
  16531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16532. {
  16533. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16534. }
  16535. }
  16536. }
  16537. else if(gunType[gun_index] == GUN_TYPE_DO)
  16538. {
  16539. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16540. {
  16541. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16542. {
  16543. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16544. }
  16545. }
  16546. }
  16547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16553. } // END FOR DC CASE
  16554. }
  16555. //======================================== Message create ==============================================
  16556. json_object *StopTransaction = json_object_new_object();
  16557. json_object *transactionDatas = json_object_new_array();
  16558. json_object *sampledValues = json_object_new_array();
  16559. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16560. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16561. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16562. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16563. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16564. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16565. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16566. {
  16567. json_object *transactionData = json_object_new_object();
  16568. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16569. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16570. {
  16571. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16572. {
  16573. json_object *sampledValue = json_object_new_object();
  16574. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16575. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16576. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16577. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16578. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16579. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16580. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16581. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16582. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16583. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16584. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16585. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16586. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16587. json_object_array_add(sampledValues, sampledValue);
  16588. }
  16589. }
  16590. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16591. json_object_array_add(transactionDatas, transactionData);
  16592. }
  16593. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16594. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16595. ,MESSAGE_TYPE_CALL
  16596. ,guid
  16597. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16598. json_object_put(StopTransaction);
  16599. // Check File "TempStopTransaction" Exist
  16600. if((access(TempStopTransaction,F_OK))!=-1)
  16601. {
  16602. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16603. fclose(fopen(TempStopTransaction, "w"));
  16604. }
  16605. else
  16606. {
  16607. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16608. FILE *log = fopen(TempStopTransaction, "w+");
  16609. if(log == NULL)
  16610. {
  16611. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16612. return ;
  16613. }
  16614. else
  16615. {
  16616. fclose(log);
  16617. }
  16618. }
  16619. //Add TempStopTransaction | Update TempStopTransaction
  16620. // open file for writing
  16621. FILE *outfile;
  16622. outfile = fopen (TempStopTransaction, "a");
  16623. //DEBUG_INFO("data = %s\n", queuedata);
  16624. fputs(queuedata, outfile);
  16625. fputs("\n", outfile);
  16626. fclose (outfile);
  16627. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16628. }
  16629. void checkTempStopTransaction(int gun_index)
  16630. {
  16631. FILE *fptr1;
  16632. char ch;
  16633. char str[QUEUE_MESSAGE_LENGTH]={0};
  16634. char guid[37]={0};
  16635. char tempdata[65]={0};
  16636. char connectorStr[2]={0};
  16637. char TempStopTransaction[256];
  16638. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16639. fptr1 = fopen(TempStopTransaction, "r");
  16640. //TempStopTransaction格式: 槍號,StopTransaction封包
  16641. if (!fptr1)
  16642. {
  16643. //printf(" File not found or unable to open the input file!!\n");
  16644. return ;
  16645. }
  16646. ch=fgetc(fptr1);
  16647. //printf(" Now the content of the file %s is : \n",fname);
  16648. rewind(fptr1);
  16649. if(ch!=EOF)
  16650. {
  16651. // copy all contents to the temporary file except the specific line
  16652. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16653. {
  16654. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16655. if(str[0]=='\0')
  16656. {
  16657. break;
  16658. }
  16659. //TempStopTransaction格式: 槍號,StopTransaction封包
  16660. strncpy(connectorStr, str, 1);
  16661. if(atoi(connectorStr) != (gun_index+1))
  16662. {
  16663. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16664. fclose(fptr1);
  16665. return ;
  16666. }
  16667. //random_uuid(guid);
  16668. strncpy(guid, str+6, 36); //copy guid
  16669. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16670. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16671. {
  16672. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16673. }
  16674. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16675. OCPP_insert_transaction_msg(NO, str);
  16676. memset(str,0,ARRAY_SIZE(str));
  16677. }
  16678. }
  16679. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16680. fclose(fptr1);
  16681. remove(TempStopTransaction); // remove the original file
  16682. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16683. }
  16684. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16685. {
  16686. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16687. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16688. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16689. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16690. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16691. }
  16692. int GetWebSocketPingInterval(void)
  16693. {
  16694. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16695. }
  16696. int GetServerSign(void)
  16697. {
  16698. return server_sign;
  16699. }
  16700. uint8_t GetOcppSecurityProfile()
  16701. {
  16702. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16703. }
  16704. void GetOcppChargerBoxId(uint8_t *data)
  16705. {
  16706. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16707. }
  16708. void GetOcppSecurityPassword(uint8_t *data)
  16709. {
  16710. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16711. }
  16712. void SetOcppVersion(uint8_t *version)
  16713. {
  16714. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16715. DEBUG_INFO("ocpp version: %s\n", version);
  16716. if(strstr((char*)version, "ocpp1.6") != NULL)
  16717. {
  16718. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16719. }
  16720. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16721. {
  16722. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16723. system("pkill OcppBackend");
  16724. }
  16725. }
  16726. void SetServerSign(int value)
  16727. {
  16728. server_sign = value;
  16729. }
  16730. int GetBootNotificationInterval(void)
  16731. {
  16732. return BootNotificationInterval;
  16733. }
  16734. int GetInternetConn(void)
  16735. {
  16736. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16737. }
  16738. int GetBackendConnectionTimeout(void)
  16739. {
  16740. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16741. }
  16742. int isConnectorInitMode(int gun_index)
  16743. {
  16744. int tempIndex = 0;
  16745. int result = TRUE;
  16746. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16747. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16748. {
  16749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16750. {
  16751. tempIndex = ((gun_index==2) ? 1: 0);
  16752. }
  16753. else
  16754. {
  16755. tempIndex = gun_index;
  16756. }
  16757. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16758. {
  16759. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16760. {
  16761. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16762. } //end of the same index
  16763. }//end of for CHAdeMO_QUANTITY
  16764. }
  16765. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16766. {
  16767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16768. {
  16769. tempIndex = ((gun_index==2) ? 1: 0);
  16770. }
  16771. else
  16772. {
  16773. tempIndex = gun_index;
  16774. }
  16775. for (int index = 0; index < CCS_QUANTITY; index++)
  16776. {
  16777. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16778. {
  16779. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16780. } //end of the same index
  16781. } // end of for CCS_QUANTITY
  16782. }
  16783. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16784. {
  16785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16786. {
  16787. tempIndex = ((gun_index==2) ? 1: 0);
  16788. }
  16789. else
  16790. {
  16791. tempIndex = gun_index;
  16792. }
  16793. for (int index = 0; index < GB_QUANTITY; index++)
  16794. {
  16795. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16796. {
  16797. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16798. } //end of the same index
  16799. } // end of for GB_QUANTITY
  16800. }
  16801. else if(gunType[gun_index] == GUN_TYPE_DO)
  16802. {
  16803. tempIndex = gun_index;
  16804. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16805. {
  16806. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16807. {
  16808. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16809. } //end of the same index
  16810. }
  16811. }
  16812. else
  16813. {
  16814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16815. {
  16816. tempIndex = 2;
  16817. }
  16818. else
  16819. {
  16820. tempIndex = gun_index;
  16821. }
  16822. for (int index = 0; index < AC_QUANTITY; index++)
  16823. {
  16824. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16825. {
  16826. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16827. }//end of the same index
  16828. }//end of for AC_QUANTITY
  16829. }
  16830. return result;
  16831. }
  16832. void refreshProcDogTimer()
  16833. {
  16834. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16835. }
  16836. void InitialSystemValue(void)
  16837. {
  16838. int connectorIndex = 0;
  16839. //int valueASCII = 0;
  16840. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16841. gunTotalNumber=0;
  16842. SystemInitial = 0;
  16843. locallistVersion=0;
  16844. BootNotificationInterval = 0;
  16845. authorizeRetryTimes = 0;
  16846. GunStatusInterval = 10;
  16847. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16848. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16849. //Hear Beat
  16850. HeartBeatWithNOResponse = 0;
  16851. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16852. FirstHeartBeat = 0;
  16853. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16854. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16855. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16856. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16857. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16858. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16859. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16860. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16861. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16862. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16863. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16864. memset(gunType, 0, ARRAY_SIZE(gunType));
  16865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16866. {
  16867. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16868. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16869. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16870. {
  16871. // DO series
  16872. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16873. {
  16874. SystemInitial = SystemInitial + 1;
  16875. gunTotalNumber = gunTotalNumber + 1;
  16876. gunType[connectorIndex] = GUN_TYPE_DO;
  16877. connectorIndex = connectorIndex + 1;
  16878. }
  16879. }
  16880. else
  16881. {
  16882. // DM, DW, DS series
  16883. //check connector / socket type (index: 8, 9, 10)
  16884. for(int index=7; index <10 ; index++)
  16885. {
  16886. if(index != 8)
  16887. {
  16888. // DC Connector
  16889. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16890. {
  16891. SystemInitial = SystemInitial + 1;
  16892. gunTotalNumber = gunTotalNumber + 1;
  16893. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16894. connectorIndex = connectorIndex + 1;
  16895. }
  16896. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16897. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16898. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16899. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16900. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16901. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16902. {
  16903. SystemInitial = SystemInitial + 1;
  16904. gunTotalNumber = gunTotalNumber + 1;
  16905. gunType[connectorIndex] = GUN_TYPE_CCS;
  16906. connectorIndex = connectorIndex + 1;
  16907. }
  16908. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16909. {
  16910. SystemInitial = SystemInitial + 1;
  16911. gunTotalNumber = gunTotalNumber + 1;
  16912. gunType[connectorIndex] = GUN_TYPE_GBT;
  16913. connectorIndex = connectorIndex + 1;
  16914. }
  16915. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16916. {
  16917. SystemInitial = SystemInitial + 1;
  16918. gunTotalNumber = gunTotalNumber + 1;
  16919. gunType[connectorIndex] = GUN_TYPE_DO;
  16920. connectorIndex = connectorIndex + 1;
  16921. }
  16922. }
  16923. else
  16924. {
  16925. // AC Connector
  16926. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16927. {
  16928. SystemInitial = SystemInitial + 1;
  16929. gunTotalNumber = gunTotalNumber + 1;
  16930. gunType[connectorIndex] = GUN_TYPE_AC;
  16931. connectorIndex = connectorIndex + 1;
  16932. }
  16933. }
  16934. }
  16935. }
  16936. //DEBUG_INFO("DC ...\n");
  16937. }
  16938. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16939. {
  16940. //check connector / socket type (index: 8, 9, 10)
  16941. for(int index=7; index <10 ; index++)
  16942. {
  16943. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16944. {
  16945. SystemInitial = SystemInitial + 1;
  16946. gunTotalNumber = gunTotalNumber + 1;
  16947. gunType[connectorIndex] = GUN_TYPE_AC;
  16948. connectorIndex = connectorIndex + 1;
  16949. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16950. }
  16951. }
  16952. }
  16953. //Status && ConnectorPlugIn Setting
  16954. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16955. {
  16956. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16957. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16958. }
  16959. for (int index = 0; index < CCS_QUANTITY; index++)
  16960. {
  16961. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16962. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16963. }
  16964. for (int index = 0; index < GB_QUANTITY; index++)
  16965. {
  16966. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16967. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16968. }
  16969. for (int index = 0; index < AC_QUANTITY; index++)
  16970. {
  16971. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16972. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16973. }
  16974. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16975. {
  16976. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16977. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16978. }
  16979. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16980. {
  16981. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16982. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16983. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16984. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16985. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16986. }
  16987. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16988. clientTime.Heartbeat=time((time_t*)NULL);
  16989. sleep(1);
  16990. }
  16991. void LWS_Send(char *str)
  16992. {
  16993. //=====================================================
  16994. // Check InternetConn 0: disconnected, 1: connected
  16995. //====================================================
  16996. if(GetOcppConnStatus() == 0)
  16997. {
  16998. DEBUG_INFO("offline now !!!\n");
  16999. return;
  17000. }
  17001. // Only disable isWebsocketSendable operation initiated by charger
  17002. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17003. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17004. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17005. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17006. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17007. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17008. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17009. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17010. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17011. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17012. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17013. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17014. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17015. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17016. {
  17017. isWebsocketSendable = 0;
  17018. }
  17019. pthread_mutex_lock(&lock_send);
  17020. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17021. sprintf((char *)SendBuffer, "%s", str);
  17022. SendBufLen = strlen(str);
  17023. pthread_mutex_unlock(&lock_send);
  17024. lws_callback_on_writable(wsi_client);
  17025. //lws_service(context, 0);
  17026. //sleep(1);
  17027. }
  17028. void LWS_SendNow(char *str)
  17029. {
  17030. //=====================================================
  17031. // Check InternetConn 0: disconnected, 1: connected
  17032. //====================================================
  17033. if(GetOcppConnStatus() == 0)
  17034. {
  17035. DEBUG_INFO("offline now !!!\n");
  17036. return;
  17037. }
  17038. // Only disable isWebsocketSendable operation initiated by charger
  17039. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17040. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17041. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17042. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17043. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17044. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17045. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17046. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17047. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17048. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17049. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17050. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17051. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17052. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17053. {
  17054. isWebsocketSendable = 0;
  17055. }
  17056. pthread_mutex_lock(&lock_send);
  17057. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17058. sprintf((char *)SendBuffer, "%s", str);
  17059. SendBufLen = strlen(str);
  17060. pthread_mutex_unlock(&lock_send);
  17061. lws_callback_on_writable(wsi_client);
  17062. lws_service(context, 0);
  17063. //sleep(1);
  17064. }