MessageHandler.c 847 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583
  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. sleep(1);
  9048. }
  9049. else
  9050. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9051. return result;
  9052. }
  9053. void* GetDiagnosticsProcess(void* data)
  9054. {
  9055. pthread_detach(pthread_self());
  9056. mtrace();
  9057. int retriesInt=0, retryIntervalInt=0;
  9058. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9059. 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};
  9060. int port=0;
  9061. int isSuccess = FALSE;
  9062. char cmdBuf[2048];
  9063. struct tm *tmNow;
  9064. time_t CurrentTime;
  9065. struct tm tmStart;
  9066. struct tm tmStop;
  9067. CurrentTime = time(NULL);
  9068. tmNow=localtime(&CurrentTime);
  9069. uint16_t targetYear, targetMonth;
  9070. json_object *GetDiagnostics;
  9071. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9072. GetDiagnostics = json_tokener_parse(data);
  9073. if(!is_error(GetDiagnostics))
  9074. {
  9075. // Required data
  9076. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9077. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9078. // Optional data
  9079. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9080. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9081. else
  9082. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9083. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9084. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9085. else
  9086. retryIntervalInt = 30;
  9087. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9088. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9089. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9090. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9091. }
  9092. json_object_put(GetDiagnostics);
  9093. // Pack log to compress file
  9094. 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) &&
  9095. (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))
  9096. {
  9097. // Pack system log
  9098. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9099. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9100. targetYear = tmStart.tm_year;
  9101. targetMonth = tmStart.tm_mon;
  9102. do
  9103. {
  9104. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9105. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9106. if(targetMonth+1>=13)
  9107. {
  9108. targetYear += 1;
  9109. targetMonth = 1;
  9110. }
  9111. else
  9112. {
  9113. targetMonth += 1;
  9114. }
  9115. }while((targetYear < (tmNow->tm_year+1900)) ||
  9116. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9117. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9118. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9119. system(cmdBuf);
  9120. // Pack charging & event log
  9121. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9122. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9123. targetYear = tmStart.tm_year;
  9124. targetMonth = tmStart.tm_mon;
  9125. do
  9126. {
  9127. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9128. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9129. if(targetMonth+1>=13)
  9130. {
  9131. targetYear += 1;
  9132. targetMonth = 1;
  9133. }
  9134. else
  9135. {
  9136. targetMonth += 1;
  9137. }
  9138. }while((targetYear < (tmNow->tm_year+1900)) ||
  9139. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9140. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9141. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9142. system(cmdBuf);
  9143. // Combine log file
  9144. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9145. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9146. }
  9147. else
  9148. {
  9149. system("exec /root/logPackTools 'log' 6");
  9150. }
  9151. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9152. system(cmdBuf);
  9153. checkUploadLog();
  9154. //****************location*******************/
  9155. if(strcmp(locationstr,"")==0)
  9156. {
  9157. DEBUG_INFO("location is <Empty>!\n");
  9158. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9159. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9160. goto end;
  9161. }
  9162. memset(protocol, 0, ARRAY_SIZE(protocol));
  9163. memset(user, 0, ARRAY_SIZE(user) );
  9164. memset(password, 0, ARRAY_SIZE(password));
  9165. memset(host, 0, ARRAY_SIZE(host));
  9166. memset(path, 0, ARRAY_SIZE(path));
  9167. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9168. memset(host1, 0, ARRAY_SIZE(host1));
  9169. memset(path1, 0, ARRAY_SIZE(path1));
  9170. /*location: ftp://user:password@host:port/path*/
  9171. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9172. if((access(fnamePlusPath,F_OK))!=-1)
  9173. {
  9174. DEBUG_INFO("fnamePlusPath exist.\n");
  9175. }
  9176. else
  9177. {
  9178. DEBUG_INFO("fnamePlusPath not exist!\n");
  9179. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9180. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9181. goto end;
  9182. }
  9183. if(strchr(locationstr,'@')==NULL)
  9184. {
  9185. sscanf(locationstr,
  9186. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9187. protocol, host, &port, path);
  9188. strcpy(user,"anonymous");
  9189. strcpy(password,"");
  9190. }
  9191. else
  9192. {
  9193. //DEBUG_INFO("pch=%s\n", pch);
  9194. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9195. protocol, user, password, host, &port, path);
  9196. }
  9197. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9198. {
  9199. DEBUG_INFO("protocol is not ftp/http ! \n");
  9200. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9201. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9202. goto end;
  9203. }
  9204. if(strncmp(locationstr,"http", 4) == 0)
  9205. {
  9206. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9207. sprintf(ftppath,"/%s", path);
  9208. do
  9209. {
  9210. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9211. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9212. sleep(3);
  9213. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9214. if(!isSuccess)
  9215. {
  9216. DEBUG_INFO("Diagnostics fail.\n");
  9217. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9218. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9219. sleep(retryIntervalInt);
  9220. }
  9221. else
  9222. {
  9223. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9224. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9225. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9226. }
  9227. retriesInt--;
  9228. }while((isSuccess == 0)&&(retriesInt >= 0));
  9229. }
  9230. else
  9231. {
  9232. sscanf(host,"%[^/]%s",host1, path1);
  9233. if(strlen(path) > 0)
  9234. sprintf(ftppath,"/%s", path);
  9235. else
  9236. sprintf(ftppath,"/%s", path1);
  9237. int ftppathlen=strlen(ftppath);
  9238. int i=1;
  9239. char filenametemp[50];
  9240. while(i < ftppathlen)
  9241. {
  9242. int len=ftppathlen-i;
  9243. if(ftppath[len]== 47) // '/' ascll code: 47
  9244. {
  9245. DEBUG_INFO("find '/' all right\n");
  9246. break;
  9247. }
  9248. i=i+1;
  9249. }
  9250. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9251. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9252. filenametemp[i+1] = 0;
  9253. if(port == 0)
  9254. port = 21;
  9255. do
  9256. {
  9257. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9258. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9259. sleep(3);
  9260. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9261. if(!isSuccess)
  9262. {
  9263. DEBUG_INFO("Diagnostics fail.\n");
  9264. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9265. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9266. sleep(retryIntervalInt);
  9267. }
  9268. else
  9269. {
  9270. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9271. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9272. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9273. }
  9274. retriesInt--;
  9275. }while((!isSuccess)&&(retriesInt >= 0));
  9276. }
  9277. end:
  9278. system("rm -f /mnt/*");
  9279. sleep(5);
  9280. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9281. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9282. interLock.isGetDiagnosticGoing = 0;
  9283. pthread_exit(NULL);
  9284. }
  9285. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9286. {
  9287. mtrace();
  9288. int result = FAIL;
  9289. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9290. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9291. {
  9292. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9293. locallistVersion = -1;
  9294. }
  9295. else
  9296. {
  9297. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9298. OCPP_getListVerion();
  9299. }
  9300. //from db.OCPP_getListVerion
  9301. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9302. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9303. sendGetLocalListVersionConfirmation(uuid,"");
  9304. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9305. return result;
  9306. }
  9307. int handleRemoteStartRequest(char *uuid, char *payload)
  9308. {
  9309. mtrace();
  9310. int result = FAIL;
  9311. int connectorIdInt=-1;
  9312. int tempIndex = 0;
  9313. int connectorIdIsNULL, chargingProfileIsNULL;
  9314. char comfirmstr[20]={0};
  9315. char cmdBuf[512];
  9316. json_object *RemoteStartTransaction;
  9317. FILE *fp;
  9318. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9319. if(server_pending == TRUE)
  9320. {
  9321. return 0;
  9322. }
  9323. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9324. RemoteStartTransaction = json_tokener_parse(payload);
  9325. if(!is_error(RemoteStartTransaction))
  9326. {
  9327. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9328. {
  9329. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9330. }
  9331. else
  9332. {
  9333. connectorIdIsNULL = TRUE;
  9334. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9335. {
  9336. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9337. {
  9338. connectorIdIsNULL = FALSE;
  9339. connectorIdInt = (gun_index+1);
  9340. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9341. break;
  9342. }
  9343. }
  9344. }
  9345. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9346. {
  9347. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9348. // Required data
  9349. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9350. // Optional data
  9351. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9352. {
  9353. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9354. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9355. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9356. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9357. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9358. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9359. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9360. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9361. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9362. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9363. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9364. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9365. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9366. {
  9367. 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")));
  9368. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9369. 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"));
  9370. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9371. 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"));
  9372. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9373. 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")));
  9374. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9375. {
  9376. 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++)
  9377. {
  9378. 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"));
  9379. 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"));
  9380. 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)
  9381. 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"));
  9382. }
  9383. }
  9384. }
  9385. }
  9386. else
  9387. {
  9388. chargingProfileIsNULL = TRUE;
  9389. }
  9390. }
  9391. }
  9392. else
  9393. {
  9394. connectorIdIsNULL = TRUE;
  9395. }
  9396. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9397. {
  9398. DEBUG_WARN("Connector id is NULL\n.");
  9399. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9400. goto end;
  9401. }
  9402. /*
  9403. enum _SYSTEM_STATUS
  9404. {
  9405. S_BOOTING = 0,
  9406. S_IDLE, = 1
  9407. S_AUTHORIZING, = 2
  9408. S_REASSIGN_CHECK, = 3
  9409. S_REASSIGN, = 4
  9410. S_PRECHARGE, = 5
  9411. S_PREPARING_FOR_EV, = 6
  9412. S_PREPARING_FOR_EVSE, = 7
  9413. S_CHARGING, = 8
  9414. S_TERMINATING, = 9
  9415. S_COMPLETE, = 10
  9416. S_ALARM, = 11
  9417. S_FAULT = 12
  9418. }
  9419. */
  9420. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9421. {
  9422. //check Transaction active
  9423. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9424. {
  9425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9426. {
  9427. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9428. }
  9429. else
  9430. {
  9431. tempIndex = connectorIdInt -1;
  9432. }
  9433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9434. {
  9435. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9436. {
  9437. 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))
  9438. {
  9439. //Reserved
  9440. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9441. }
  9442. 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))
  9443. {
  9444. //Reserved
  9445. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9447. goto end;
  9448. }
  9449. else
  9450. {
  9451. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9452. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9453. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9454. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9455. {
  9456. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9457. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9458. goto end;
  9459. }
  9460. }//END FOR ELSE
  9461. }
  9462. }// END FOR CHAdeMO_QUANTITY
  9463. }
  9464. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9465. {
  9466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9467. {
  9468. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9469. }
  9470. else
  9471. {
  9472. tempIndex = connectorIdInt -1;
  9473. }
  9474. for (int index = 0; index < CCS_QUANTITY; index++)
  9475. {
  9476. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9477. {
  9478. 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))
  9479. {
  9480. //Reserved
  9481. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9482. }
  9483. 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))
  9484. {
  9485. //Reserved
  9486. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9487. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9488. goto end;
  9489. }
  9490. else
  9491. {
  9492. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9493. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9494. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9495. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9496. {
  9497. DEBUG_WARN("CCS connector not allow start\n.");
  9498. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9499. goto end;
  9500. }
  9501. }// END FOR ELSE
  9502. }
  9503. }// END FOR CCS_QUANTITY
  9504. }
  9505. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9506. {
  9507. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9508. {
  9509. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9510. }
  9511. else
  9512. {
  9513. tempIndex = connectorIdInt -1;
  9514. }
  9515. for (int index = 0; index < GB_QUANTITY; index++)
  9516. {
  9517. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9518. {
  9519. 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))
  9520. {
  9521. //Reserved
  9522. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9523. }
  9524. 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))
  9525. {
  9526. //Reserved
  9527. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9528. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9529. goto end;
  9530. }
  9531. else
  9532. {
  9533. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9534. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9535. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9536. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9537. {
  9538. DEBUG_WARN("GB connector not allow start\n.");
  9539. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9540. goto end;
  9541. }
  9542. }// END FOR ELSE
  9543. }
  9544. } // END FOR GB_QUANTITY
  9545. }
  9546. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9547. {
  9548. tempIndex = connectorIdInt -1;
  9549. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9550. {
  9551. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9552. {
  9553. 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))
  9554. {
  9555. //Reserved
  9556. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9557. }
  9558. 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))
  9559. {
  9560. //Reserved
  9561. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9562. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9563. goto end;
  9564. }
  9565. else
  9566. {
  9567. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9568. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9569. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9570. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9571. {
  9572. DEBUG_WARN("GB connector not allow start\n.");
  9573. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9574. goto end;
  9575. }
  9576. }// END FOR ELSE
  9577. }
  9578. } // END FOR GB_QUANTITY
  9579. }
  9580. else
  9581. {
  9582. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9583. {
  9584. tempIndex = 2;
  9585. }
  9586. else
  9587. {
  9588. tempIndex = connectorIdInt -1;
  9589. }
  9590. for (int index = 0; index < AC_QUANTITY; index++)
  9591. {
  9592. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9593. {
  9594. 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))
  9595. {
  9596. //Reserved
  9597. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9598. }
  9599. 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))
  9600. {
  9601. //Reserved
  9602. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9603. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9604. goto end;
  9605. }
  9606. else
  9607. {
  9608. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9609. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9610. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9611. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9612. {
  9613. DEBUG_WARN("AC connector not allow start\n.");
  9614. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9615. goto end;
  9616. }
  9617. }//END FOR ELSE
  9618. }
  9619. }// END FOR AC_QUANTITY
  9620. }
  9621. if(chargingProfileIsNULL == FALSE)
  9622. {
  9623. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9624. {
  9625. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9626. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9627. //memset idTag
  9628. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9629. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9630. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9631. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9632. // Save profile to file
  9633. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9634. system(cmdBuf);
  9635. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9636. fp = fopen(cmdBuf, "w");
  9637. 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));
  9638. fclose(fp);
  9639. }
  9640. else
  9641. {
  9642. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9643. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9644. }
  9645. }
  9646. else
  9647. {
  9648. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9649. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9650. //memset idTag
  9651. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9652. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9653. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9654. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9655. }
  9656. }
  9657. else
  9658. {
  9659. DEBUG_WARN("Connector id over\n.");
  9660. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9661. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9662. }
  9663. end:
  9664. json_object_put(RemoteStartTransaction);
  9665. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9666. {
  9667. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9668. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9669. }
  9670. //OCPP send RemoteStartConfirmation by first.
  9671. sendRemoteStartConfirmation(uuid, comfirmstr);
  9672. return result;
  9673. }
  9674. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9675. {
  9676. mtrace();
  9677. int result = FAIL;
  9678. int match = FALSE;
  9679. int GunNO = 0;
  9680. int tempIndex = 0;
  9681. int transactionIdInt=0;
  9682. int transactionIdIsNULL= TRUE;
  9683. char comfirmstr[20];
  9684. json_object *RemoteStopTransaction;
  9685. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9686. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9687. if(server_pending == TRUE)
  9688. {
  9689. return 0;
  9690. }
  9691. RemoteStopTransaction = json_tokener_parse(payload);
  9692. if(!is_error(RemoteStopTransaction))
  9693. {
  9694. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9695. {
  9696. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9697. transactionIdIsNULL = FALSE;
  9698. }
  9699. }
  9700. json_object_put(RemoteStopTransaction);
  9701. if(transactionIdIsNULL == FALSE)
  9702. {
  9703. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9704. {
  9705. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9706. {
  9707. //check Transaction active
  9708. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9709. {
  9710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9711. {
  9712. tempIndex = ((gun_index==2) ? 1: 0);
  9713. }
  9714. else
  9715. {
  9716. tempIndex = gun_index;
  9717. }
  9718. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9719. {
  9720. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9721. {
  9722. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9723. {
  9724. match = TRUE;
  9725. GunNO = gun_index;
  9726. }
  9727. }
  9728. }// END FOR CHAdeMO_QUANTITY
  9729. }
  9730. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9731. {
  9732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9733. {
  9734. tempIndex = ((gun_index==2) ? 1: 0);
  9735. }
  9736. else
  9737. {
  9738. tempIndex = gun_index;
  9739. }
  9740. for (int index = 0; index < CCS_QUANTITY; index++)
  9741. {
  9742. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9743. {
  9744. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9745. {
  9746. match = TRUE;
  9747. GunNO = gun_index;
  9748. }
  9749. }
  9750. }// END FOR CCS_QUANTITY
  9751. }
  9752. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9753. {
  9754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9755. {
  9756. tempIndex = ((gun_index==2) ? 1: 0);
  9757. }
  9758. else
  9759. {
  9760. tempIndex = gun_index;
  9761. }
  9762. for (int index = 0; index < GB_QUANTITY; index++)
  9763. {
  9764. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9765. {
  9766. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9767. {
  9768. match = TRUE;
  9769. GunNO = gun_index;
  9770. }
  9771. }
  9772. }// END FOR GB_QUANTITY
  9773. }
  9774. else if(gunType[gun_index] == GUN_TYPE_DO)
  9775. {
  9776. tempIndex = gun_index;
  9777. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9778. {
  9779. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9780. {
  9781. 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
  9782. {
  9783. match = TRUE;
  9784. GunNO = gun_index;
  9785. }
  9786. }
  9787. }// END FOR GB_QUANTITY
  9788. }
  9789. else
  9790. {
  9791. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9792. {
  9793. tempIndex = 2;
  9794. }
  9795. else
  9796. {
  9797. tempIndex = gun_index;
  9798. }
  9799. for (int index = 0; index < AC_QUANTITY; index++)
  9800. {
  9801. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9802. {
  9803. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9804. {
  9805. match = TRUE;
  9806. GunNO = gun_index;
  9807. }
  9808. }
  9809. }// END FOR CHAdeMO_QUANTITY
  9810. } // END FOR AC ELSE
  9811. }// CHECK IF ResponseTransactionId == transactionIdInt
  9812. }//END FOR
  9813. if( match == TRUE)
  9814. {
  9815. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9816. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9817. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9818. }
  9819. else
  9820. {
  9821. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9822. }
  9823. }
  9824. else
  9825. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9826. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9827. return result;
  9828. }
  9829. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9830. {
  9831. mtrace();
  9832. int result = FAIL;
  9833. int connectorIdInt=0, reservationIdInt=0;
  9834. int tempIndex = 0;
  9835. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9836. char comfirmstr[20]={0};
  9837. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9838. int c = 0;
  9839. char *loc;
  9840. //char *ptr;
  9841. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9842. strcpy(sstrtemp, stringtrimspace(payload));
  9843. //***(1)connectorId ****/
  9844. c=0;
  9845. loc = strstr(sstrtemp, "connectorId");
  9846. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9847. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9848. {
  9849. sstr[c] = loc[strlen("connectorId")+2+c];
  9850. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9851. c++;
  9852. }
  9853. sstr[c] = '\0';
  9854. connectorIdInt = atoi(sstr);
  9855. //***(2)expiryDate ****/
  9856. loc = strstr(sstrtemp, "expiryDate");
  9857. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9858. c = 0;
  9859. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9860. {
  9861. sstr[c] = loc[3+strlen("expiryDate")+c];
  9862. c++;
  9863. }
  9864. sstr[c] = '\0';
  9865. strcpy(expiryDatestr, sstr);
  9866. //***(3)idTag ****/
  9867. loc = strstr(sstrtemp, "idTag");
  9868. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9869. c = 0;
  9870. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9871. {
  9872. sstr[c] = loc[3+strlen("idTag")+c];
  9873. c++;
  9874. }
  9875. sstr[c] = '\0';
  9876. strcpy(idTagstr, sstr);
  9877. //***(4)parentIdTag ****/
  9878. loc = strstr(sstrtemp, "parentIdTag");
  9879. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9880. c = 0;
  9881. if(loc == NULL)
  9882. {
  9883. strcpy(parentIdTagstr, "");
  9884. }
  9885. else
  9886. {
  9887. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9888. {
  9889. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9890. c++;
  9891. }
  9892. sstr[c] = '\0';
  9893. strcpy(parentIdTagstr, sstr);
  9894. }
  9895. //***(5)reservationId ****/
  9896. c=0;
  9897. loc = strstr(sstrtemp, "reservationId");
  9898. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9899. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9900. {
  9901. sstr[c] = loc[strlen("reservationId")+2+c];
  9902. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9903. c++;
  9904. }
  9905. sstr[c] = '\0';
  9906. reservationIdInt = atoi(sstr);
  9907. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9908. /*
  9909. enum SYSTEM_STATUS
  9910. {
  9911. SYS_MODE_BOOTING = 0,
  9912. SYS_MODE_IDLE = 1,
  9913. SYS_MODE_AUTHORIZING = 2,
  9914. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9915. SYS_MODE_REASSIGN = 4,
  9916. SYS_MODE_PREPARING = 5,
  9917. SYS_MODE_PREPARE_FOR_EV = 6,
  9918. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9919. SYS_MODE_CHARGING = 8,
  9920. SYS_MODE_TERMINATING = 9,
  9921. SYS_MODE_COMPLETE = 10,
  9922. SYS_MODE_ALARM = 11,
  9923. SYS_MODE_FAULT = 12,
  9924. SYS_MODE_RESERVATION = 13,
  9925. SYS_MODE_BOOKING = 14,
  9926. SYS_MODE_MAINTAIN = 15,
  9927. SYS_MODE_DEBUG = 16,
  9928. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9929. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9930. SYS_MODE_UPDATE = 19
  9931. };
  9932. */
  9933. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9934. {
  9935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9936. goto end;
  9937. }
  9938. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9939. {
  9940. //check Transaction active
  9941. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9942. {
  9943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9944. {
  9945. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9946. }
  9947. else
  9948. {
  9949. tempIndex = connectorIdInt -1;
  9950. }
  9951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9952. {
  9953. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9954. {
  9955. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9956. {
  9957. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9958. {
  9959. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9960. {
  9961. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9963. }
  9964. 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'))
  9965. {
  9966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9967. }
  9968. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9969. {
  9970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9971. }
  9972. else
  9973. {
  9974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9975. }
  9976. }
  9977. 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
  9978. {
  9979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9980. }
  9981. }
  9982. else
  9983. {
  9984. //replace reservation
  9985. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9987. }
  9988. }
  9989. } // END FOR CHAdeMO_QUANTITY
  9990. }
  9991. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9992. {
  9993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9994. {
  9995. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9996. }
  9997. else
  9998. {
  9999. tempIndex = connectorIdInt -1;
  10000. }
  10001. for (int index = 0; index < CCS_QUANTITY; index++)
  10002. {
  10003. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10004. {
  10005. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10006. {
  10007. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10008. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10009. {
  10010. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10011. {
  10012. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10014. }
  10015. 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'))
  10016. {
  10017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10018. }
  10019. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10020. {
  10021. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10022. }
  10023. else
  10024. {
  10025. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10026. }
  10027. }
  10028. 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
  10029. {
  10030. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10031. }
  10032. }
  10033. else
  10034. {
  10035. //replace reservation
  10036. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10037. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10038. }
  10039. }
  10040. } // END FOR CCS_QUANTITY
  10041. }
  10042. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10043. {
  10044. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10045. {
  10046. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10047. }
  10048. else
  10049. {
  10050. tempIndex = connectorIdInt -1;
  10051. }
  10052. for (int index = 0; index < GB_QUANTITY; index++)
  10053. {
  10054. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10055. {
  10056. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10057. {
  10058. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10059. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10060. {
  10061. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10062. {
  10063. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10065. }
  10066. 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'))
  10067. {
  10068. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10069. }
  10070. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10071. {
  10072. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10073. }
  10074. else
  10075. {
  10076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10077. }
  10078. }
  10079. 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
  10080. {
  10081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10082. }
  10083. }
  10084. else
  10085. {
  10086. //replace reservation
  10087. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10089. }
  10090. }
  10091. }// END FOR GB_QUANTITY
  10092. }
  10093. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10094. {
  10095. tempIndex = connectorIdInt -1;
  10096. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10097. {
  10098. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10099. {
  10100. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10101. {
  10102. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10103. 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
  10104. {
  10105. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10106. {
  10107. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10108. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10109. }
  10110. 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'))
  10111. {
  10112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10113. }
  10114. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10115. {
  10116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10117. }
  10118. else
  10119. {
  10120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10121. }
  10122. }
  10123. 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
  10124. {
  10125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10126. }
  10127. }
  10128. else
  10129. {
  10130. //replace reservation
  10131. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10133. }
  10134. }
  10135. }// END FOR GB_QUANTITY
  10136. }
  10137. else
  10138. {
  10139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10140. {
  10141. tempIndex = 2;
  10142. }
  10143. else
  10144. {
  10145. tempIndex = (connectorIdInt -1);
  10146. }
  10147. for (int index = 0; index < AC_QUANTITY; index++)
  10148. {
  10149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10150. {
  10151. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10152. {
  10153. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10154. {
  10155. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10156. {
  10157. 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))
  10158. {
  10159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10160. }
  10161. else
  10162. {
  10163. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10165. }
  10166. }
  10167. 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'))
  10168. {
  10169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10170. }
  10171. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10172. {
  10173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10174. }
  10175. else
  10176. {
  10177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10178. }
  10179. }
  10180. 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
  10181. {
  10182. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10183. }
  10184. }
  10185. else
  10186. {
  10187. //replace reservation
  10188. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10189. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10190. }
  10191. }
  10192. } // END FOR AC_QUANTITY
  10193. }
  10194. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10195. }
  10196. else if(connectorIdInt == 0)
  10197. {
  10198. //check Transaction active
  10199. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10200. {
  10201. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10202. {
  10203. 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'))
  10204. {
  10205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10206. goto end;
  10207. }
  10208. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10209. {
  10210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10211. goto end;
  10212. }
  10213. 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
  10214. {
  10215. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10216. goto end;
  10217. }
  10218. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10219. {
  10220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10221. goto end;
  10222. }
  10223. }
  10224. }// END FOR CHAdeMO_QUANTITY
  10225. for (int index = 0; index < CCS_QUANTITY; index++)
  10226. {
  10227. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10228. {
  10229. 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'))
  10230. {
  10231. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10232. goto end;
  10233. }
  10234. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10235. {
  10236. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10237. goto end;
  10238. }
  10239. 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
  10240. {
  10241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10242. goto end;
  10243. }
  10244. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10245. {
  10246. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10247. goto end;
  10248. }
  10249. }
  10250. } // END FOR CCS_QUANTITY
  10251. for (int index = 0; index < GB_QUANTITY; index++)
  10252. {
  10253. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10254. {
  10255. 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'))
  10256. {
  10257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10258. goto end;
  10259. }
  10260. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10261. {
  10262. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10263. goto end;
  10264. }
  10265. 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
  10266. {
  10267. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10268. goto end;
  10269. }
  10270. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10271. {
  10272. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10273. goto end;
  10274. }
  10275. }
  10276. } // END FOR GB_QUANTITY
  10277. for (int index = 0; index < AC_QUANTITY; index++)
  10278. {
  10279. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10280. {
  10281. 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'))
  10282. {
  10283. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10284. goto end;
  10285. }
  10286. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10287. {
  10288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10289. goto end;
  10290. }
  10291. 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
  10292. {
  10293. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10294. goto end;
  10295. }
  10296. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10297. {
  10298. 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))
  10299. {
  10300. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10301. goto end;
  10302. }
  10303. }
  10304. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10305. {
  10306. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10307. goto end;
  10308. }
  10309. }
  10310. }// END FOR AC_QUANTITY
  10311. //The connectorId is 0
  10312. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10313. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10314. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10315. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10316. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10317. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10318. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10319. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10320. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10321. result = TRUE;
  10322. return result;
  10323. }
  10324. else
  10325. {
  10326. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10327. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10328. }
  10329. if(strcmp(comfirmstr,"Accepted") == 0)
  10330. {
  10331. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10332. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10333. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10334. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10335. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10336. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10337. result = TRUE;
  10338. return result;
  10339. }
  10340. end:
  10341. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10342. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10343. return result;
  10344. }
  10345. int handleResetRequest(char *uuid, char *payload)
  10346. {
  10347. mtrace();
  10348. int result = FAIL;
  10349. char sstr[10]={0},sstrtemp[30]={ 0 };
  10350. char typestr[10]={0};
  10351. char comfirmstr[20]={0};
  10352. int c = 0;
  10353. char *loc;
  10354. DEBUG_INFO("handleResetRequest...\n");
  10355. strcpy(sstrtemp, stringtrimspace(payload));
  10356. loc = strstr(sstrtemp, "type");
  10357. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10358. c = 0;
  10359. while (loc[3+strlen("type")+c] != '\"')
  10360. {
  10361. sstr[c] = loc[3+strlen("type")+c];
  10362. c++;
  10363. }
  10364. sstr[c] = '\0';
  10365. strcpy(typestr,sstr);
  10366. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10367. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10368. {
  10369. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10370. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10371. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10372. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10373. }
  10374. else
  10375. {
  10376. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10377. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10378. result = PASS;
  10379. }
  10380. sendResetConfirmation(uuid, comfirmstr);
  10381. return result;
  10382. }
  10383. int handleSendLocalListRequest(char *uuid, char *payload)
  10384. {
  10385. mtrace();
  10386. int result = FAIL;
  10387. char comfirmstr[20];
  10388. int checkState_Faulted = FALSE;
  10389. json_object *SendLocalList;
  10390. DEBUG_INFO("handleSendLocalListRequest...\n");
  10391. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10392. {
  10393. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10394. goto end;
  10395. }
  10396. //check Charge Point state
  10397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10398. {
  10399. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10400. {
  10401. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10402. }
  10403. }
  10404. for (int index = 0; index < CCS_QUANTITY; index++)
  10405. {
  10406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10407. {
  10408. checkState_Faulted = TRUE; //OCPP Status
  10409. }
  10410. }
  10411. for (int index = 0; index < GB_QUANTITY; index++)
  10412. {
  10413. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10414. {
  10415. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10416. }
  10417. }
  10418. //check Charge Point state
  10419. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10420. {
  10421. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10422. {
  10423. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10424. }
  10425. }
  10426. //check Charge Point state
  10427. for (int index = 0; index < AC_QUANTITY; index++)
  10428. {
  10429. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10430. {
  10431. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10432. }
  10433. }
  10434. if(checkState_Faulted == TRUE)
  10435. {
  10436. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10437. goto end;
  10438. }
  10439. // Parsing payload
  10440. SendLocalList = json_tokener_parse(payload);
  10441. if(!is_error(SendLocalList))
  10442. {
  10443. // Required data
  10444. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10445. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10446. // Optional data
  10447. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10448. {
  10449. //Check UpdateType
  10450. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10451. {
  10452. //Local list full update
  10453. DEBUG_INFO("Local list full update.\n");
  10454. OCPP_getListVerion();
  10455. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10456. {
  10457. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10458. goto end;
  10459. }
  10460. OCPP_cleanLocalList();
  10461. }
  10462. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10463. {
  10464. //Local list different update
  10465. DEBUG_INFO("Local list different update.\n");
  10466. OCPP_getListVerion();
  10467. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10468. {
  10469. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10470. goto end;
  10471. }
  10472. }
  10473. else
  10474. {
  10475. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10476. goto end;
  10477. }
  10478. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10479. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10480. {
  10481. 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")));
  10482. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10483. {
  10484. 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")));
  10485. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10486. 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")));
  10487. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10488. 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")));
  10489. }
  10490. // Add to db
  10491. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10492. {
  10493. //Local list full update
  10494. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10495. idx,
  10496. ShmOCPP16Data->SendLocalList.ListVersion,
  10497. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10498. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10499. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10500. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10501. // update list
  10502. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10503. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10504. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10505. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10506. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10507. }
  10508. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10509. {
  10510. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10511. idx,
  10512. ShmOCPP16Data->SendLocalList.ListVersion,
  10513. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10514. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10515. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10516. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10517. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10518. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  10519. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10520. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10521. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10522. }
  10523. }
  10524. }
  10525. else
  10526. {
  10527. //Check UpdateType
  10528. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10529. {
  10530. //Local list full update
  10531. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10532. OCPP_cleanLocalList();
  10533. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10534. goto end;
  10535. }
  10536. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10537. {
  10538. //Local list different update
  10539. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10540. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10541. goto end;
  10542. }
  10543. }
  10544. result = PASS;
  10545. }
  10546. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10547. end:
  10548. json_object_put(SendLocalList);
  10549. sendSendLocalListConfirmation(uuid, comfirmstr);
  10550. return result;
  10551. }
  10552. #define MAX 200
  10553. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10554. {
  10555. mtrace();
  10556. int result = FAIL;
  10557. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10558. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10559. char chargingProfilePurposeStr[30]={0};
  10560. char chargingProfileKindStr[16]={0};
  10561. char recurrencyKindStr[10]={0};
  10562. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10563. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10564. int chargingSchedulePeriodCount = 0;
  10565. char comfirmstr[20]={0};
  10566. int meet= FALSE;
  10567. FILE *fptr1;
  10568. char filename[MAX]={0};
  10569. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10570. char rmFileCmd[50]={0};
  10571. char tempchargingProfilePurposeStr[30]={0};
  10572. char word[1600]={0};
  10573. int n_chargingProfile = 0;
  10574. json_object *SetChargingProfile;
  10575. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10576. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10577. SetChargingProfile = json_tokener_parse(payload);
  10578. if(!is_error(SetChargingProfile))
  10579. {
  10580. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10581. {
  10582. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10583. if(connectorIdInt == 0)
  10584. {
  10585. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10586. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10587. }
  10588. else
  10589. {
  10590. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10591. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10592. }
  10593. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10594. }
  10595. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10596. {
  10597. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10598. {
  10599. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10600. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10601. {
  10602. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10603. }
  10604. else
  10605. {
  10606. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10607. }
  10608. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10609. }
  10610. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10611. {
  10612. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10613. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10614. {
  10615. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10616. }
  10617. else
  10618. {
  10619. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10620. }
  10621. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10622. }
  10623. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10624. {
  10625. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10626. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10627. {
  10628. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10629. }
  10630. else
  10631. {
  10632. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10633. }
  10634. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10635. }
  10636. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10637. {
  10638. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10639. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10640. {
  10641. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10642. }
  10643. else
  10644. {
  10645. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10646. }
  10647. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10648. }
  10649. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10650. {
  10651. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10652. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10653. {
  10654. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10655. }
  10656. else
  10657. {
  10658. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10659. }
  10660. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10661. }
  10662. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10663. {
  10664. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10665. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10666. {
  10667. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10668. }
  10669. else
  10670. {
  10671. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10672. }
  10673. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10674. }
  10675. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10676. {
  10677. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10678. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10679. {
  10680. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10681. }
  10682. else
  10683. {
  10684. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10685. }
  10686. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10687. }
  10688. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10689. {
  10690. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10691. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10692. {
  10693. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10694. }
  10695. else
  10696. {
  10697. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10698. }
  10699. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10700. }
  10701. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10702. {
  10703. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10704. {
  10705. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10706. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10707. {
  10708. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10709. }
  10710. else
  10711. {
  10712. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10713. }
  10714. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10715. }
  10716. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10717. {
  10718. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10719. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10720. {
  10721. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10722. }
  10723. else
  10724. {
  10725. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10726. }
  10727. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10728. }
  10729. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10730. {
  10731. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10732. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10733. {
  10734. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10735. }
  10736. else
  10737. {
  10738. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10739. }
  10740. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10741. }
  10742. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10743. {
  10744. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10745. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10746. {
  10747. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10748. }
  10749. else
  10750. {
  10751. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10752. }
  10753. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10754. }
  10755. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10756. {
  10757. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10758. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10759. if(chargingSchedulePeriodCount <= 10)
  10760. {
  10761. 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++)
  10762. {
  10763. 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)
  10764. {
  10765. 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"));
  10766. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10767. {
  10768. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10769. }
  10770. else
  10771. {
  10772. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10773. }
  10774. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10775. }
  10776. 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)
  10777. {
  10778. 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"));
  10779. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10780. {
  10781. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10782. }
  10783. else
  10784. {
  10785. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10786. }
  10787. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10788. }
  10789. 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)
  10790. {
  10791. 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"));
  10792. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10793. {
  10794. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10795. }
  10796. else
  10797. {
  10798. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10799. }
  10800. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10801. }
  10802. }
  10803. }
  10804. }
  10805. }
  10806. }
  10807. }
  10808. json_object_put(SetChargingProfile);
  10809. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10810. {
  10811. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10812. goto end;
  10813. }
  10814. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10815. {
  10816. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10817. if(connectorIdInt != 0)
  10818. {
  10819. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10820. goto end;
  10821. }
  10822. strcpy(filename, ChargePointMaxProfile_JSON );
  10823. fptr1 = fopen(filename, "r");
  10824. if (!fptr1)
  10825. {
  10826. //file not exist
  10827. DEBUG_INFO("Unable to open the input file!!\n");
  10828. fptr1 = fopen(filename, "w+");
  10829. }
  10830. else
  10831. {
  10832. //Check Charging Profile Count
  10833. while(fscanf(fptr1, "%s", word) != EOF)
  10834. {
  10835. //DEBUG_INFO("word=%s\n",word);
  10836. if(strstr(word, "chargingProfileId")!= NULL)
  10837. {
  10838. //DEBUG_INFO("test chargingProfileId \n");
  10839. n_chargingProfile = n_chargingProfile + 1;
  10840. //DEBUG_INFO("chargingProfileId Found\n");
  10841. }
  10842. }
  10843. }
  10844. fclose(fptr1);
  10845. }
  10846. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10847. {
  10848. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10849. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10850. {
  10851. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10852. goto end;
  10853. }
  10854. memset(filename, 0, ARRAY_SIZE(filename));
  10855. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10856. fptr1 = fopen(filename, "r");
  10857. if (!fptr1)
  10858. {
  10859. //file not exist
  10860. //DEBUG_INFO("Unable to open the input file!!\n");
  10861. fptr1 = fopen(filename, "w+");
  10862. }
  10863. else
  10864. {
  10865. //Check Charging Profile Count
  10866. while(fscanf(fptr1, "%s", word) != EOF)
  10867. {
  10868. //DEBUG_INFO("word=%s\n",word);
  10869. if(strstr(word, "chargingProfileId")!= NULL)
  10870. {
  10871. //DEBUG_INFO("test chargingProfileId \n");
  10872. n_chargingProfile = n_chargingProfile + 1;
  10873. //DEBUG_INFO("chargingProfileId Found\n");
  10874. }
  10875. }
  10876. }
  10877. fclose(fptr1);
  10878. }
  10879. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10880. {
  10881. //printf("set chargingProfile 1-4\n");
  10882. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10883. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10884. if(connectorIdInt == 0)
  10885. {
  10886. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10887. goto end;
  10888. }
  10889. int tempIndex = 0;
  10890. //check Transaction active
  10891. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10892. {
  10893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10894. {
  10895. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10896. }
  10897. else
  10898. {
  10899. tempIndex = connectorIdInt -1;
  10900. }
  10901. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10902. {
  10903. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10904. {
  10905. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10906. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10907. {
  10908. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10909. {
  10910. meet = TRUE;
  10911. break;
  10912. }
  10913. }
  10914. }
  10915. }
  10916. }
  10917. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10918. {
  10919. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10920. {
  10921. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10922. }
  10923. else
  10924. {
  10925. tempIndex = connectorIdInt -1;
  10926. }
  10927. for (int index = 0; index < CCS_QUANTITY; index++)
  10928. {
  10929. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10930. {
  10931. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10932. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10933. {
  10934. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10935. {
  10936. meet = TRUE;
  10937. break;
  10938. }
  10939. }
  10940. }
  10941. }
  10942. }
  10943. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10944. {
  10945. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10946. {
  10947. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10948. }
  10949. else
  10950. {
  10951. tempIndex = connectorIdInt -1;
  10952. }
  10953. for (int index = 0; index < GB_QUANTITY; index++)
  10954. {
  10955. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10956. {
  10957. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10958. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10959. {
  10960. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10961. {
  10962. meet = TRUE;
  10963. break;
  10964. }
  10965. }
  10966. }
  10967. }
  10968. }
  10969. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10970. {
  10971. tempIndex = connectorIdInt -1;
  10972. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10973. {
  10974. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10975. {
  10976. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10977. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10978. {
  10979. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10980. {
  10981. meet = TRUE;
  10982. break;
  10983. }
  10984. }
  10985. }
  10986. }
  10987. }
  10988. else
  10989. {
  10990. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10991. {
  10992. tempIndex = 2;
  10993. }
  10994. else
  10995. {
  10996. tempIndex = (connectorIdInt -1);
  10997. }
  10998. for (int index = 0; index < AC_QUANTITY; index++)
  10999. {
  11000. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11001. {
  11002. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11003. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11004. {
  11005. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  11006. {
  11007. meet = TRUE;
  11008. break;
  11009. }
  11010. }
  11011. }
  11012. }
  11013. }
  11014. //check Transaction active
  11015. if(meet == FALSE)
  11016. {
  11017. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11018. goto end;
  11019. }
  11020. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  11021. {
  11022. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11023. goto end;
  11024. }
  11025. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  11026. fptr1 = fopen(filename, "r");
  11027. if (!fptr1)
  11028. {
  11029. //file not exist
  11030. DEBUG_INFO("Unable to open the input file!!\n");
  11031. fptr1 = fopen(filename, "w+");
  11032. }
  11033. else
  11034. {
  11035. //Check Charging Profile Count
  11036. while(fscanf(fptr1, "%s", word) != EOF)
  11037. {
  11038. //DEBUG_INFO("word=%s\n",word);
  11039. if(strstr(word, "chargingProfileId")!= NULL)
  11040. {
  11041. //DEBUG_INFO("test chargingProfileId \n");
  11042. n_chargingProfile = n_chargingProfile + 1;
  11043. //DEBUG_INFO("chargingProfileId Found\n");
  11044. }
  11045. }
  11046. }
  11047. fclose(fptr1);
  11048. }
  11049. // Check ChargeProfileMaxStackLevel
  11050. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11051. {
  11052. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11053. goto end;
  11054. }
  11055. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11056. {
  11057. int i = 0;
  11058. char fnametemp[200]={0};
  11059. n_chargingProfile = 0;
  11060. //Check ChargePointMaxProfile.json exit
  11061. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11062. {
  11063. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11064. //Check Charging Profile Count
  11065. while(fscanf(fptr1, "%s", word) != EOF)
  11066. {
  11067. //DEBUG_INFO("word=%s\n",word);
  11068. if(strstr(word, "chargingProfileId")!= NULL)
  11069. {
  11070. //DEBUG_INFO("test chargingProfileId \n");
  11071. n_chargingProfile = n_chargingProfile + 1;
  11072. i = i + 1;
  11073. //DEBUG_INFO("chargingProfileId Found\n");
  11074. }
  11075. memset(word, 0, ARRAY_SIZE(word));
  11076. }
  11077. fclose(fptr1);
  11078. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  11079. }
  11080. //Check TxDefaultProfile_0.json exit
  11081. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  11082. {
  11083. i = 0;
  11084. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  11085. //Check Charging Profile Count
  11086. while(fscanf(fptr1, "%s", word) != EOF)
  11087. {
  11088. //DEBUG_INFO("word=%s\n",word);
  11089. if(strstr(word, "chargingProfileId")!= NULL)
  11090. {
  11091. //DEBUG_INFO("test chargingProfileId \n");
  11092. n_chargingProfile = n_chargingProfile + 1;
  11093. i = i + 1;
  11094. //DEBUG_INFO("chargingProfileId Found\n");
  11095. }
  11096. memset(word, 0, ARRAY_SIZE(word));
  11097. }
  11098. fclose(fptr1);
  11099. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  11100. }
  11101. //Check TxDefaultProfile_%d.json
  11102. for(int j=1; j <= gunTotalNumber; j++)
  11103. {
  11104. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11105. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  11106. if((access(fnametemp,F_OK))!=-1)
  11107. {
  11108. i = 0;
  11109. fptr1 = fopen(fnametemp, "r");
  11110. //Check Charging Profile Count
  11111. while(fscanf(fptr1, "%s", word) != EOF)
  11112. {
  11113. //DEBUG_INFO("word=%s\n",word);
  11114. if(strstr(word, "chargingProfileId")!= NULL)
  11115. {
  11116. //DEBUG_INFO("test chargingProfileId \n");
  11117. n_chargingProfile = n_chargingProfile + 1;
  11118. i = i + 1;
  11119. //DEBUG_INFO("chargingProfileId Found\n");
  11120. }
  11121. memset(word, 0, ARRAY_SIZE(word));
  11122. }
  11123. fclose(fptr1);
  11124. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11125. }
  11126. }
  11127. //Check TxProfile_%d.json
  11128. for(int j=1; j <= gunTotalNumber; j++)
  11129. {
  11130. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11131. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  11132. if((access(fnametemp,F_OK))!=-1)
  11133. {
  11134. i = 0;
  11135. fptr1 = fopen(fnametemp, "r");
  11136. //Check Charging Profile Count
  11137. while(fscanf(fptr1, "%s", word) != EOF)
  11138. {
  11139. //DEBUG_INFO("word=%s\n",word);
  11140. if(strstr(word, "chargingProfileId")!= NULL)
  11141. {
  11142. //DEBUG_INFO("test chargingProfileId \n");
  11143. n_chargingProfile = n_chargingProfile + 1;
  11144. i = i + 1;
  11145. //DEBUG_INFO("chargingProfileId Found\n");
  11146. }
  11147. memset(word, 0, ARRAY_SIZE(word));
  11148. }
  11149. fclose(fptr1);
  11150. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11151. }
  11152. }
  11153. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11154. {
  11155. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11156. goto end;
  11157. }
  11158. }
  11159. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11160. //**********************************Write to File********************************************************/
  11161. FILE *infile;
  11162. FILE *outfile;
  11163. infile = fopen (filename, "r");
  11164. outfile = fopen (tempfile, "w");
  11165. int d =0;
  11166. d = fgetc(infile);
  11167. rewind(infile);
  11168. if(d == EOF)
  11169. {
  11170. // Profile is empty
  11171. fprintf(outfile,"%s\n",payload);
  11172. fclose(infile);
  11173. fclose(outfile);
  11174. sprintf(rmFileCmd,"rm -f %s",filename);
  11175. system(rmFileCmd);
  11176. rename(tempfile, filename);
  11177. }
  11178. else
  11179. {
  11180. // Profile is not empty
  11181. char buf[2048]={0};
  11182. int ChargingProfileAdded = FALSE;
  11183. while (fgets(buf, sizeof(buf), infile) != NULL)
  11184. {
  11185. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  11186. json_object *tmpChargingProfile;
  11187. tmpChargingProfile = json_tokener_parse(buf);
  11188. if(!is_error(SetChargingProfile))
  11189. {
  11190. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  11191. {
  11192. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  11193. }
  11194. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11195. {
  11196. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11197. {
  11198. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11199. }
  11200. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11201. {
  11202. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  11203. }
  11204. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11205. {
  11206. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11207. }
  11208. }
  11209. }
  11210. json_object_put(tmpChargingProfile);
  11211. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  11212. {
  11213. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11214. {
  11215. //DEBUG_INFO("update set chargingProfile to file -0\n");
  11216. if(ChargingProfileAdded == FALSE)
  11217. {
  11218. fprintf(outfile,"%s\n",payload);
  11219. ChargingProfileAdded = TRUE;
  11220. }
  11221. }
  11222. else
  11223. {
  11224. if(tempstackLevelInt < stackLevelInt)
  11225. {
  11226. if(ChargingProfileAdded == FALSE)
  11227. {
  11228. fprintf(outfile,"%s\n",buf);
  11229. fprintf(outfile,"%s\n",payload);
  11230. ChargingProfileAdded = TRUE;
  11231. }
  11232. else
  11233. {
  11234. fprintf(outfile,"%s\n",buf);
  11235. }
  11236. }
  11237. else
  11238. {
  11239. if(ChargingProfileAdded == FALSE)
  11240. {
  11241. fprintf(outfile,"%s\n",buf);
  11242. fprintf(outfile,"%s\n",payload);
  11243. ChargingProfileAdded = TRUE;
  11244. }
  11245. else
  11246. {
  11247. fprintf(outfile,"%s\n",buf);
  11248. }
  11249. }
  11250. }
  11251. }
  11252. else
  11253. {
  11254. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11255. {
  11256. if(ChargingProfileAdded == FALSE)
  11257. {
  11258. fprintf(outfile,"%s\n",buf);
  11259. fprintf(outfile,"%s\n",payload);
  11260. ChargingProfileAdded = TRUE;
  11261. }
  11262. else
  11263. {
  11264. fprintf(outfile,"%s\n",buf);
  11265. }
  11266. }
  11267. else if(tempstackLevelInt < stackLevelInt)
  11268. {
  11269. if(ChargingProfileAdded == FALSE)
  11270. {
  11271. fprintf(outfile,"%s\n",buf);
  11272. fprintf(outfile,"%s\n",payload);
  11273. ChargingProfileAdded = TRUE;
  11274. }
  11275. else
  11276. {
  11277. fprintf(outfile,"%s\n",buf);
  11278. }
  11279. }
  11280. else
  11281. {
  11282. if(ChargingProfileAdded == FALSE)
  11283. {
  11284. fprintf(outfile,"%s\n",buf);
  11285. fprintf(outfile,"%s\n",payload);
  11286. ChargingProfileAdded = TRUE;
  11287. }
  11288. else
  11289. {
  11290. fprintf(outfile,"%s\n",buf);
  11291. }
  11292. }
  11293. }
  11294. } // end of while loop
  11295. fclose(infile);
  11296. fclose(outfile);
  11297. sprintf(rmFileCmd,"rm -f %s",filename);
  11298. system(rmFileCmd);
  11299. rename(tempfile, filename);
  11300. }
  11301. sleep(1);
  11302. result = TRUE;
  11303. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11304. end:
  11305. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11306. {
  11307. if(connectorIdInt == 0)
  11308. {
  11309. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11310. {
  11311. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11312. }
  11313. }
  11314. else
  11315. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11316. }
  11317. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11318. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11319. return result;
  11320. }
  11321. int handleTriggerMessageRequest(char *uuid, char *payload)
  11322. {
  11323. mtrace();
  11324. int result = FAIL;
  11325. int connectorIdIsNULL = FALSE;
  11326. int connectorIdInt =0;
  11327. char sstr[40]={0},sstrtemp[100]={ 0 };
  11328. char requestedMessagestr[40]={0};
  11329. char comfirmstr[20]={0};
  11330. int c = 0;
  11331. char *loc;
  11332. DEBUG_INFO("handleTriggerMessageRequest\n");
  11333. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11334. strcpy(sstrtemp, stringtrimspace(payload));
  11335. c = 0;
  11336. loc = strstr(sstrtemp, "requestedMessage");
  11337. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11338. {
  11339. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11340. c++;
  11341. }
  11342. sstr[c] = '\0';
  11343. strcpy(requestedMessagestr, sstr);
  11344. c = 0;
  11345. loc = strstr(sstrtemp, "connectorId");
  11346. if(loc == NULL)
  11347. {
  11348. connectorIdIsNULL = TRUE;
  11349. }
  11350. else
  11351. {
  11352. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11353. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11354. {
  11355. sstr[c] = loc[strlen("connectorId")+2+c];
  11356. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11357. c++;
  11358. }
  11359. sstr[c] = '\0';
  11360. connectorIdInt = atoi(sstr);
  11361. }
  11362. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11363. {
  11364. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11365. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11366. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11367. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11368. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11369. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11370. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11371. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11372. {
  11373. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11374. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11375. return TRUE;
  11376. }
  11377. else
  11378. {
  11379. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11380. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11381. }
  11382. }
  11383. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11384. {
  11385. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11386. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11387. return TRUE;
  11388. }
  11389. //==========================
  11390. // Trigger message
  11391. //==========================
  11392. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11393. {
  11394. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11395. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11396. {
  11397. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11398. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11399. }
  11400. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11401. }
  11402. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11403. {
  11404. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11405. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11406. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11407. }
  11408. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11409. {
  11410. //sendBootNotificationRequest();
  11411. server_sign = FALSE;
  11412. }
  11413. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11414. {
  11415. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11416. }
  11417. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11418. {
  11419. if(connectorIdIsNULL == FALSE)
  11420. {
  11421. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11422. {
  11423. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11424. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11425. }
  11426. }
  11427. else
  11428. {
  11429. for(int idx=0;idx< gunTotalNumber;idx++)
  11430. {
  11431. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11432. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11433. }
  11434. }
  11435. }
  11436. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11437. {
  11438. if(connectorIdIsNULL == FALSE)
  11439. {
  11440. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11441. {
  11442. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11443. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11444. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11445. }
  11446. }
  11447. else
  11448. {
  11449. for(int idx=0;idx< gunTotalNumber;idx++)
  11450. {
  11451. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11452. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11453. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11454. }
  11455. }
  11456. }
  11457. return result;
  11458. }
  11459. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11460. {
  11461. mtrace();
  11462. int result = FAIL;
  11463. int connectorIdInt =0;
  11464. char comfirmstr[20]={0};
  11465. int tempIndex = 0;
  11466. json_object *UnlockConnector;
  11467. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11468. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11469. UnlockConnector = json_tokener_parse(payload);
  11470. if(!is_error(UnlockConnector))
  11471. {
  11472. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11473. {
  11474. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11475. }
  11476. }
  11477. json_object_put(UnlockConnector);
  11478. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11479. if(gunTotalNumber == 0)
  11480. {
  11481. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11482. goto end;
  11483. }
  11484. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11485. {
  11486. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11487. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11488. goto end;
  11489. }
  11490. else
  11491. {
  11492. //check Transaction active
  11493. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11494. {
  11495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11496. {
  11497. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11498. }
  11499. else
  11500. {
  11501. tempIndex = connectorIdInt -1;
  11502. }
  11503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11504. {
  11505. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11506. {
  11507. //stop Transaction
  11508. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11509. }
  11510. }
  11511. }
  11512. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11513. {
  11514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11515. {
  11516. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11517. }
  11518. else
  11519. {
  11520. tempIndex = connectorIdInt -1;
  11521. }
  11522. for (int index = 0; index < CCS_QUANTITY; index++)
  11523. {
  11524. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11525. {
  11526. //stop Transaction
  11527. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11528. }
  11529. }
  11530. }
  11531. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11532. {
  11533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11534. {
  11535. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11536. }
  11537. else
  11538. {
  11539. tempIndex = connectorIdInt -1;
  11540. }
  11541. for (int index = 0; index < GB_QUANTITY; index++)
  11542. {
  11543. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11544. {
  11545. //stop Transaction
  11546. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11547. }
  11548. }
  11549. }
  11550. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11551. {
  11552. tempIndex = connectorIdInt -1;
  11553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11554. {
  11555. 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)))
  11556. {
  11557. //stop Transaction
  11558. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11559. }
  11560. }
  11561. }
  11562. else
  11563. {
  11564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11565. {
  11566. tempIndex = 2;
  11567. }
  11568. else
  11569. {
  11570. tempIndex = connectorIdInt-1;
  11571. }
  11572. for (int index = 0; index < AC_QUANTITY; index++)
  11573. {
  11574. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11575. {
  11576. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11577. }
  11578. }
  11579. }
  11580. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11581. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11582. result = TRUE;
  11583. return result;
  11584. }
  11585. end:
  11586. //json_object_put(obj); --- remove temporally
  11587. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11588. return result;
  11589. }
  11590. static char UpdateFirmwarepayloadData[300]={0};
  11591. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11592. {
  11593. mtrace();
  11594. int result = FAIL;
  11595. pthread_t t;
  11596. sendUpdateFirmwareConfirmation(uuid);
  11597. memset(UpdateFirmwarepayloadData, 0, 300);
  11598. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11599. if(!interLock.isUpdateFirmwareGoing)
  11600. {
  11601. interLock.isUpdateFirmwareGoing = 1;
  11602. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11603. sleep(1);
  11604. }
  11605. else
  11606. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11607. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11608. return result;
  11609. }
  11610. void *UpdateFirmwareProcess(void *data)
  11611. {
  11612. pthread_detach(pthread_self());
  11613. mtrace();
  11614. int retriesInt =0, retryIntervalInt=0;
  11615. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11616. int port=0;
  11617. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11618. int isSuccess = 0;
  11619. char ftpbuf[1024];
  11620. char temp[1024];
  11621. char * pch;
  11622. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11623. json_object *UpdateFirmware;
  11624. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11625. if(!is_error(UpdateFirmware))
  11626. {
  11627. // Required data
  11628. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11629. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11630. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11631. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11632. // Optional data
  11633. if(json_object_object_get(UpdateFirmware, "retries"))
  11634. {
  11635. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11636. }
  11637. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11638. {
  11639. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11640. }
  11641. }
  11642. json_object_put(UpdateFirmware);
  11643. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11644. memset(path, 0, ARRAY_SIZE(path));
  11645. // Wait retrieveData
  11646. if(strlen(retrieveDatestr) > 10)
  11647. {
  11648. do
  11649. {
  11650. sleep(1);
  11651. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11652. }
  11653. // Ready to download
  11654. system("rm -f /mnt/*");
  11655. if(strncmp(locationstr,"http", 4) == 0)
  11656. {
  11657. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11658. sprintf(ftppath,"/%s", path);
  11659. DEBUG_INFO("locationstr: %s\n", locationstr);
  11660. DEBUG_INFO("protocol: %s\n",protocol);
  11661. DEBUG_INFO("host: %s\n",host);
  11662. DEBUG_INFO("path: %s\n",path);
  11663. DEBUG_INFO("ftppath: %s\n",ftppath);
  11664. int ftppathlen=strlen(ftppath);
  11665. int i=1;
  11666. char filenametemp[50];
  11667. while(i < ftppathlen)
  11668. {
  11669. int len=ftppathlen-i;
  11670. if(ftppath[len]== 47) // '/' ascll code: 47
  11671. {
  11672. DEBUG_INFO("compare '/' all right\n");
  11673. break;
  11674. }
  11675. i=i+1;
  11676. }
  11677. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11678. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11679. filenametemp[i+1] = 0;
  11680. do
  11681. {
  11682. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11683. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11684. sleep(1);
  11685. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11686. if(!isSuccess)
  11687. {
  11688. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11689. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11690. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11691. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11692. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11693. }
  11694. else
  11695. {
  11696. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11697. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11698. }
  11699. retriesInt--;
  11700. }while((isSuccess == 0)&&(retriesInt >= 0));
  11701. }
  11702. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11703. {
  11704. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11705. memset(temp, 0, ARRAY_SIZE(temp));
  11706. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11707. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11708. int ftppathlen=strlen(ftpbuf);
  11709. int i=1;
  11710. char filenametemp[50];
  11711. while(i < ftppathlen)
  11712. {
  11713. int len=ftppathlen-i;
  11714. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11715. {
  11716. DEBUG_INFO(" compare '/' all right\n");
  11717. break;
  11718. }
  11719. i=i+1;
  11720. }
  11721. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11722. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11723. filenametemp[i+1] = 0;
  11724. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11725. pch=strchr(temp,'@');
  11726. if(pch==NULL)
  11727. {
  11728. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11729. protocol, host, &port, path);
  11730. strcpy(user,"anonymous");
  11731. strcpy(password,"");
  11732. }
  11733. else
  11734. {
  11735. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11736. protocol, user, password, host, &port, path);
  11737. }
  11738. sscanf(host,"%[^/]%s",host1, path1);
  11739. sprintf(ftppath,"%s", path1);
  11740. //DEBUG_INFO("protocol =%s\n",protocol);
  11741. //DEBUG_INFO("user =%s\n",user);
  11742. //DEBUG_INFO("password =%s\n",password);
  11743. //DEBUG_INFO("host1 =%s\n",host1);
  11744. //DEBUG_INFO("port =%d\n",port);
  11745. //DEBUG_INFO("path1 =%s\n",path1);
  11746. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11747. //ftpFile(host, user, password, port, ftppath, fname);
  11748. //download firmware pthred
  11749. if(port == 0)
  11750. {
  11751. port = 21;
  11752. }
  11753. do
  11754. {
  11755. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11756. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11757. sleep(1);
  11758. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11759. if(!isSuccess)
  11760. {
  11761. //BulldogUtil.sleepMs(interval*1000);
  11762. DEBUG_INFO("Update firmware request and download file fail.\n");
  11763. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11764. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11765. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11766. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11767. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11768. }
  11769. else
  11770. {
  11771. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11772. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11773. }
  11774. retriesInt--;
  11775. }while((!isSuccess)&&(retriesInt >= 0));
  11776. }
  11777. else
  11778. {
  11779. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11780. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11781. sleep(1);
  11782. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11783. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11784. }
  11785. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11786. interLock.isUpdateFirmwareGoing = 0;
  11787. pthread_exit(NULL);
  11788. }
  11789. int handleCertificateSignedRequest(char *uuid, char *payload)
  11790. {
  11791. mtrace();
  11792. int result = PASS;
  11793. json_object *CertificateSigned;
  11794. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11795. CertificateSigned = json_tokener_parse(payload);
  11796. if(!is_error(CertificateSigned))
  11797. {
  11798. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11799. }
  11800. json_object_put(CertificateSigned);
  11801. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11802. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11803. fclose(fp);
  11804. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11805. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11806. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11807. sendCertificateSignedConfirmation(uuid);
  11808. return result;
  11809. }
  11810. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11811. {
  11812. mtrace();
  11813. int result = PASS;
  11814. json_object *DeleteCertificate;
  11815. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11816. DeleteCertificate = json_tokener_parse(payload);
  11817. if(!is_error(DeleteCertificate))
  11818. {
  11819. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11820. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11821. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11822. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11823. }
  11824. json_object_put(DeleteCertificate);
  11825. /*
  11826. * TODO: Delete certificateSigned process
  11827. */
  11828. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11829. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11830. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11831. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11832. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11833. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11834. sendDeleteCertificateConfirmation(uuid);
  11835. return result;
  11836. }
  11837. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11838. {
  11839. mtrace();
  11840. int result = PASS;
  11841. json_object *ExtendedTriggerMessage;
  11842. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11843. ExtendedTriggerMessage = json_tokener_parse(payload);
  11844. if(!is_error(ExtendedTriggerMessage))
  11845. {
  11846. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11847. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11848. {
  11849. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11850. }
  11851. else
  11852. {
  11853. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11854. }
  11855. }
  11856. json_object_put(ExtendedTriggerMessage);
  11857. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11858. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11859. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11860. {
  11861. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11862. }
  11863. else
  11864. {
  11865. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11866. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11867. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11868. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11869. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11870. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11871. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11872. {
  11873. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11874. }
  11875. else
  11876. {
  11877. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11878. }
  11879. }
  11880. sendExtendedTriggerMessageConfirmation(uuid);
  11881. //==========================
  11882. // Trigger message
  11883. //==========================
  11884. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11885. {
  11886. //sendBootNotificationRequest();
  11887. server_sign = FALSE;
  11888. }
  11889. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11890. {
  11891. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11892. }
  11893. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11894. {
  11895. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11896. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11897. {
  11898. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11899. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11900. }
  11901. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11902. }
  11903. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11904. {
  11905. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11906. }
  11907. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11908. {
  11909. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11910. {
  11911. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11912. }
  11913. else
  11914. {
  11915. for(int idx=0;idx< gunTotalNumber;idx++)
  11916. {
  11917. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11918. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11919. }
  11920. }
  11921. }
  11922. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11923. {
  11924. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11925. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11926. {
  11927. 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\" &");
  11928. }
  11929. }
  11930. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11931. {
  11932. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11933. {
  11934. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11935. }
  11936. else
  11937. {
  11938. for(int idx=0;idx< gunTotalNumber;idx++)
  11939. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11940. }
  11941. }
  11942. return result;
  11943. }
  11944. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11945. {
  11946. mtrace();
  11947. int result = PASS;
  11948. json_object *GetInstalledCertificateIds;
  11949. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11950. GetInstalledCertificateIds = json_tokener_parse(payload);
  11951. if(!is_error(GetInstalledCertificateIds))
  11952. {
  11953. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11954. }
  11955. json_object_put(GetInstalledCertificateIds);
  11956. /*
  11957. * TODO: Return installed certificate process
  11958. */
  11959. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11960. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11961. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11962. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11963. sendGetInstalledCertificateIdsConfirmation(uuid);
  11964. return result;
  11965. }
  11966. int handleGetLogRequest(char *uuid, char *payload)
  11967. {
  11968. mtrace();
  11969. int result = PASS;
  11970. json_object *GetLog;
  11971. DEBUG_INFO("handleGetLogRequest...\n");
  11972. GetLog = json_tokener_parse(payload);
  11973. if(!is_error(GetLog))
  11974. {
  11975. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11976. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11977. if(json_object_object_get(GetLog, "retries") != NULL)
  11978. {
  11979. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11980. }
  11981. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11982. {
  11983. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11984. }
  11985. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11986. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11987. {
  11988. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11989. }
  11990. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11991. {
  11992. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11993. }
  11994. }
  11995. json_object_put(GetLog);
  11996. /*
  11997. * TODO: Upload log process
  11998. */
  11999. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  12000. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  12001. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  12002. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  12003. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  12004. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  12005. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  12006. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  12007. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  12008. sendGetLogConfirmation(uuid);
  12009. return result;
  12010. }
  12011. int handleInstallCertificateRequest(char *uuid, char *payload)
  12012. {
  12013. mtrace();
  12014. int result = PASS;
  12015. json_object *InstallCertificate;
  12016. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12017. InstallCertificate = json_tokener_parse(payload);
  12018. if(!is_error(InstallCertificate))
  12019. {
  12020. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12021. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12022. /*
  12023. * TODO: Install certificate process
  12024. */
  12025. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12026. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12027. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12028. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12029. sendInstallCertificateConfirmation(uuid);
  12030. }
  12031. json_object_put(InstallCertificate);
  12032. return result;
  12033. }
  12034. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12035. {
  12036. mtrace();
  12037. int result = PASS;
  12038. json_object *SignedUpdateFirmware;
  12039. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12040. SignedUpdateFirmware = json_tokener_parse(payload);
  12041. if(!is_error(SignedUpdateFirmware))
  12042. {
  12043. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12044. {
  12045. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12046. }
  12047. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12048. {
  12049. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12050. }
  12051. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12052. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12053. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12054. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12055. {
  12056. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12057. }
  12058. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12059. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12060. }
  12061. json_object_put(SignedUpdateFirmware);
  12062. /*
  12063. * TODO: Upgrade firmware process
  12064. */
  12065. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12066. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12067. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12068. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12069. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12070. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12071. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12072. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12073. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12074. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12075. sendInstallCertificateConfirmation(uuid);
  12076. return result;
  12077. }
  12078. int handleUnknownRequest(char *uuid, char *payload)
  12079. {
  12080. mtrace();
  12081. int result = PASS;
  12082. DEBUG_INFO("handleUnknownRequest...\n");
  12083. sendUnknownConfirmation(uuid);
  12084. result = PASS;
  12085. return result;
  12086. }
  12087. //==========================================
  12088. // Handle server response routine
  12089. //==========================================
  12090. void handleAuthorizeResponse(char *payload, int gun_index)
  12091. {
  12092. mtrace();
  12093. char expiryDatestr[30]={0};
  12094. char parentIdTagstr[20]={0};
  12095. char statusstr[20]={0};
  12096. int expiryDateISNULL=FALSE;
  12097. int parentIdTagISNULL=FALSE;
  12098. DEBUG_INFO("handleAuthorizeResponse...\n");
  12099. json_object *Authorize;
  12100. Authorize = json_tokener_parse(payload);
  12101. if(!is_error(Authorize))
  12102. {
  12103. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12104. {
  12105. // Required data
  12106. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12107. // Optional data
  12108. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12109. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12110. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12111. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12112. }
  12113. }
  12114. json_object_put(Authorize);
  12115. if(expiryDateISNULL == FALSE)
  12116. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12117. if(parentIdTagISNULL == FALSE)
  12118. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12119. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12120. //Update idTag information to authorization cache if supproted
  12121. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12122. {
  12123. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12124. }
  12125. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12126. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12127. authorizeRetryTimes = 0;
  12128. }
  12129. void handleBootNotificationResponse(char *payload, int gun_index)
  12130. {
  12131. mtrace();
  12132. char statusStr[12]={0};
  12133. char currentTimeStr[30]={0};
  12134. int intervalInt = 0;
  12135. DEBUG_INFO("handleBootNotificationResponse...\n");
  12136. json_object *BootNotification;
  12137. BootNotification = json_tokener_parse(payload);
  12138. if(!is_error(BootNotification))
  12139. {
  12140. // Required data
  12141. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12142. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12143. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12144. }
  12145. json_object_put(BootNotification);
  12146. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12147. BootNotificationInterval = intervalInt;
  12148. HeartBeatWaitTime = intervalInt;
  12149. //write back to ShmOCPP16Data->BootNotification
  12150. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12151. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12152. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12153. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12154. {
  12155. server_sign = TRUE;
  12156. server_pending =FALSE;
  12157. }
  12158. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12159. {
  12160. server_pending = TRUE;
  12161. }
  12162. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12163. srand(time(NULL));
  12164. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12165. SetOcppConnStatus(TRUE);
  12166. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12167. }
  12168. void handleDataTransferResponse(char *payload, int gun_index)
  12169. {
  12170. char sstr[160]={0};//sstr[200]={ 0 };
  12171. int c = 0;
  12172. char *loc;
  12173. DEBUG_INFO("handleDataTransferResponse ...\n");
  12174. loc = strstr(payload, "status");
  12175. c = 0;
  12176. while (loc[3+strlen("status")+c] != '\"')
  12177. {
  12178. sstr[c] = loc[3+strlen("status")+c];
  12179. c++;
  12180. }
  12181. sstr[c] = '\0';
  12182. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12183. }
  12184. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12185. {
  12186. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12187. //struct json_object *obj;
  12188. // obj = json_tokener_parse(payload);
  12189. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12190. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12191. //No fields are defined.
  12192. }
  12193. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12194. {
  12195. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12196. //struct json_object *obj;
  12197. // obj = json_tokener_parse(payload);
  12198. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12199. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12200. //No fields are defined.
  12201. }
  12202. void handleHeartbeatResponse(char *payload, int gun_index)
  12203. {
  12204. mtrace();
  12205. DEBUG_INFO("handleHeartbeatResponse...\n");
  12206. json_object *Heartbeat;
  12207. Heartbeat = json_tokener_parse(payload);
  12208. if(!is_error(Heartbeat))
  12209. {
  12210. // Required data
  12211. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12212. }
  12213. json_object_put(Heartbeat);
  12214. if(FirstHeartBeat == 0)
  12215. {
  12216. FirstHeartBeat = 1;
  12217. DEBUG_INFO("FirstHeartBeat \n");
  12218. }
  12219. HeartBeatWithNOResponse = 0;
  12220. clientTime.Heartbeat=time((time_t*)NULL);
  12221. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12222. }
  12223. void handleMeterValuesResponse(char *payload, int gun_index)
  12224. {
  12225. mtrace();
  12226. DEBUG_INFO("handleMeterValuesResponse...\n");
  12227. }
  12228. void handleStartTransactionResponse(char *payload, int gun_index)
  12229. {
  12230. mtrace();
  12231. //int transactionIdInt = 0;
  12232. FILE *outfile;
  12233. char data[100]={0};
  12234. DEBUG_INFO("handleStartTransactionResponse...\n");
  12235. json_object *StartTransaction;
  12236. StartTransaction = json_tokener_parse(payload);
  12237. if(!is_error(StartTransaction))
  12238. {
  12239. // Required data
  12240. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12241. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12242. // Optional data
  12243. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12244. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12245. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12246. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12247. }
  12248. json_object_put(StartTransaction);
  12249. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12250. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12251. //-----------Start : write to the Queue TransactionId file -----------------//
  12252. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12253. {}
  12254. else
  12255. {
  12256. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12257. if(log == NULL)
  12258. {
  12259. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12260. return ;
  12261. }
  12262. else
  12263. {
  12264. fclose(log);
  12265. }
  12266. }
  12267. // open file for writing
  12268. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12269. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12270. {
  12271. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12272. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12273. fputs(data, outfile);
  12274. fclose (outfile);
  12275. }
  12276. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12277. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12278. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12279. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12280. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12281. }
  12282. void handleStatusNotificationResponse(char *payload, int gun_index)
  12283. {
  12284. mtrace();
  12285. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12286. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12287. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12288. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12289. }
  12290. void handleStopTransactionnResponse(char *payload, int gun_index)
  12291. {
  12292. mtrace();
  12293. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12294. json_object *StopTransaction;
  12295. StopTransaction = json_tokener_parse(payload);
  12296. if(!is_error(StopTransaction))
  12297. {
  12298. // Optional data
  12299. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12300. {
  12301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12302. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12303. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12304. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12305. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12306. }
  12307. }
  12308. json_object_put(StopTransaction);
  12309. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12310. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12311. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12312. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12313. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12314. }
  12315. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12316. {
  12317. mtrace();
  12318. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12319. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12320. }
  12321. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12322. {
  12323. mtrace();
  12324. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12325. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12326. }
  12327. void handleSignCertificateResponse(char *payload, int gun_index)
  12328. {
  12329. mtrace();
  12330. DEBUG_INFO("handleSignCertificateResponse...\n");
  12331. json_object *SignCertificate;
  12332. SignCertificate = json_tokener_parse(payload);
  12333. if(!is_error(SignCertificate))
  12334. {
  12335. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12336. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12337. }
  12338. json_object_put(SignCertificate);
  12339. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12340. }
  12341. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12342. {
  12343. mtrace();
  12344. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12345. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12346. }
  12347. //==========================================
  12348. // Handle Error routine
  12349. //==========================================
  12350. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12351. {
  12352. mtrace();
  12353. #ifdef SystemLogMessage
  12354. DEBUG_INFO("errorCode: %s\n", errorCode);
  12355. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12356. DEBUG_INFO("errorDetails: %s\n", payload);
  12357. #endif
  12358. }
  12359. //===============================================
  12360. // Common routine
  12361. //===============================================
  12362. int initialConfigurationTable(void)
  12363. {
  12364. //clock_t start_t, end_t, total_t;
  12365. FILE *fp;
  12366. FILE *outfile;
  12367. char str[512]={0};
  12368. char sstr[256]={0};
  12369. int c = 0;
  12370. char *loc;
  12371. int confVersion = 8;
  12372. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12373. //start_t = clock();
  12374. //printf("Starting of the program, start_t = %ld\n", start_t);
  12375. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12376. // Check configuration file size is correct
  12377. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12378. {
  12379. struct stat st;
  12380. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12381. if(st.st_size < 3100)
  12382. {
  12383. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12384. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12385. }
  12386. }
  12387. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12388. {
  12389. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12390. if(outfile == NULL)
  12391. {
  12392. DEBUG_INFO("Error opening file\n");
  12393. return FALSE;
  12394. }
  12395. /*Core Profile*/
  12396. //AllowOfflineTxForUnknownId
  12397. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12401. //AuthorizationCacheEnabled
  12402. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12403. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12405. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12406. //AuthorizeRemoteTxRequests
  12407. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12411. //BlinkRepeat
  12412. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12415. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12416. //ClockAlignedDataInterval
  12417. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12421. //ConnectionTimeOut
  12422. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12426. //GetConfigurationMaxKeys
  12427. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12431. // HeartbeatInterval
  12432. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12435. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12436. // LightIntensity
  12437. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12441. // LocalAuthorizeOffline
  12442. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12446. // LocalPreAuthorize
  12447. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12451. // MaxEnergyOnInvalidId
  12452. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12456. // MeterValuesAlignedData
  12457. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12460. 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" );
  12461. else
  12462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12464. // MeterValuesAlignedDataMaxLength
  12465. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12466. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12469. else
  12470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12472. // MeterValuesSampledData
  12473. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12474. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12476. 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" );
  12477. else
  12478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12480. // MeterValuesSampledDataMaxLength
  12481. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12485. else
  12486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12488. // MeterValueSampleInterval
  12489. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12493. // MinimumStatusDuration
  12494. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12495. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12497. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12499. // NumberOfConnectors
  12500. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12502. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12503. {
  12504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12505. }
  12506. else
  12507. {
  12508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12509. }
  12510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12511. // ResetRetries
  12512. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12516. // ConnectorPhaseRotation
  12517. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12521. // ConnectorPhaseRotationMaxLength
  12522. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12525. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12526. // StopTransactionOnEVSideDisconnect
  12527. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12531. // StopTransactionOnInvalidId
  12532. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12536. // StopTxnAlignedData
  12537. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12541. // StopTxnAlignedDataMaxLength
  12542. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12546. // StopTxnSampledData
  12547. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12551. else
  12552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12553. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12554. // StopTxnSampledDataMaxLength
  12555. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12557. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12558. {
  12559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12560. }
  12561. else
  12562. {
  12563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12564. }
  12565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12566. // SupportedFeatureProfiles
  12567. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12571. // SupportedFeatureProfilesMaxLength
  12572. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12576. // TransactionMessageAttempts
  12577. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12580. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12581. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12582. // TransactionMessageRetryInterval
  12583. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12586. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12588. // UnlockConnectorOnEVSideDisconnect
  12589. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12592. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12593. // WebSocketPingInterval
  12594. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12598. // QueueOffLineMeterValues
  12599. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12603. // AuthorizationKey
  12604. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12608. // SecurityProfile
  12609. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12613. // DefaultPrice
  12614. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12617. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12618. // CustomDisplayCostAndPrice
  12619. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12623. // CustomIdleFeeAfterStop
  12624. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12627. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12628. // TimeOffset
  12629. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12633. // NextTimeOffsetTransitionDateTime
  12634. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12638. // TimeOffsetNextTransition
  12639. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12643. // Configuration Version
  12644. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12648. //* Local Auth List Management Profile*/
  12649. #if 0
  12650. //For OCTT Test Case
  12651. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12654. #endif
  12655. #if 1
  12656. //LocalAuthListEnabled
  12657. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12661. #endif
  12662. //LocalAuthListMaxLength
  12663. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12666. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12667. //SendLocalListMaxLength
  12668. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12671. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12672. //ReserveConnectorZeroSupported
  12673. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12677. //* Smart Charging Profile */
  12678. //ChargeProfileMaxStackLevel
  12679. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12683. // ChargingScheduleAllowedChargingRateUnit
  12684. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12688. // ChargingScheduleMaxPeriods
  12689. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12693. // ConnectorSwitch3to1PhaseSupported
  12694. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12698. // MaxChargingProfilesInstalled
  12699. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12703. fclose(outfile);
  12704. }
  12705. else
  12706. {
  12707. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12708. char keystr[60]={0};
  12709. char readonlystr[10]={0};
  12710. char valuestr[256]={0};
  12711. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12712. if(fp == NULL) {
  12713. DEBUG_INFO("Error opening file");
  12714. return FALSE;
  12715. }
  12716. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12717. {
  12718. //DEBUG_INFO("Get Configuration \n");
  12719. if(strlen(str) > 0)
  12720. {
  12721. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12722. //*************************key*********************************/
  12723. if(strstr(str, "key") != NULL)
  12724. {
  12725. loc = strstr(str, "key");
  12726. c = 0;
  12727. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12728. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12729. {
  12730. sstr[c] = loc[strlen("key")+3+c];
  12731. c++;
  12732. }
  12733. sstr[c] = '\0';
  12734. strcpy(keystr,sstr);
  12735. }
  12736. //*************************readonly*********************************/
  12737. if(strstr(str, "readonly") != NULL)
  12738. {
  12739. loc = strstr(str, "readonly");
  12740. c = 0;
  12741. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12742. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12743. {
  12744. sstr[c] = loc[strlen("readonly")+2+c];
  12745. c++;
  12746. }
  12747. sstr[c] = '\0';
  12748. strcpy(readonlystr,sstr);
  12749. }
  12750. //*************************value*********************************/
  12751. if(strstr(str, "value") != NULL)
  12752. {
  12753. loc = strstr(str, "value");
  12754. c = 0;
  12755. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12756. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12757. {
  12758. sstr[c] = loc[strlen("value")+3+c];
  12759. c++;
  12760. }
  12761. sstr[c] = '\0';
  12762. strcpy(valuestr,sstr);
  12763. }
  12764. // DEBUG_INFO("keystr=%s\n",keystr);
  12765. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12766. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12767. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12768. {
  12769. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12770. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12772. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12773. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12774. }
  12775. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12776. {
  12777. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12778. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12780. }
  12781. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12782. {
  12783. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12785. }
  12786. if(strcmp(keystr, "BlinkRepeat") == 0)
  12787. {
  12788. //Charger.BlinkRepeat = Integer.parseInt(value);
  12789. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12790. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12791. }
  12792. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12793. {
  12794. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12796. }
  12797. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12798. {
  12799. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12800. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12801. }
  12802. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12803. {
  12804. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12806. }
  12807. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12808. {
  12809. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12810. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12811. HeartBeatWaitTime = atoi(valuestr);
  12812. }
  12813. if(strcmp(keystr, "LightIntensity") == 0)
  12814. {
  12815. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12816. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12817. }
  12818. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12819. {
  12820. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12822. }
  12823. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12824. {
  12825. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12827. }
  12828. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12829. {
  12830. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12832. }
  12833. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12834. {
  12835. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12837. }
  12838. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12839. {
  12840. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12842. }
  12843. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12844. {
  12845. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12847. }
  12848. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12849. {
  12850. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12852. }
  12853. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12854. {
  12855. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12857. }
  12858. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12859. {
  12860. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12862. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12863. }
  12864. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12865. {
  12866. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12867. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12868. }
  12869. if(strcmp(keystr, "ResetRetries") == 0)
  12870. {
  12871. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12872. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12873. }
  12874. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12875. {
  12876. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12878. }
  12879. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12880. {
  12881. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12883. }
  12884. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12885. {
  12886. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12888. }
  12889. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12890. {
  12891. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12893. }
  12894. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12895. {
  12896. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12898. }
  12899. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12900. {
  12901. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12903. }
  12904. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12905. {
  12906. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12908. }
  12909. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12910. {
  12911. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12913. }
  12914. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12915. {
  12916. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12918. }
  12919. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12920. {
  12921. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12923. }
  12924. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12925. {
  12926. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12928. TransactionMessageAttemptsValue = atoi(valuestr);
  12929. }
  12930. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12931. {
  12932. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12934. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12935. }
  12936. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12937. {
  12938. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12940. }
  12941. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12942. {
  12943. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12945. }
  12946. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12947. {
  12948. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12950. }
  12951. if(strcmp(keystr, "AuthorizationKey") == 0)
  12952. {
  12953. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12954. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12956. }
  12957. if(strcmp(keystr, "SecurityProfile") == 0)
  12958. {
  12959. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12961. }
  12962. if(strcmp(keystr, "DefaultPrice") == 0)
  12963. {
  12964. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12966. }
  12967. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12968. {
  12969. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12971. }
  12972. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12973. {
  12974. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12976. }
  12977. if(strcmp(keystr, "TimeOffset") == 0)
  12978. {
  12979. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12981. }
  12982. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12983. {
  12984. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12986. }
  12987. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12988. {
  12989. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12991. }
  12992. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12993. {
  12994. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12996. }
  12997. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12998. {
  12999. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13001. }
  13002. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13003. {
  13004. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13006. }
  13007. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13008. {
  13009. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13011. }
  13012. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13013. {
  13014. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13016. }
  13017. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13018. {
  13019. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13021. }
  13022. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13023. {
  13024. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13026. }
  13027. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13028. {
  13029. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13031. }
  13032. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13033. {
  13034. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13036. }
  13037. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13038. {
  13039. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13041. }
  13042. }
  13043. }
  13044. fclose(fp);
  13045. }
  13046. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13047. {
  13048. return PASS;
  13049. }
  13050. else
  13051. {
  13052. return FAIL;
  13053. }
  13054. }
  13055. void StoreConfigurationTable(void)
  13056. {
  13057. FILE *outfile;
  13058. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13059. if(outfile == NULL)
  13060. {
  13061. DEBUG_INFO("Error opening file");
  13062. return ;
  13063. }
  13064. /*Core Profile*/
  13065. //AllowOfflineTxForUnknownId
  13066. /*
  13067. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13068. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13071. */
  13072. //DEBUG_INFO("data=%s\n",data);
  13073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13074. //AuthorizationCacheEnabled
  13075. /*
  13076. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13079. */
  13080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13081. //AuthorizeRemoteTxRequests
  13082. /*
  13083. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13086. */
  13087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13088. //BlinkRepeat
  13089. /*
  13090. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13093. */
  13094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13095. //ClockAlignedDataInterval
  13096. /*
  13097. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13100. */
  13101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13102. //ConnectionTimeOut
  13103. /*
  13104. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13107. */
  13108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13109. //GetConfigurationMaxKeys
  13110. /*
  13111. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13114. */
  13115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13116. // HeartbeatInterval
  13117. /*
  13118. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13121. */
  13122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13123. // LightIntensity
  13124. /*
  13125. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13128. */
  13129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13130. // LocalAuthorizeOffline
  13131. /*
  13132. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13135. */
  13136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13137. // LocalPreAuthorize
  13138. /*
  13139. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13142. */
  13143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13144. // MaxEnergyOnInvalidId
  13145. /*
  13146. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13149. */
  13150. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13151. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13152. // MeterValuesAlignedData
  13153. /*
  13154. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13157. */
  13158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13159. // MeterValuesAlignedDataMaxLength
  13160. /*
  13161. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13164. */
  13165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13166. // MeterValuesSampledData
  13167. /*
  13168. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13171. */
  13172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13173. // MeterValuesSampledDataMaxLength
  13174. /*
  13175. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13178. */
  13179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13180. // MeterValueSampleInterval
  13181. /*
  13182. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13185. */
  13186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13187. // MinimumStatusDuration
  13188. /*
  13189. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13192. */
  13193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13194. // NumberOfConnectors
  13195. /*
  13196. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13198. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13199. {
  13200. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13201. }
  13202. else
  13203. {
  13204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13205. }
  13206. */
  13207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13208. // ResetRetries
  13209. /*
  13210. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13213. */
  13214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13215. // ConnectorPhaseRotation
  13216. /*
  13217. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13220. */
  13221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13222. // ConnectorPhaseRotationMaxLength
  13223. /*
  13224. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13227. */
  13228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13229. // StopTransactionOnEVSideDisconnect
  13230. /*
  13231. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13234. */
  13235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13236. // StopTransactionOnInvalidId
  13237. /*
  13238. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13241. */
  13242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13243. // StopTxnAlignedData
  13244. /*
  13245. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13248. */
  13249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13250. // StopTxnAlignedDataMaxLength
  13251. /*
  13252. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13255. */
  13256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13257. // StopTxnSampledData
  13258. /*
  13259. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13262. */
  13263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13264. // StopTxnSampledDataMaxLength
  13265. /*
  13266. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13269. */
  13270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13271. // SupportedFeatureProfiles
  13272. /*
  13273. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13276. */
  13277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13278. // SupportedFeatureProfilesMaxLength
  13279. /*
  13280. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13283. */
  13284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13285. // TransactionMessageAttempts
  13286. /*
  13287. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13290. */
  13291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13292. // TransactionMessageRetryInterval
  13293. /*
  13294. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13297. */
  13298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13299. // UnlockConnectorOnEVSideDisconnect
  13300. /*
  13301. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13304. */
  13305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13306. // WebSocketPingInterval
  13307. /*
  13308. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13311. */
  13312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13313. // QueueOffLineMeterValues
  13314. /*
  13315. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  13316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  13318. */
  13319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13320. // AuthorizationKey
  13321. /*
  13322. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13325. */
  13326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13327. // SecurityProfile
  13328. /*
  13329. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13332. */
  13333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13334. // DefaultPrice
  13335. /*
  13336. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13339. */
  13340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13341. // CustomDisplayCostAndPrice
  13342. /*
  13343. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13346. */
  13347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13348. // CustomIdleFeeAfterStop
  13349. /*
  13350. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13353. */
  13354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13355. // TimeOffset
  13356. /*
  13357. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13360. */
  13361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13362. // NextTimeOffsetTransitionDateTime
  13363. /*
  13364. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13367. */
  13368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13369. // TimeOffsetNextTransition
  13370. /*
  13371. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13374. */
  13375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13376. // ConfigurationVersion
  13377. /*
  13378. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13381. */
  13382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13383. //* Local Auth List Management Profile*/
  13384. //LocalAuthListEnabled
  13385. /*
  13386. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13388. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13389. */
  13390. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13391. //LocalAuthListMaxLength
  13392. /*
  13393. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13396. */
  13397. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13398. //SendLocalListMaxLength
  13399. /*
  13400. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13403. */
  13404. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13405. //ReserveConnectorZeroSupported
  13406. /*
  13407. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13409. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13410. */
  13411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13412. //* Smart Charging Profile */
  13413. //ChargeProfileMaxStackLevel
  13414. /*
  13415. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13418. */
  13419. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13420. // ChargingScheduleAllowedChargingRateUnit
  13421. /*
  13422. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13425. */
  13426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13427. // ChargingScheduleMaxPeriods
  13428. /*
  13429. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13430. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13432. */
  13433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13434. // ConnectorSwitch3to1PhaseSupported
  13435. /*
  13436. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13438. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13439. */
  13440. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13441. // MaxChargingProfilesInstalled
  13442. /*
  13443. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13446. */
  13447. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13448. fclose(outfile);
  13449. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13450. }
  13451. void getKeyValue(char *keyReq)
  13452. {
  13453. int isEmpty = FALSE;
  13454. int isKnowKey = FALSE;
  13455. DEBUG_INFO("keyReq = %s\n", keyReq);
  13456. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13457. isEmpty = TRUE;
  13458. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13459. {
  13460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13463. {
  13464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13465. }
  13466. else
  13467. {
  13468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13469. }
  13470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13471. isKnowKey = TRUE;
  13472. }
  13473. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13474. {
  13475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13477. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13478. {
  13479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13480. }
  13481. else
  13482. {
  13483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13484. }
  13485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13486. isKnowKey = TRUE;
  13487. }
  13488. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13489. {
  13490. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13492. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13493. {
  13494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13495. }
  13496. else
  13497. {
  13498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13499. }
  13500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13501. isKnowKey = TRUE;
  13502. }
  13503. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13504. {
  13505. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13507. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13508. {
  13509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13510. }
  13511. else
  13512. {
  13513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13514. }
  13515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13516. isKnowKey = TRUE;
  13517. }
  13518. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13519. {
  13520. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13523. {
  13524. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13525. }
  13526. else
  13527. {
  13528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13529. }
  13530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13531. isKnowKey = TRUE;
  13532. }
  13533. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13534. {
  13535. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13538. {
  13539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13540. }
  13541. else
  13542. {
  13543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13544. }
  13545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13546. isKnowKey = TRUE;
  13547. }
  13548. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13549. {
  13550. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13552. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13553. {
  13554. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13555. }
  13556. else
  13557. {
  13558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13559. }
  13560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13561. isKnowKey = TRUE;
  13562. }
  13563. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13564. {
  13565. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13567. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13568. {
  13569. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13570. }
  13571. else
  13572. {
  13573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13574. }
  13575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13576. isKnowKey = TRUE;
  13577. }
  13578. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13579. {
  13580. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13582. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13583. {
  13584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13585. }
  13586. else
  13587. {
  13588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13589. }
  13590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13591. isKnowKey = TRUE;
  13592. }
  13593. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13594. {
  13595. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13598. {
  13599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13600. }
  13601. else
  13602. {
  13603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13604. }
  13605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13606. isKnowKey = TRUE;
  13607. }
  13608. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13609. {
  13610. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13612. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13613. {
  13614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13615. }
  13616. else
  13617. {
  13618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13619. }
  13620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13621. isKnowKey = TRUE;
  13622. }
  13623. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13624. {
  13625. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13627. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13628. {
  13629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13630. }
  13631. else
  13632. {
  13633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13634. }
  13635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13636. isKnowKey = TRUE;
  13637. }
  13638. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13639. {
  13640. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13642. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13643. {
  13644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13645. }
  13646. else
  13647. {
  13648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13649. }
  13650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13651. isKnowKey = TRUE;
  13652. }
  13653. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13654. {
  13655. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13657. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13658. {
  13659. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13660. }
  13661. else
  13662. {
  13663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13664. }
  13665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13666. isKnowKey = TRUE;
  13667. }
  13668. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13669. {
  13670. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13672. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13673. {
  13674. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13675. }
  13676. else
  13677. {
  13678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13679. }
  13680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13681. isKnowKey = TRUE;
  13682. }
  13683. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13684. {
  13685. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13688. {
  13689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13690. }
  13691. else
  13692. {
  13693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13694. }
  13695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13696. isKnowKey = TRUE;
  13697. }
  13698. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13699. {
  13700. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13703. {
  13704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13705. }
  13706. else
  13707. {
  13708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13709. }
  13710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13711. isKnowKey = TRUE;
  13712. }
  13713. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13714. {
  13715. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13717. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13718. {
  13719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13720. }
  13721. else
  13722. {
  13723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13724. }
  13725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13726. isKnowKey = TRUE;
  13727. }
  13728. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13729. {
  13730. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13732. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13733. {
  13734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13735. }
  13736. else
  13737. {
  13738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13739. }
  13740. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13741. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13742. isKnowKey = TRUE;
  13743. }
  13744. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13745. {
  13746. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13749. {
  13750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13751. }
  13752. else
  13753. {
  13754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13755. }
  13756. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13757. isKnowKey = TRUE;
  13758. }
  13759. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13760. {
  13761. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13763. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13764. {
  13765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13766. }
  13767. else
  13768. {
  13769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13770. }
  13771. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13772. isKnowKey = TRUE;
  13773. }
  13774. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13775. {
  13776. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13779. {
  13780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13781. }
  13782. else
  13783. {
  13784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13785. }
  13786. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13787. isKnowKey = TRUE;
  13788. }
  13789. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13790. {
  13791. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13794. {
  13795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13796. }
  13797. else
  13798. {
  13799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13800. }
  13801. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13802. isKnowKey = TRUE;
  13803. }
  13804. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13805. {
  13806. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13809. {
  13810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13811. }
  13812. else
  13813. {
  13814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13815. }
  13816. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13817. isKnowKey = TRUE;
  13818. }
  13819. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13820. {
  13821. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13824. {
  13825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13826. }
  13827. else
  13828. {
  13829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13830. }
  13831. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13832. isKnowKey = TRUE;
  13833. }
  13834. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13835. {
  13836. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13839. {
  13840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13841. }
  13842. else
  13843. {
  13844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13845. }
  13846. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13847. isKnowKey = TRUE;
  13848. }
  13849. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13850. {
  13851. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13853. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13854. {
  13855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13856. }
  13857. else
  13858. {
  13859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13860. }
  13861. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13862. isKnowKey = TRUE;
  13863. }
  13864. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13865. {
  13866. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13869. {
  13870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13871. }
  13872. else
  13873. {
  13874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13875. }
  13876. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13877. isKnowKey = TRUE;
  13878. }
  13879. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13880. {
  13881. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13883. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13884. {
  13885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13886. }
  13887. else
  13888. {
  13889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13890. }
  13891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13892. isKnowKey = TRUE;
  13893. }
  13894. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13895. {
  13896. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13899. {
  13900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13901. }
  13902. else
  13903. {
  13904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13905. }
  13906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13907. isKnowKey = TRUE;
  13908. }
  13909. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13910. {
  13911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13913. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13914. {
  13915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13916. }
  13917. else
  13918. {
  13919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13920. }
  13921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13922. isKnowKey = TRUE;
  13923. }
  13924. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13925. {
  13926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13929. {
  13930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13931. }
  13932. else
  13933. {
  13934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13935. }
  13936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13937. isKnowKey = TRUE;
  13938. }
  13939. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13940. {
  13941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13944. {
  13945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13946. }
  13947. else
  13948. {
  13949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13950. }
  13951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13952. isKnowKey = TRUE;
  13953. }
  13954. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13955. {
  13956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13959. {
  13960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13961. }
  13962. else
  13963. {
  13964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13965. }
  13966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13967. isKnowKey = TRUE;
  13968. }
  13969. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13970. {
  13971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13974. {
  13975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13976. }
  13977. else
  13978. {
  13979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13980. }
  13981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13982. isKnowKey = TRUE;
  13983. }
  13984. /*
  13985. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13986. {
  13987. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13990. {
  13991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13992. }
  13993. else
  13994. {
  13995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13996. }
  13997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13998. isKnowKey = TRUE;
  13999. }*/
  14000. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14001. {
  14002. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14005. {
  14006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14007. }
  14008. else
  14009. {
  14010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14011. }
  14012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14013. isKnowKey = TRUE;
  14014. }
  14015. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14016. {
  14017. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14020. {
  14021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14022. }
  14023. else
  14024. {
  14025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14026. }
  14027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14028. isKnowKey = TRUE;
  14029. }
  14030. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14031. {
  14032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14034. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14035. {
  14036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14037. }
  14038. else
  14039. {
  14040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14041. }
  14042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14043. isKnowKey = TRUE;
  14044. }
  14045. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14046. {
  14047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14049. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14050. {
  14051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14052. }
  14053. else
  14054. {
  14055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14056. }
  14057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14058. isKnowKey = TRUE;
  14059. }
  14060. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14061. {
  14062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14065. {
  14066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14067. }
  14068. else
  14069. {
  14070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14071. }
  14072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14073. isKnowKey = TRUE;
  14074. }
  14075. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14076. {
  14077. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14080. {
  14081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14082. }
  14083. else
  14084. {
  14085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14086. }
  14087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14088. isKnowKey = TRUE;
  14089. }
  14090. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14091. {
  14092. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14095. {
  14096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14097. }
  14098. else
  14099. {
  14100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14101. }
  14102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14103. isKnowKey = TRUE;
  14104. }
  14105. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14106. {
  14107. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14110. {
  14111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14112. }
  14113. else
  14114. {
  14115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14116. }
  14117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14118. isKnowKey = TRUE;
  14119. }
  14120. #if 1
  14121. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14122. {
  14123. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14125. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14126. {
  14127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14128. }
  14129. else
  14130. {
  14131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14132. }
  14133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14134. isKnowKey = TRUE;
  14135. }
  14136. #endif
  14137. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14138. {
  14139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14141. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14142. {
  14143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14144. }
  14145. else
  14146. {
  14147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14148. }
  14149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14150. isKnowKey = TRUE;
  14151. }
  14152. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14153. {
  14154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14156. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14157. {
  14158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14159. }
  14160. else
  14161. {
  14162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14163. }
  14164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14165. isKnowKey = TRUE;
  14166. }
  14167. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14168. {
  14169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14171. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14172. {
  14173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14174. }
  14175. else
  14176. {
  14177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14178. }
  14179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14180. isKnowKey = TRUE;
  14181. }
  14182. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14183. {
  14184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14186. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14187. {
  14188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14189. }
  14190. else
  14191. {
  14192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14193. }
  14194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14195. isKnowKey = TRUE;
  14196. }
  14197. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14198. {
  14199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14201. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14202. {
  14203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14204. }
  14205. else
  14206. {
  14207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14208. }
  14209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14210. isKnowKey = TRUE;
  14211. }
  14212. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14213. {
  14214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14216. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14217. {
  14218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14219. }
  14220. else
  14221. {
  14222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14223. }
  14224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14225. isKnowKey = TRUE;
  14226. }
  14227. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14228. {
  14229. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14231. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14232. {
  14233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14234. }
  14235. else
  14236. {
  14237. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14238. }
  14239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14240. isKnowKey = TRUE;
  14241. }
  14242. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14243. {
  14244. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14246. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14247. {
  14248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14249. }
  14250. else
  14251. {
  14252. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14253. }
  14254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14255. isKnowKey = TRUE;
  14256. }
  14257. //=========================================================
  14258. if(!isEmpty && !isKnowKey)
  14259. {
  14260. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14261. strcpy(unknownkey[UnknownKeynum], keyReq);
  14262. UnknownKeynum = UnknownKeynum + 1;
  14263. }
  14264. }
  14265. void processUnkownKey(void)
  14266. {
  14267. DEBUG_INFO("processUnkownKey...\n");
  14268. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14269. for(int index=0; index < UnknownKeynum; index++)
  14270. {
  14271. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14272. {
  14273. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14274. }
  14275. }
  14276. }
  14277. int setKeyValue(char *key, char *value)
  14278. {
  14279. int isSuccess = NotSupported;
  14280. int check_ascii=0;
  14281. char str[256]={0};
  14282. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14283. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14284. {
  14285. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14287. {
  14288. strcpy(str, (const char*)value);
  14289. for(int i = 0; str[i]; i++){
  14290. str[i] = tolower(str[i]);
  14291. }
  14292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14293. isSuccess = ConfigurationStatus_Accepted;
  14294. }
  14295. else
  14296. {
  14297. isSuccess = ConfigurationStatus_Rejected;
  14298. }
  14299. }
  14300. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14301. {
  14302. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14304. {
  14305. strcpy(str, (const char*)value);
  14306. for(int i = 0; str[i]; i++){
  14307. str[i] = tolower(str[i]);
  14308. }
  14309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14310. isSuccess = ConfigurationStatus_Accepted;
  14311. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14312. }
  14313. else
  14314. {
  14315. isSuccess = ConfigurationStatus_Rejected;
  14316. }
  14317. }
  14318. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14319. {
  14320. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14321. {
  14322. strcpy(str, (const char*)value);
  14323. for(int i = 0; str[i]; i++)
  14324. {
  14325. str[i] = tolower(str[i]);
  14326. }
  14327. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14329. isSuccess = ConfigurationStatus_Accepted;
  14330. }
  14331. else
  14332. {
  14333. isSuccess = ConfigurationStatus_Rejected;
  14334. }
  14335. }
  14336. if(strcmp(key, "BlinkRepeat") == 0)
  14337. {
  14338. //Charger.BlinkRepeat = Integer.parseInt(value);
  14339. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14340. {
  14341. check_ascii = value[0];
  14342. if( (check_ascii < 48) || (check_ascii > 57) )
  14343. {
  14344. isSuccess = ConfigurationStatus_Rejected;
  14345. }
  14346. else
  14347. {
  14348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14349. isSuccess = ConfigurationStatus_Accepted;
  14350. }
  14351. }
  14352. else
  14353. {
  14354. isSuccess = ConfigurationStatus_Rejected;
  14355. }
  14356. }
  14357. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14358. {
  14359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14360. {
  14361. check_ascii = value[0];
  14362. if( (check_ascii < 48) || (check_ascii > 57) )
  14363. {
  14364. isSuccess = ConfigurationStatus_Rejected;
  14365. }
  14366. else
  14367. {
  14368. if((atoi(value) == 0) || (atoi(value) >= 10))
  14369. {
  14370. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14372. isSuccess = ConfigurationStatus_Accepted;
  14373. }
  14374. else
  14375. isSuccess = ConfigurationStatus_Rejected;
  14376. }
  14377. }
  14378. else
  14379. {
  14380. isSuccess = ConfigurationStatus_Rejected;
  14381. }
  14382. }
  14383. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14384. {
  14385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14386. {
  14387. check_ascii = value[0];
  14388. if( (check_ascii < 48) || (check_ascii > 57) )
  14389. {
  14390. isSuccess = ConfigurationStatus_Rejected;
  14391. }
  14392. else
  14393. {
  14394. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14396. isSuccess = ConfigurationStatus_Accepted;
  14397. }
  14398. }
  14399. else
  14400. {
  14401. isSuccess = ConfigurationStatus_Rejected;
  14402. }
  14403. }
  14404. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14405. {
  14406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14407. {
  14408. check_ascii = value[0];
  14409. if( (check_ascii < 48) || (check_ascii > 57) )
  14410. {
  14411. isSuccess = ConfigurationStatus_Rejected;
  14412. }
  14413. else
  14414. {
  14415. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14417. isSuccess = ConfigurationStatus_Accepted;
  14418. }
  14419. }
  14420. else
  14421. {
  14422. isSuccess = ConfigurationStatus_Rejected;
  14423. }
  14424. }
  14425. if(strcmp(key, "HeartbeatInterval") == 0)
  14426. {
  14427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14428. {
  14429. check_ascii = value[0];
  14430. if( (check_ascii < 48) || (check_ascii > 57) )
  14431. {
  14432. isSuccess = ConfigurationStatus_Rejected;
  14433. }
  14434. else
  14435. {
  14436. if((atoi(value) == 0) || (atoi(value) >= 10))
  14437. {
  14438. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14439. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14440. HeartBeatWaitTime = atoi(value);
  14441. isSuccess = ConfigurationStatus_Accepted;
  14442. }
  14443. else
  14444. {
  14445. isSuccess = ConfigurationStatus_Rejected;
  14446. }
  14447. }
  14448. }
  14449. else
  14450. {
  14451. isSuccess = ConfigurationStatus_Rejected;
  14452. }
  14453. }
  14454. if(strcmp(key, "LightIntensity") == 0)
  14455. {
  14456. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14457. {
  14458. check_ascii = value[0];
  14459. if( (check_ascii < 48) || (check_ascii > 57) )
  14460. {
  14461. isSuccess = ConfigurationStatus_Rejected;
  14462. }
  14463. else
  14464. {
  14465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14466. isSuccess = ConfigurationStatus_Accepted;
  14467. }
  14468. }
  14469. else
  14470. {
  14471. isSuccess = ConfigurationStatus_Rejected;
  14472. }
  14473. }
  14474. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14475. {
  14476. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14477. {
  14478. strcpy(str, (const char*)value);
  14479. for(int i = 0; str[i]; i++)
  14480. {
  14481. str[i] = tolower(str[i]);
  14482. }
  14483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14484. isSuccess = ConfigurationStatus_Accepted;
  14485. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14486. }
  14487. else
  14488. {
  14489. isSuccess = ConfigurationStatus_Rejected;
  14490. }
  14491. }
  14492. if(strcmp(key, "LocalPreAuthorize") == 0)
  14493. {
  14494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14495. {
  14496. strcpy(str, (const char*)value);
  14497. for(int i = 0; str[i]; i++)
  14498. {
  14499. str[i] = tolower(str[i]);
  14500. }
  14501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14502. isSuccess = ConfigurationStatus_Accepted;
  14503. }
  14504. else
  14505. {
  14506. isSuccess = ConfigurationStatus_Rejected;
  14507. }
  14508. }
  14509. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14510. {
  14511. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14512. {
  14513. check_ascii = value[0];
  14514. if( (check_ascii < 48) || (check_ascii > 57) )
  14515. {
  14516. isSuccess = ConfigurationStatus_Rejected;
  14517. }
  14518. else
  14519. {
  14520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14521. isSuccess = ConfigurationStatus_Accepted;
  14522. }
  14523. }
  14524. else
  14525. {
  14526. isSuccess = ConfigurationStatus_Rejected;
  14527. }
  14528. }
  14529. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14530. {
  14531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14532. {
  14533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14534. isSuccess = ConfigurationStatus_Accepted;
  14535. }
  14536. else
  14537. {
  14538. isSuccess = ConfigurationStatus_Rejected;
  14539. }
  14540. }
  14541. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14542. {
  14543. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14544. {
  14545. check_ascii = value[0];
  14546. if( (check_ascii < 48) || (check_ascii > 57) )
  14547. {
  14548. isSuccess = ConfigurationStatus_Rejected;
  14549. }
  14550. else
  14551. {
  14552. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14554. isSuccess = ConfigurationStatus_Accepted;
  14555. }
  14556. }
  14557. else
  14558. {
  14559. isSuccess = ConfigurationStatus_Rejected;
  14560. }
  14561. }
  14562. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14563. {
  14564. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14565. {
  14566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14567. isSuccess = ConfigurationStatus_Accepted;
  14568. }
  14569. else
  14570. {
  14571. isSuccess = ConfigurationStatus_Rejected;
  14572. }
  14573. }
  14574. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14575. {
  14576. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14577. {
  14578. check_ascii = value[0];
  14579. if( (check_ascii < 48) || (check_ascii > 57) )
  14580. {
  14581. isSuccess = ConfigurationStatus_Rejected;
  14582. }
  14583. else
  14584. {
  14585. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14587. isSuccess = ConfigurationStatus_Accepted;
  14588. }
  14589. }
  14590. else
  14591. {
  14592. isSuccess = ConfigurationStatus_Rejected;
  14593. }
  14594. }
  14595. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14596. {
  14597. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14598. {
  14599. check_ascii = value[0];
  14600. if( (check_ascii < 48) || (check_ascii > 57) )
  14601. {
  14602. isSuccess = ConfigurationStatus_Rejected;
  14603. }
  14604. else
  14605. {
  14606. if((atoi(value) == 0) || (atoi(value) >= 10))
  14607. {
  14608. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14610. isSuccess = ConfigurationStatus_Accepted;
  14611. }
  14612. else
  14613. {
  14614. isSuccess = ConfigurationStatus_Rejected;
  14615. }
  14616. }
  14617. }
  14618. else
  14619. {
  14620. isSuccess = ConfigurationStatus_Rejected;
  14621. }
  14622. }
  14623. if(strcmp(key, "MinimumStatusDuration") == 0)
  14624. {
  14625. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14626. {
  14627. check_ascii = value[0];
  14628. if( (check_ascii < 48) || (check_ascii > 57) )
  14629. {
  14630. isSuccess = ConfigurationStatus_Rejected;
  14631. }
  14632. else
  14633. {
  14634. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14635. {
  14636. isSuccess = ConfigurationStatus_Rejected;
  14637. }
  14638. else
  14639. {
  14640. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14642. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14643. isSuccess = ConfigurationStatus_Accepted;
  14644. }
  14645. }
  14646. }
  14647. else
  14648. {
  14649. isSuccess = ConfigurationStatus_Rejected;
  14650. }
  14651. }
  14652. if(strcmp(key, "NumberOfConnectors") == 0)
  14653. {
  14654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14655. {
  14656. check_ascii = value[0];
  14657. if( (check_ascii < 48) || (check_ascii > 57) )
  14658. {
  14659. isSuccess = ConfigurationStatus_Rejected;
  14660. }
  14661. else
  14662. {
  14663. //Charger.ResetRetries = Integer.parseInt(value);
  14664. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14665. isSuccess = ConfigurationStatus_Accepted;
  14666. }
  14667. }
  14668. else
  14669. {
  14670. isSuccess = ConfigurationStatus_Rejected;
  14671. }
  14672. }
  14673. if(strcmp(key, "ResetRetries") == 0)
  14674. {
  14675. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14676. {
  14677. check_ascii = value[0];
  14678. if( (check_ascii < 48) || (check_ascii > 57) )
  14679. {
  14680. isSuccess = ConfigurationStatus_Rejected;
  14681. }
  14682. else
  14683. {
  14684. //Charger.ResetRetries = Integer.parseInt(value);
  14685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14686. isSuccess = ConfigurationStatus_Accepted;
  14687. }
  14688. }
  14689. else
  14690. {
  14691. isSuccess = ConfigurationStatus_Rejected;
  14692. }
  14693. }
  14694. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14695. {
  14696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14697. {
  14698. strcpy(str, (const char*)value);
  14699. for(int i = 0; str[i]; i++)
  14700. {
  14701. str[i] = tolower(str[i]);
  14702. }
  14703. if(strcmp(str, "notapplicable")== 0)
  14704. {
  14705. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14706. isSuccess = ConfigurationStatus_Accepted;
  14707. }
  14708. else if(strcmp(str, "unknown")== 0)
  14709. {
  14710. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14711. isSuccess = ConfigurationStatus_Accepted;
  14712. }
  14713. else if(strcmp(str, "rst")== 0)
  14714. {
  14715. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14716. isSuccess = ConfigurationStatus_Accepted;
  14717. }
  14718. else if(strcmp(str, "rts")== 0)
  14719. {
  14720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14721. isSuccess = ConfigurationStatus_Accepted;
  14722. }
  14723. else if(strcmp(str, "srt")== 0)
  14724. {
  14725. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14726. isSuccess = ConfigurationStatus_Accepted;
  14727. }
  14728. else if(strcmp(str, "str")== 0)
  14729. {
  14730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14731. isSuccess = ConfigurationStatus_Accepted;
  14732. }
  14733. else if(strcmp(str, "trs")== 0)
  14734. {
  14735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14736. isSuccess = ConfigurationStatus_Accepted;
  14737. }
  14738. else if(strcmp(str, "tsr")== 0)
  14739. {
  14740. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14741. isSuccess = ConfigurationStatus_Accepted;
  14742. }
  14743. else
  14744. {
  14745. isSuccess = ConfigurationStatus_Rejected;
  14746. }
  14747. }
  14748. else
  14749. {
  14750. isSuccess = ConfigurationStatus_Rejected;
  14751. }
  14752. }
  14753. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14754. {
  14755. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14756. {
  14757. check_ascii = value[0];
  14758. if( (check_ascii < 48) || (check_ascii > 57) )
  14759. {
  14760. isSuccess = ConfigurationStatus_Rejected;
  14761. }
  14762. else
  14763. {
  14764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14765. isSuccess = ConfigurationStatus_Accepted;
  14766. }
  14767. }
  14768. else
  14769. {
  14770. isSuccess = ConfigurationStatus_Rejected;
  14771. }
  14772. }
  14773. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14774. {
  14775. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14776. {
  14777. strcpy(str, (const char*)value);
  14778. for(int i = 0; str[i]; i++)
  14779. {
  14780. str[i] = tolower(str[i]);
  14781. }
  14782. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14784. isSuccess = ConfigurationStatus_Accepted;
  14785. }
  14786. else
  14787. {
  14788. isSuccess = ConfigurationStatus_Rejected;
  14789. }
  14790. }
  14791. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14792. {
  14793. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14794. {
  14795. strcpy(str, (const char*)value);
  14796. for(int i = 0; str[i]; i++)
  14797. {
  14798. str[i] = tolower(str[i]);
  14799. }
  14800. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14802. isSuccess = ConfigurationStatus_Accepted;
  14803. }
  14804. else
  14805. {
  14806. isSuccess = ConfigurationStatus_Rejected;
  14807. }
  14808. }
  14809. if(strcmp(key, "StopTxnAlignedData") == 0)
  14810. {
  14811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14812. {
  14813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14814. isSuccess = ConfigurationStatus_Accepted;
  14815. }
  14816. else
  14817. {
  14818. isSuccess = ConfigurationStatus_Rejected;
  14819. }
  14820. }
  14821. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14822. {
  14823. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14824. {
  14825. check_ascii = value[0];
  14826. if( (check_ascii < 48) || (check_ascii > 57) )
  14827. {
  14828. isSuccess = ConfigurationStatus_Rejected;
  14829. }
  14830. else
  14831. {
  14832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14833. isSuccess = ConfigurationStatus_Accepted;
  14834. }
  14835. }
  14836. else
  14837. {
  14838. isSuccess = ConfigurationStatus_Rejected;
  14839. }
  14840. }
  14841. if(strcmp(key, "StopTxnSampledData") == 0)
  14842. {
  14843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14844. {
  14845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14846. isSuccess = ConfigurationStatus_Accepted;
  14847. }
  14848. else
  14849. {
  14850. isSuccess = ConfigurationStatus_Rejected;
  14851. }
  14852. }
  14853. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14854. {
  14855. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14856. {
  14857. check_ascii = value[0];
  14858. if( (check_ascii < 48) || (check_ascii > 57) )
  14859. {
  14860. isSuccess = ConfigurationStatus_Rejected;
  14861. }
  14862. else
  14863. {
  14864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14865. isSuccess = ConfigurationStatus_Accepted;
  14866. }
  14867. }
  14868. else
  14869. {
  14870. isSuccess = ConfigurationStatus_Rejected;
  14871. }
  14872. }
  14873. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14874. {
  14875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14876. {
  14877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14878. isSuccess = ConfigurationStatus_Accepted;
  14879. }
  14880. else
  14881. {
  14882. isSuccess = ConfigurationStatus_Rejected;
  14883. }
  14884. }
  14885. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14886. {
  14887. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14888. {
  14889. check_ascii = value[0];
  14890. if( (check_ascii < 48) || (check_ascii > 57) )
  14891. {
  14892. isSuccess = ConfigurationStatus_Rejected;
  14893. }
  14894. else
  14895. {
  14896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14897. isSuccess = ConfigurationStatus_Accepted;
  14898. }
  14899. }
  14900. else
  14901. {
  14902. isSuccess = ConfigurationStatus_Rejected;
  14903. }
  14904. }
  14905. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14906. {
  14907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14908. {
  14909. check_ascii = value[0];
  14910. if( (check_ascii < 48) || (check_ascii > 57) )
  14911. {
  14912. isSuccess = ConfigurationStatus_Rejected;
  14913. }
  14914. else
  14915. {
  14916. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14918. TransactionMessageAttemptsValue = atoi(value);
  14919. isSuccess = ConfigurationStatus_Accepted;
  14920. }
  14921. }
  14922. else
  14923. {
  14924. isSuccess = ConfigurationStatus_Rejected;
  14925. }
  14926. }
  14927. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14928. {
  14929. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14930. {
  14931. check_ascii = value[0];
  14932. if( (check_ascii < 48) || (check_ascii > 57) )
  14933. {
  14934. isSuccess = ConfigurationStatus_Rejected;
  14935. }
  14936. else
  14937. {
  14938. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14940. TransactionMessageRetryIntervalValue = atoi(value);
  14941. isSuccess = ConfigurationStatus_Accepted;
  14942. }
  14943. }
  14944. else
  14945. {
  14946. isSuccess = ConfigurationStatus_Rejected;
  14947. }
  14948. }
  14949. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14950. {
  14951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14952. {
  14953. strcpy(str, (const char*)value);
  14954. for(int i = 0; str[i]; i++)
  14955. {
  14956. str[i] = tolower(str[i]);
  14957. }
  14958. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14960. isSuccess = ConfigurationStatus_Accepted;
  14961. }
  14962. else
  14963. {
  14964. isSuccess = ConfigurationStatus_Rejected;
  14965. }
  14966. }
  14967. if(strcmp(key, "WebSocketPingInterval") == 0)
  14968. {
  14969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14970. {
  14971. check_ascii = value[0];
  14972. if( (check_ascii < 48) || (check_ascii > 57) )
  14973. {
  14974. isSuccess = ConfigurationStatus_Rejected;
  14975. }
  14976. else
  14977. {
  14978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14979. isSuccess = ConfigurationStatus_Accepted;
  14980. }
  14981. }
  14982. else
  14983. {
  14984. isSuccess = ConfigurationStatus_Rejected;
  14985. }
  14986. }
  14987. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14988. {
  14989. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14990. {
  14991. strcpy(str, (const char*)value);
  14992. for(int i = 0; str[i]; i++)
  14993. {
  14994. str[i] = tolower(str[i]);
  14995. }
  14996. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14997. isSuccess = ConfigurationStatus_Accepted;
  14998. }
  14999. else
  15000. {
  15001. isSuccess = ConfigurationStatus_Rejected;
  15002. }
  15003. }
  15004. if(strcmp(key, "AuthorizationKey") == 0)
  15005. {
  15006. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15007. {
  15008. strcpy(str, (const char*)value);
  15009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15010. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15011. isSuccess = ConfigurationStatus_Accepted;
  15012. }
  15013. else
  15014. {
  15015. isSuccess = ConfigurationStatus_Rejected;
  15016. }
  15017. }
  15018. if(strcmp(key, "SecurityProfile") == 0)
  15019. {
  15020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15021. {
  15022. check_ascii = value[0];
  15023. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15024. {
  15025. isSuccess = ConfigurationStatus_Rejected;
  15026. }
  15027. else if(check_ascii == 0x33)
  15028. {
  15029. isSuccess = NotSupported;
  15030. }
  15031. else
  15032. {
  15033. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15034. {
  15035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15036. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15037. isSuccess = ConfigurationStatus_Accepted;
  15038. }
  15039. else
  15040. isSuccess = ConfigurationStatus_Rejected;
  15041. }
  15042. }
  15043. else
  15044. {
  15045. isSuccess = ConfigurationStatus_Rejected;
  15046. }
  15047. }
  15048. if(strcmp(key, "DefaultPrice") == 0)
  15049. {
  15050. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15051. {
  15052. strcpy(str, (const char*)value);
  15053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15054. isSuccess = ConfigurationStatus_Accepted;
  15055. }
  15056. else
  15057. {
  15058. isSuccess = ConfigurationStatus_Rejected;
  15059. }
  15060. }
  15061. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15062. {
  15063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15064. {
  15065. strcpy(str, (const char*)value);
  15066. for(int i = 0; str[i]; i++)
  15067. {
  15068. str[i] = tolower(str[i]);
  15069. }
  15070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15071. isSuccess = ConfigurationStatus_Accepted;
  15072. }
  15073. else
  15074. {
  15075. isSuccess = ConfigurationStatus_Rejected;
  15076. }
  15077. }
  15078. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15079. {
  15080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15081. {
  15082. strcpy(str, (const char*)value);
  15083. for(int i = 0; str[i]; i++)
  15084. {
  15085. str[i] = tolower(str[i]);
  15086. }
  15087. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15088. isSuccess = ConfigurationStatus_Accepted;
  15089. }
  15090. else
  15091. {
  15092. isSuccess = ConfigurationStatus_Rejected;
  15093. }
  15094. }
  15095. if(strcmp(key, "TimeOffset") == 0)
  15096. {
  15097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15098. {
  15099. strcpy(str, (const char*)value);
  15100. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15101. isSuccess = ConfigurationStatus_Accepted;
  15102. }
  15103. else
  15104. {
  15105. isSuccess = ConfigurationStatus_Rejected;
  15106. }
  15107. }
  15108. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15109. {
  15110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15111. {
  15112. strcpy(str, (const char*)value);
  15113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15114. isSuccess = ConfigurationStatus_Accepted;
  15115. }
  15116. else
  15117. {
  15118. isSuccess = ConfigurationStatus_Rejected;
  15119. }
  15120. }
  15121. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15122. {
  15123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15124. {
  15125. strcpy(str, (const char*)value);
  15126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15127. isSuccess = ConfigurationStatus_Accepted;
  15128. }
  15129. else
  15130. {
  15131. isSuccess = ConfigurationStatus_Rejected;
  15132. }
  15133. }
  15134. #if 0
  15135. //For OCPP Test Case
  15136. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15137. {
  15138. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15139. {
  15140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  15141. isSuccess = ConfigurationStatus_Accepted;
  15142. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15143. }
  15144. else
  15145. {
  15146. isSuccess = ConfigurationStatus_Rejected;
  15147. }
  15148. }
  15149. #endif
  15150. #if 1
  15151. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15152. {
  15153. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15154. {
  15155. strcpy(str, (const char*)value);
  15156. for(int i = 0; str[i]; i++)
  15157. {
  15158. str[i] = tolower(str[i]);
  15159. }
  15160. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15161. isSuccess = ConfigurationStatus_Accepted;
  15162. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15163. }
  15164. else
  15165. {
  15166. isSuccess = ConfigurationStatus_Rejected;
  15167. }
  15168. }
  15169. #endif
  15170. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15171. {
  15172. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15173. {
  15174. check_ascii = value[0];
  15175. if( (check_ascii < 48) || (check_ascii > 57) )
  15176. {
  15177. isSuccess = ConfigurationStatus_Rejected;
  15178. }
  15179. else
  15180. {
  15181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15182. isSuccess = ConfigurationStatus_Accepted;
  15183. }
  15184. }
  15185. else
  15186. {
  15187. isSuccess = ConfigurationStatus_Rejected;
  15188. }
  15189. }
  15190. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15191. {
  15192. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15193. {
  15194. check_ascii = value[0];
  15195. if( (check_ascii < 48) || (check_ascii > 57) )
  15196. {
  15197. isSuccess = ConfigurationStatus_Rejected;
  15198. }
  15199. else
  15200. {
  15201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15202. isSuccess = ConfigurationStatus_Accepted;
  15203. }
  15204. }
  15205. else
  15206. {
  15207. isSuccess = ConfigurationStatus_Rejected;
  15208. }
  15209. }
  15210. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15211. {
  15212. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15213. {
  15214. strcpy(str, (const char*)value);
  15215. for(int i = 0; str[i]; i++)
  15216. {
  15217. str[i] = tolower(str[i]);
  15218. }
  15219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15220. isSuccess = ConfigurationStatus_Accepted;
  15221. }
  15222. else
  15223. {
  15224. isSuccess = ConfigurationStatus_Rejected;
  15225. }
  15226. }
  15227. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15228. {
  15229. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15230. {
  15231. check_ascii = value[0];
  15232. if( (check_ascii < 48) || (check_ascii > 57) )
  15233. {
  15234. isSuccess = ConfigurationStatus_Rejected;
  15235. }
  15236. else
  15237. {
  15238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15239. isSuccess = ConfigurationStatus_Accepted;
  15240. }
  15241. }
  15242. else
  15243. {
  15244. isSuccess = ConfigurationStatus_Rejected;
  15245. }
  15246. }
  15247. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15248. {
  15249. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15250. {
  15251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15252. isSuccess = ConfigurationStatus_Accepted;
  15253. }
  15254. else
  15255. {
  15256. isSuccess = ConfigurationStatus_Rejected;
  15257. }
  15258. }
  15259. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15260. {
  15261. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15262. {
  15263. check_ascii = value[0];
  15264. if( (check_ascii < 48) || (check_ascii > 57) )
  15265. {
  15266. isSuccess = ConfigurationStatus_Rejected;
  15267. }
  15268. else
  15269. {
  15270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15271. isSuccess = ConfigurationStatus_Accepted;
  15272. }
  15273. }
  15274. else
  15275. {
  15276. isSuccess = ConfigurationStatus_Rejected;
  15277. }
  15278. }
  15279. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15280. {
  15281. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15282. {
  15283. strcpy(str, (const char*)value);
  15284. for(int i = 0; str[i]; i++)
  15285. {
  15286. str[i] = tolower(str[i]);
  15287. }
  15288. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15289. isSuccess = ConfigurationStatus_Accepted;
  15290. }
  15291. else
  15292. {
  15293. isSuccess = ConfigurationStatus_Rejected;
  15294. }
  15295. }
  15296. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15297. {
  15298. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15299. {
  15300. check_ascii = value[0];
  15301. if( (check_ascii < 48) || (check_ascii > 57) )
  15302. {
  15303. isSuccess = ConfigurationStatus_Rejected;
  15304. }
  15305. else
  15306. {
  15307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15308. isSuccess = ConfigurationStatus_Accepted;
  15309. }
  15310. }
  15311. else
  15312. {
  15313. isSuccess = ConfigurationStatus_Rejected;
  15314. }
  15315. }
  15316. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15317. return isSuccess;
  15318. }
  15319. int TransactionMessageAttemptsGet(void)
  15320. {
  15321. return TransactionMessageAttemptsValue;
  15322. }
  15323. int FirstHeartBeatResponse(void)
  15324. {
  15325. return FirstHeartBeat;
  15326. }
  15327. int TransactionMessageRetryIntervalGet(void)
  15328. {
  15329. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15330. }
  15331. int ReadHttpStatus(int sock)
  15332. {
  15333. //char c;
  15334. char buff[1024]="",*ptr=buff+1;
  15335. int bytes_received, status;
  15336. DEBUG_INFO("Begin Response ..\n");
  15337. while((bytes_received = recv(sock, ptr, 1, 0))){
  15338. if(bytes_received==-1){
  15339. perror("ReadHttpStatus");
  15340. exit(1);
  15341. }
  15342. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15343. ptr++;
  15344. }
  15345. *ptr=0;
  15346. ptr=buff+1;
  15347. sscanf(ptr,"%*s %d ", &status);
  15348. DEBUG_INFO("%s\n",ptr);
  15349. DEBUG_INFO("status=%d\n",status);
  15350. DEBUG_INFO("End Response ..\n");
  15351. return (bytes_received>0)?status:0;
  15352. }
  15353. //the only filed that it parsed is 'Content-Length'
  15354. int ParseHeader(int sock)
  15355. {
  15356. //char c;
  15357. char buff[1024]="",*ptr=buff+4;
  15358. int bytes_received;
  15359. DEBUG_INFO("Begin HEADER ..\n");
  15360. while((bytes_received = recv(sock, ptr, 1, 0))){
  15361. if(bytes_received==-1){
  15362. perror("Parse Header");
  15363. exit(1);
  15364. }
  15365. if(
  15366. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15367. (ptr[-1]=='\r') && (*ptr=='\n' )
  15368. ) break;
  15369. ptr++;
  15370. }
  15371. *ptr=0;
  15372. ptr=buff+4;
  15373. //printf("%s",ptr);
  15374. if(bytes_received){
  15375. ptr=strstr(ptr,"Content-Length:");
  15376. if(ptr){
  15377. sscanf(ptr,"%*s %d",&bytes_received);
  15378. }else
  15379. bytes_received=-1; //unknown size
  15380. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15381. }
  15382. DEBUG_INFO("End HEADER ..\n");
  15383. return bytes_received ;
  15384. }
  15385. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15386. {
  15387. int result = TRUE;
  15388. char rmFileCmd[100]={0};
  15389. char FilePath[100]={0};
  15390. char ftpbuf[200];
  15391. int systemresult;
  15392. sprintf(FilePath,"/mnt/%s",filename);
  15393. system("ping 8.8.8.8 &");
  15394. if((access(FilePath,F_OK))!=-1)
  15395. {
  15396. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15397. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15398. system(rmFileCmd);
  15399. }
  15400. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15401. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  15402. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15403. systemresult = system(ftpbuf);
  15404. if(systemresult != 0)
  15405. {
  15406. DEBUG_INFO("http DownLoad error!\n");
  15407. result = FALSE;
  15408. }
  15409. system("pkill ping");
  15410. return result;
  15411. }
  15412. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15413. {
  15414. int result = TRUE;
  15415. char rmFileCmd[100]={0};
  15416. char FilePath[100]={0};
  15417. char ftpbuf[200];
  15418. int systemresult;
  15419. sprintf(FilePath,"/mnt/%s",filename);
  15420. system("ping 8.8.8.8 &");
  15421. if((access(FilePath,F_OK))!=-1)
  15422. {
  15423. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15424. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15425. system(rmFileCmd);
  15426. }
  15427. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15428. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15429. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15430. systemresult = system(ftpbuf);
  15431. if(systemresult != 0)
  15432. {
  15433. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  15434. DEBUG_INFO("Download command: %s\n",ftpbuf);
  15435. systemresult = system(ftpbuf);
  15436. if(systemresult != 0)
  15437. {
  15438. DEBUG_WARN("wget error!\n");
  15439. result = FALSE;
  15440. }
  15441. }
  15442. system("pkill ping");
  15443. return result;
  15444. }
  15445. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15446. {
  15447. char rmFileCmd[100]={0};
  15448. char FilePath[100]={0};
  15449. char buf[512];
  15450. int systemresult = 0;
  15451. //DEBUG_INFO("filename=%s\n",filename);
  15452. //DEBUG_INFO("url=%s\n",url);
  15453. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15454. if((access(FilePath,F_OK))!=-1)
  15455. {
  15456. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15457. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15458. system(rmFileCmd);
  15459. }
  15460. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15461. if(fp == NULL)
  15462. {
  15463. DEBUG_INFO("log is NULL\n");
  15464. return FALSE;
  15465. }
  15466. else
  15467. {
  15468. fprintf(fp, "%s\n", url);
  15469. fprintf(fp, "%s\n", filename);
  15470. fclose(fp);
  15471. }
  15472. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15473. if(phpFP == NULL)
  15474. {
  15475. DEBUG_INFO("PHP upload fail.\n");
  15476. return FALSE;
  15477. }
  15478. else
  15479. {
  15480. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15481. {
  15482. if(strstr(buf, "result") != NULL)
  15483. {
  15484. sscanf(buf, "result: %d", &systemresult);
  15485. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15486. }
  15487. }
  15488. pclose(phpFP);
  15489. }
  15490. if(systemresult != 1)
  15491. {
  15492. DEBUG_INFO("HTTP upload error!\n");
  15493. return FALSE;
  15494. }
  15495. return TRUE;
  15496. }
  15497. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15498. {
  15499. struct hostent* server;
  15500. char *IPbuffer;
  15501. char ftpbuf[200];
  15502. int systemresult;
  15503. // To retrieve host information
  15504. server = gethostbyname(location);
  15505. // To convert an Internet network
  15506. // address into ASCII string
  15507. IPbuffer = inet_ntoa(*((struct in_addr*)
  15508. server->h_addr_list[0]));
  15509. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15510. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15511. /* format : ftpput -u username -p passwd IP target source*/
  15512. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15513. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15514. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15515. systemresult = system(ftpbuf);
  15516. DEBUG_INFO("systemresult=%d\n",systemresult);
  15517. if(systemresult != 0)
  15518. {
  15519. DEBUG_INFO("ftpput error!\n");
  15520. return FALSE;
  15521. }
  15522. return TRUE;
  15523. }
  15524. int GetOcppServerURL()
  15525. {
  15526. int result = FALSE;
  15527. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15528. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15529. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15530. struct yuarel url;
  15531. char urlStr[512];
  15532. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15533. {
  15534. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15535. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15536. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15537. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15538. if(yuarel_parse(&url, urlStr) != -1)
  15539. {
  15540. sprintf(OcppProtocol, "%s", url.scheme);
  15541. sprintf(OcppHost, "%s", url.host);
  15542. if(url.path == NULL)
  15543. OcppTempPath[0] = '\0';
  15544. else
  15545. {
  15546. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15547. {
  15548. sprintf(OcppTempPath, "%s/", url.path);
  15549. }
  15550. else
  15551. {
  15552. sprintf(OcppTempPath, "%s", url.path);
  15553. }
  15554. }
  15555. if(url.port == 0)
  15556. {
  15557. if(strcmp(OcppProtocol, "wss") == 0)
  15558. OcppPort = 443;
  15559. else
  15560. OcppPort = 80;
  15561. }
  15562. else
  15563. OcppPort = url.port;
  15564. result = TRUE;
  15565. }
  15566. }
  15567. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15568. {
  15569. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15570. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15571. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15572. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15573. if(yuarel_parse(&url, urlStr) != -1)
  15574. {
  15575. sprintf(OcppProtocol, "%s", url.scheme);
  15576. sprintf(OcppHost, "%s", url.host);
  15577. if(url.path == NULL)
  15578. OcppTempPath[0] = '\0';
  15579. else
  15580. sprintf(OcppTempPath, "%s", url.path);
  15581. if(url.port == 0)
  15582. {
  15583. if(strcmp(OcppProtocol, "wss") == 0)
  15584. OcppPort = 443;
  15585. else
  15586. OcppPort = 80;
  15587. }
  15588. else
  15589. OcppPort = url.port;
  15590. result = TRUE;
  15591. }
  15592. }
  15593. else
  15594. {
  15595. strcpy(OcppHost,"");
  15596. }
  15597. return result;
  15598. }
  15599. int GetOcppPath()
  15600. {
  15601. int result = FALSE;
  15602. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15603. {
  15604. if(OcppTempPath == NULL)
  15605. {
  15606. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15607. }
  15608. else
  15609. {
  15610. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15611. }
  15612. result = TRUE;
  15613. goto End;
  15614. }
  15615. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15616. {
  15617. if(OcppTempPath == NULL)
  15618. {
  15619. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15620. }
  15621. else
  15622. {
  15623. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15624. }
  15625. result = TRUE;
  15626. goto End;
  15627. }
  15628. else
  15629. {
  15630. strcpy(OcppPath,"");
  15631. }
  15632. End:
  15633. return result;
  15634. }
  15635. int GetOcppPort()
  15636. {
  15637. return OcppPort;
  15638. }
  15639. int GetOcppConnStatus(void)
  15640. {
  15641. return ShmOCPP16Data->OcppConnStatus;
  15642. }
  15643. void SetOcppConnStatus(uint8_t status)
  15644. {
  15645. ShmOCPP16Data->OcppConnStatus = status;
  15646. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15647. }
  15648. int GetHeartBeatWithNOResponse(void)
  15649. {
  15650. return HeartBeatWithNOResponse;
  15651. }
  15652. void SetHeartBeatWithNOResponse(void)
  15653. {
  15654. HeartBeatWithNOResponse = 0;
  15655. }
  15656. void GetStartTransactionIdTag(int gun_index)
  15657. {
  15658. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15659. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15660. }
  15661. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15662. {
  15663. char ch;
  15664. FILE *fptr1;
  15665. int temptransactionId;
  15666. char str[100]={0};
  15667. temptransactionId = 0;
  15668. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15669. {
  15670. DEBUG_INFO("IdTag is empty.\n");
  15671. return temptransactionId;
  15672. }
  15673. /*------ Read the file ----------------*/
  15674. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15675. if (!fptr1)
  15676. {
  15677. DEBUG_INFO("QueueTransactionId file open error.\n");
  15678. //printf(" File not found or unable to open the input file!!\n");
  15679. return temptransactionId;
  15680. }
  15681. ch=fgetc(fptr1);
  15682. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15683. rewind(fptr1);
  15684. if(ch!=EOF)
  15685. {
  15686. // printf("%c",ch);
  15687. while (fgets(str, 100, fptr1) != NULL)
  15688. {
  15689. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15690. if(str[0]=='\0')
  15691. {
  15692. break;
  15693. }
  15694. char *revbuf[8] = {0}; // Variable store string split
  15695. int num = 0;// Quantity after string split
  15696. DEBUG_INFO("Transaction queue data= %s\n", str);
  15697. splitstring(str,",",revbuf,&num); // String split
  15698. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15699. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15700. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15701. DEBUG_INFO("------------------------------\n");
  15702. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15703. {
  15704. if(isStopTransaction)
  15705. {
  15706. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15707. {
  15708. temptransactionId = atoi(revbuf[2]);
  15709. //break;
  15710. }
  15711. }
  15712. else
  15713. {
  15714. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15715. {
  15716. temptransactionId = atoi(revbuf[2]);
  15717. //break;
  15718. }
  15719. }
  15720. }
  15721. }
  15722. }
  15723. else
  15724. DEBUG_INFO("EOF\n");
  15725. fclose(fptr1);
  15726. /*------- End of reading ---------------*/
  15727. return temptransactionId;
  15728. }
  15729. void SetTransactionIdZero(int transactionId)
  15730. {
  15731. char ch;
  15732. FILE *fptr1, *fptr2;
  15733. int temptransactionId = 0;
  15734. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15735. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15736. if (!fptr1)
  15737. {
  15738. //printf(" File not found or unable to open the input file!!\n");
  15739. return ;
  15740. }
  15741. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15742. if (!fptr2)
  15743. {
  15744. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15745. fclose(fptr1);
  15746. return ;
  15747. }
  15748. ch=fgetc(fptr1);
  15749. rewind(fptr1);
  15750. if(ch!=EOF)
  15751. {
  15752. // copy all contents to the temporary file except the specific line
  15753. while (fgets(str, 100, fptr1) != NULL)
  15754. {
  15755. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15756. if(str[0]=='\0')
  15757. {
  15758. break;
  15759. }
  15760. char *revbuf[8] = {0};
  15761. int num = 0;
  15762. strcpy(strtemp, str);
  15763. splitstring(str,",",revbuf,&num);
  15764. if(revbuf[2][0] != '\0')
  15765. {
  15766. temptransactionId = atoi(revbuf[2]);
  15767. if(transactionId != temptransactionId)
  15768. {
  15769. fprintf(fptr2, "%s\n", strtemp);
  15770. }
  15771. }
  15772. }
  15773. }
  15774. fclose(fptr1);
  15775. fclose(fptr2);
  15776. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15777. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15778. /*------ Read the file ----------------*/
  15779. }
  15780. int InternetDisconnect(void)
  15781. {
  15782. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15783. }
  15784. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15785. void storeTempStopTransaction(int gun_index)
  15786. {
  15787. char guid[37]={0};
  15788. int tempIndex = 0;
  15789. char TempStopTransaction[256];
  15790. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15791. DEBUG_INFO("storeTempStopTransaction...\n");
  15792. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15793. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15794. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15795. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15796. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15797. {
  15798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15799. {
  15800. tempIndex = ((gun_index==2) ? 1: 0);
  15801. }
  15802. else
  15803. {
  15804. tempIndex = gun_index;
  15805. }
  15806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15807. {
  15808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15809. {
  15810. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15811. }
  15812. }// END OF CHAdeMO_QUANTITY
  15813. }
  15814. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15815. {
  15816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15817. {
  15818. tempIndex = ((gun_index==2) ? 1: 0);
  15819. }
  15820. else
  15821. {
  15822. tempIndex = gun_index;
  15823. }
  15824. for (int index = 0; index < CCS_QUANTITY; index++)
  15825. {
  15826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15827. {
  15828. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15829. }
  15830. }// END OF CCS_QUANTITY
  15831. }
  15832. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15833. {
  15834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15835. {
  15836. tempIndex = ((gun_index==2) ? 1: 0);
  15837. }
  15838. else
  15839. {
  15840. tempIndex = gun_index;
  15841. }
  15842. for (int index = 0; index < GB_QUANTITY; index++)
  15843. {
  15844. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15845. {
  15846. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15847. }
  15848. }// END OF GB_QUANTITY
  15849. }
  15850. else if(gunType[gun_index] == GUN_TYPE_DO)
  15851. {
  15852. tempIndex = gun_index;
  15853. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15854. {
  15855. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15856. {
  15857. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15858. }
  15859. }
  15860. }
  15861. else
  15862. {
  15863. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15864. {
  15865. tempIndex = 2;
  15866. }
  15867. else
  15868. {
  15869. tempIndex = gun_index;
  15870. }
  15871. for (int index = 0; index < AC_QUANTITY; index++)
  15872. {
  15873. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15874. {
  15875. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15876. }
  15877. }// END OF AC_QUANTITY
  15878. }
  15879. //Stop Transaction Time
  15880. struct timeval tmnow;
  15881. struct tm *tm;
  15882. char buf[28];//, usec_buf[6];
  15883. gettimeofday(&tmnow, NULL);
  15884. time_t t;
  15885. t = time(NULL);
  15886. /*UTC time and date*/
  15887. tm = gmtime(&t);
  15888. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15889. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15890. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15891. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15892. random_uuid(guid);
  15893. /***********************************transactionData******************************************************/
  15894. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15895. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15896. //=================================
  15897. //1. Transaction_Begin
  15898. //=================================
  15899. //============================== Energy.Active.Import.Interval ===========================================
  15900. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15901. {
  15902. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15905. 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*/]);
  15906. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15907. 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))
  15908. {
  15909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15910. }
  15911. else
  15912. {
  15913. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15914. }
  15915. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15916. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15917. }
  15918. //=================================
  15919. //2. Transaction_End
  15920. //=================================
  15921. //2.1====================================== Current.Import L1 ==============================================
  15922. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15923. {
  15924. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15925. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15926. {
  15927. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15928. {
  15929. tempIndex = ((gun_index==2) ? 1: 0);
  15930. }
  15931. else
  15932. {
  15933. tempIndex = gun_index;
  15934. }
  15935. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15936. {
  15937. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15938. {
  15939. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15940. }
  15941. }// End of for CHAdeMO_QUANTITY
  15942. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15943. }
  15944. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15945. {
  15946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15947. {
  15948. tempIndex = ((gun_index==2) ? 1: 0);
  15949. }
  15950. else
  15951. {
  15952. tempIndex = gun_index;
  15953. }
  15954. for (int index = 0; index < CCS_QUANTITY; index++)
  15955. {
  15956. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15957. {
  15958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15959. }
  15960. }// End of for CCS_QUANTITY
  15961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15962. }
  15963. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15964. {
  15965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15966. {
  15967. tempIndex = ((gun_index==2) ? 1: 0);
  15968. }
  15969. else
  15970. {
  15971. tempIndex = gun_index;
  15972. }
  15973. for (int index = 0; index < GB_QUANTITY; index++)
  15974. {
  15975. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15976. {
  15977. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15978. }
  15979. }// End of for GB_QUANTITY
  15980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15981. }
  15982. else if(gunType[gun_index] == GUN_TYPE_DO)
  15983. {
  15984. tempIndex = gun_index;
  15985. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15986. {
  15987. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15988. {
  15989. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15990. }
  15991. }
  15992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15993. }
  15994. else
  15995. {
  15996. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15997. {
  15998. tempIndex = 2;
  15999. }
  16000. else
  16001. {
  16002. tempIndex = gun_index;
  16003. }
  16004. for (int index = 0; index < AC_QUANTITY; index++)
  16005. {
  16006. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16007. {
  16008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16009. }
  16010. }// End of for AC_QUANTITY
  16011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16012. }
  16013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16016. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16019. }
  16020. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16021. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16022. {
  16023. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16024. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16025. {
  16026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16027. {
  16028. tempIndex = ((gun_index==2) ? 1: 0);
  16029. }
  16030. else
  16031. {
  16032. tempIndex = gun_index;
  16033. }
  16034. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16035. {
  16036. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16037. {
  16038. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16039. }
  16040. }// END OF CHAdeMO_QUANTITY
  16041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16042. }
  16043. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16044. {
  16045. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16046. {
  16047. tempIndex = ((gun_index==2) ? 1: 0);
  16048. }
  16049. else
  16050. {
  16051. tempIndex = gun_index;
  16052. }
  16053. for (int index = 0; index < CCS_QUANTITY; index++)
  16054. {
  16055. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16056. {
  16057. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16058. }
  16059. }// END OF CCS_QUANTITY
  16060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16061. }
  16062. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16063. {
  16064. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16065. {
  16066. tempIndex = ((gun_index==2) ? 1: 0);
  16067. }
  16068. else
  16069. {
  16070. tempIndex = gun_index;
  16071. }
  16072. for (int index = 0; index < GB_QUANTITY; index++)
  16073. {
  16074. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16075. {
  16076. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16077. }
  16078. }// END OF GB_QUANTITY
  16079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16080. }
  16081. else if(gunType[gun_index] == GUN_TYPE_DO)
  16082. {
  16083. tempIndex = gun_index;
  16084. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16085. {
  16086. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16087. {
  16088. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16089. }
  16090. }
  16091. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16092. }
  16093. else
  16094. {
  16095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16096. {
  16097. tempIndex = 2;
  16098. }
  16099. else
  16100. {
  16101. tempIndex = gun_index;
  16102. }
  16103. for (int index = 0; index < AC_QUANTITY; index++)
  16104. {
  16105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16106. {
  16107. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16108. }
  16109. }// END OF AC_QUANTITY
  16110. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16111. }
  16112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16113. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16115. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16117. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16118. }
  16119. //2.3====================================== Power.Active.Import =========================================
  16120. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16121. {
  16122. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16123. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16124. {
  16125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16126. {
  16127. tempIndex = ((gun_index==2) ? 1: 0);
  16128. }
  16129. else
  16130. {
  16131. tempIndex = gun_index;
  16132. }
  16133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16134. {
  16135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16136. {
  16137. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16138. }
  16139. } // End for CHAdeMO_QUANTITY
  16140. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16141. }
  16142. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16143. {
  16144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16145. {
  16146. tempIndex = ((gun_index==2) ? 1: 0);
  16147. }
  16148. else
  16149. {
  16150. tempIndex = gun_index;
  16151. }
  16152. for (int index = 0; index < CCS_QUANTITY; index++)
  16153. {
  16154. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16155. {
  16156. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16157. }
  16158. } // END for CCS_QUANTITY
  16159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16160. }
  16161. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16162. {
  16163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16164. {
  16165. tempIndex = ((gun_index==2) ? 1: 0);
  16166. }
  16167. else
  16168. {
  16169. tempIndex = gun_index;
  16170. }
  16171. for (int index = 0; index < GB_QUANTITY; index++)
  16172. {
  16173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16174. {
  16175. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16176. }
  16177. }// END for GB_QUANTITY
  16178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16179. }
  16180. else if(gunType[gun_index] == GUN_TYPE_DO)
  16181. {
  16182. tempIndex = gun_index;
  16183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16184. {
  16185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16186. {
  16187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16188. }
  16189. }
  16190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16191. }
  16192. else
  16193. {
  16194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16195. {
  16196. tempIndex = 2;
  16197. }
  16198. else
  16199. {
  16200. tempIndex = gun_index;
  16201. }
  16202. for (int index = 0; index < AC_QUANTITY; index++)
  16203. {
  16204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16205. {
  16206. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16207. }
  16208. } // END for AC_QUANTITY
  16209. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16210. }
  16211. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16212. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16213. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16214. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16217. }
  16218. //2.4====================================== Voltage L1 ====================================================
  16219. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16220. {
  16221. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16222. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16223. {
  16224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16225. {
  16226. tempIndex = ((gun_index==2) ? 1: 0);
  16227. }
  16228. else
  16229. {
  16230. tempIndex = gun_index;
  16231. }
  16232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16233. {
  16234. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16235. {
  16236. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16237. }
  16238. } // END OF FOR CHAdeMO_QUANTITY
  16239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16240. }
  16241. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16242. {
  16243. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16244. {
  16245. tempIndex = ((gun_index==2) ? 1: 0);
  16246. }
  16247. else
  16248. {
  16249. tempIndex = gun_index;
  16250. }
  16251. for (int index = 0; index < CCS_QUANTITY; index++)
  16252. {
  16253. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16254. {
  16255. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16256. }
  16257. } // END OF FOR CCS_QUANTITY
  16258. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16259. }
  16260. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16261. {
  16262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16263. {
  16264. tempIndex = ((gun_index==2) ? 1: 0);
  16265. }
  16266. else
  16267. {
  16268. tempIndex = gun_index;
  16269. }
  16270. for (int index = 0; index < GB_QUANTITY; index++)
  16271. {
  16272. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16273. {
  16274. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16275. }
  16276. } // END OF FOR GB_QUANTITY
  16277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16278. }
  16279. else if(gunType[gun_index] == GUN_TYPE_DO)
  16280. {
  16281. tempIndex = gun_index;
  16282. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16283. {
  16284. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16285. {
  16286. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16287. }
  16288. }
  16289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16290. }
  16291. else
  16292. {
  16293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16294. {
  16295. tempIndex = 2;
  16296. }
  16297. else
  16298. {
  16299. tempIndex = gun_index;
  16300. }
  16301. for (int index = 0; index < AC_QUANTITY; index++)
  16302. {
  16303. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16304. {
  16305. 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
  16306. }
  16307. } // END OF FOR AC_QUANTITY
  16308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16309. }
  16310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16313. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16316. }
  16317. //2.5============================================== End SoC =========================================================
  16318. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16319. {
  16320. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16321. 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))
  16322. {
  16323. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16324. {
  16325. tempIndex = ((gun_index==2) ? 1: 0);
  16326. }
  16327. else
  16328. {
  16329. tempIndex = gun_index;
  16330. }
  16331. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16332. {
  16333. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16334. {
  16335. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16336. {
  16337. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16338. }
  16339. }
  16340. }
  16341. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16342. {
  16343. for (int index = 0; index < CCS_QUANTITY; index++)
  16344. {
  16345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16346. {
  16347. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16348. }
  16349. }
  16350. }
  16351. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16352. {
  16353. for (int index = 0; index < GB_QUANTITY; index++)
  16354. {
  16355. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16356. {
  16357. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16358. }
  16359. }
  16360. }
  16361. else if(gunType[gun_index] == GUN_TYPE_DO)
  16362. {
  16363. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16364. {
  16365. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16366. {
  16367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16368. }
  16369. }
  16370. }
  16371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16377. } // END FOR DC CASE
  16378. }
  16379. //2.6====================================== Current.Import L2 ==============================================
  16380. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16381. {
  16382. // AC 3 phase L2 current
  16383. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16384. {
  16385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16386. {
  16387. tempIndex = 2;
  16388. }
  16389. else
  16390. {
  16391. tempIndex = gun_index;
  16392. }
  16393. for (int index = 0; index < AC_QUANTITY; index++)
  16394. {
  16395. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16396. {
  16397. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16398. }
  16399. }// End of for AC_QUANTITY
  16400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16401. }
  16402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16403. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16404. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16407. }
  16408. //2.7====================================== Current.Import L3 ==============================================
  16409. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16410. {
  16411. // AC 3 phase L3 current
  16412. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16413. {
  16414. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16415. {
  16416. tempIndex = 2;
  16417. }
  16418. else
  16419. {
  16420. tempIndex = gun_index;
  16421. }
  16422. for (int index = 0; index < AC_QUANTITY; index++)
  16423. {
  16424. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16425. {
  16426. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16427. }
  16428. }// End of for AC_QUANTITY
  16429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16430. }
  16431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16432. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16433. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16435. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16436. }
  16437. //2.9====================================== Voltage L2 ====================================================
  16438. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16439. {
  16440. // AC 3 phase L2 volatge
  16441. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16442. {
  16443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16444. {
  16445. tempIndex = 2;
  16446. }
  16447. else
  16448. {
  16449. tempIndex = gun_index;
  16450. }
  16451. for (int index = 0; index < AC_QUANTITY; index++)
  16452. {
  16453. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16454. {
  16455. 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
  16456. }
  16457. } // END OF FOR AC_QUANTITY
  16458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16459. }
  16460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16463. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16465. }
  16466. //2.10====================================== Voltage L3 ====================================================
  16467. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16468. {
  16469. // AC 3 phase L3 volatge
  16470. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16471. {
  16472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16473. {
  16474. tempIndex = 2;
  16475. }
  16476. else
  16477. {
  16478. tempIndex = gun_index;
  16479. }
  16480. for (int index = 0; index < AC_QUANTITY; index++)
  16481. {
  16482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16483. {
  16484. 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
  16485. }
  16486. } // END OF FOR AC_QUANTITY
  16487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16488. }
  16489. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16494. }
  16495. //====================== Start SoC ================================
  16496. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  16497. {
  16498. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16499. 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))
  16500. {
  16501. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16502. {
  16503. tempIndex = ((gun_index==2) ? 1: 0);
  16504. }
  16505. else
  16506. {
  16507. tempIndex = gun_index;
  16508. }
  16509. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16510. {
  16511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16512. {
  16513. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16514. {
  16515. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16516. }
  16517. }
  16518. }
  16519. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16520. {
  16521. for (int index = 0; index < CCS_QUANTITY; index++)
  16522. {
  16523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16524. {
  16525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16526. }
  16527. }
  16528. }
  16529. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16530. {
  16531. for (int index = 0; index < GB_QUANTITY; index++)
  16532. {
  16533. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16534. {
  16535. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16536. }
  16537. }
  16538. }
  16539. else if(gunType[gun_index] == GUN_TYPE_DO)
  16540. {
  16541. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16542. {
  16543. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16544. {
  16545. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16546. }
  16547. }
  16548. }
  16549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16552. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16555. } // END FOR DC CASE
  16556. }
  16557. //======================================== Message create ==============================================
  16558. json_object *StopTransaction = json_object_new_object();
  16559. json_object *transactionDatas = json_object_new_array();
  16560. json_object *sampledValues = json_object_new_array();
  16561. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16562. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16563. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16564. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16565. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16566. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16567. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16568. {
  16569. json_object *transactionData = json_object_new_object();
  16570. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16571. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16572. {
  16573. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16574. {
  16575. json_object *sampledValue = json_object_new_object();
  16576. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16577. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16578. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16579. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16580. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16581. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16582. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16583. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16584. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16585. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16586. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16587. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16588. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16589. json_object_array_add(sampledValues, sampledValue);
  16590. }
  16591. }
  16592. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16593. json_object_array_add(transactionDatas, transactionData);
  16594. }
  16595. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16596. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16597. ,MESSAGE_TYPE_CALL
  16598. ,guid
  16599. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16600. json_object_put(StopTransaction);
  16601. // Check File "TempStopTransaction" Exist
  16602. if((access(TempStopTransaction,F_OK))!=-1)
  16603. {
  16604. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16605. fclose(fopen(TempStopTransaction, "w"));
  16606. }
  16607. else
  16608. {
  16609. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16610. FILE *log = fopen(TempStopTransaction, "w+");
  16611. if(log == NULL)
  16612. {
  16613. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16614. return ;
  16615. }
  16616. else
  16617. {
  16618. fclose(log);
  16619. }
  16620. }
  16621. //Add TempStopTransaction | Update TempStopTransaction
  16622. // open file for writing
  16623. FILE *outfile;
  16624. outfile = fopen (TempStopTransaction, "a");
  16625. //DEBUG_INFO("data = %s\n", queuedata);
  16626. fputs(queuedata, outfile);
  16627. fputs("\n", outfile);
  16628. fclose (outfile);
  16629. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16630. }
  16631. void checkTempStopTransaction(int gun_index)
  16632. {
  16633. FILE *fptr1;
  16634. char ch;
  16635. char str[QUEUE_MESSAGE_LENGTH]={0};
  16636. char guid[37]={0};
  16637. char tempdata[65]={0};
  16638. char connectorStr[2]={0};
  16639. char TempStopTransaction[256];
  16640. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16641. fptr1 = fopen(TempStopTransaction, "r");
  16642. //TempStopTransaction格式: 槍號,StopTransaction封包
  16643. if (!fptr1)
  16644. {
  16645. //printf(" File not found or unable to open the input file!!\n");
  16646. return ;
  16647. }
  16648. ch=fgetc(fptr1);
  16649. //printf(" Now the content of the file %s is : \n",fname);
  16650. rewind(fptr1);
  16651. if(ch!=EOF)
  16652. {
  16653. // copy all contents to the temporary file except the specific line
  16654. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16655. {
  16656. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16657. if(str[0]=='\0')
  16658. {
  16659. break;
  16660. }
  16661. //TempStopTransaction格式: 槍號,StopTransaction封包
  16662. strncpy(connectorStr, str, 1);
  16663. if(atoi(connectorStr) != (gun_index+1))
  16664. {
  16665. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16666. fclose(fptr1);
  16667. return ;
  16668. }
  16669. //random_uuid(guid);
  16670. strncpy(guid, str+6, 36); //copy guid
  16671. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16672. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16673. {
  16674. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16675. }
  16676. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16677. OCPP_insert_transaction_msg(NO, str);
  16678. memset(str,0,ARRAY_SIZE(str));
  16679. }
  16680. }
  16681. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16682. fclose(fptr1);
  16683. remove(TempStopTransaction); // remove the original file
  16684. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16685. }
  16686. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16687. {
  16688. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16689. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16690. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16691. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16692. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16693. }
  16694. int GetWebSocketPingInterval(void)
  16695. {
  16696. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16697. }
  16698. int GetServerSign(void)
  16699. {
  16700. return server_sign;
  16701. }
  16702. uint8_t GetOcppSecurityProfile()
  16703. {
  16704. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16705. }
  16706. void GetOcppChargerBoxId(uint8_t *data)
  16707. {
  16708. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16709. }
  16710. void GetOcppSecurityPassword(uint8_t *data)
  16711. {
  16712. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16713. }
  16714. void SetOcppVersion(uint8_t *version)
  16715. {
  16716. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16717. DEBUG_INFO("ocpp version: %s\n", version);
  16718. if(strstr((char*)version, "ocpp1.6") != NULL)
  16719. {
  16720. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16721. }
  16722. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16723. {
  16724. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16725. system("pkill OcppBackend");
  16726. }
  16727. }
  16728. void SetServerSign(int value)
  16729. {
  16730. server_sign = value;
  16731. }
  16732. int GetBootNotificationInterval(void)
  16733. {
  16734. return BootNotificationInterval;
  16735. }
  16736. int GetInternetConn(void)
  16737. {
  16738. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16739. }
  16740. int GetBackendConnectionTimeout(void)
  16741. {
  16742. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16743. }
  16744. int isConnectorInitMode(int gun_index)
  16745. {
  16746. int tempIndex = 0;
  16747. int result = TRUE;
  16748. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16749. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16750. {
  16751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16752. {
  16753. tempIndex = ((gun_index==2) ? 1: 0);
  16754. }
  16755. else
  16756. {
  16757. tempIndex = gun_index;
  16758. }
  16759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16760. {
  16761. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16762. {
  16763. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16764. } //end of the same index
  16765. }//end of for CHAdeMO_QUANTITY
  16766. }
  16767. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16768. {
  16769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16770. {
  16771. tempIndex = ((gun_index==2) ? 1: 0);
  16772. }
  16773. else
  16774. {
  16775. tempIndex = gun_index;
  16776. }
  16777. for (int index = 0; index < CCS_QUANTITY; index++)
  16778. {
  16779. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16780. {
  16781. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16782. } //end of the same index
  16783. } // end of for CCS_QUANTITY
  16784. }
  16785. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16786. {
  16787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16788. {
  16789. tempIndex = ((gun_index==2) ? 1: 0);
  16790. }
  16791. else
  16792. {
  16793. tempIndex = gun_index;
  16794. }
  16795. for (int index = 0; index < GB_QUANTITY; index++)
  16796. {
  16797. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16798. {
  16799. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16800. } //end of the same index
  16801. } // end of for GB_QUANTITY
  16802. }
  16803. else if(gunType[gun_index] == GUN_TYPE_DO)
  16804. {
  16805. tempIndex = gun_index;
  16806. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16807. {
  16808. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16809. {
  16810. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16811. } //end of the same index
  16812. }
  16813. }
  16814. else
  16815. {
  16816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16817. {
  16818. tempIndex = 2;
  16819. }
  16820. else
  16821. {
  16822. tempIndex = gun_index;
  16823. }
  16824. for (int index = 0; index < AC_QUANTITY; index++)
  16825. {
  16826. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16827. {
  16828. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16829. }//end of the same index
  16830. }//end of for AC_QUANTITY
  16831. }
  16832. return result;
  16833. }
  16834. void refreshProcDogTimer()
  16835. {
  16836. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16837. }
  16838. void InitialSystemValue(void)
  16839. {
  16840. int connectorIndex = 0;
  16841. //int valueASCII = 0;
  16842. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16843. gunTotalNumber=0;
  16844. SystemInitial = 0;
  16845. locallistVersion=0;
  16846. BootNotificationInterval = 0;
  16847. authorizeRetryTimes = 0;
  16848. GunStatusInterval = 10;
  16849. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16850. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16851. //Hear Beat
  16852. HeartBeatWithNOResponse = 0;
  16853. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16854. FirstHeartBeat = 0;
  16855. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16856. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16857. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16858. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16859. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16860. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16861. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16862. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16863. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16864. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16865. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16866. memset(gunType, 0, ARRAY_SIZE(gunType));
  16867. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16868. {
  16869. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16870. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16871. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16872. {
  16873. // DO series
  16874. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16875. {
  16876. SystemInitial = SystemInitial + 1;
  16877. gunTotalNumber = gunTotalNumber + 1;
  16878. gunType[connectorIndex] = GUN_TYPE_DO;
  16879. connectorIndex = connectorIndex + 1;
  16880. }
  16881. }
  16882. else
  16883. {
  16884. // DM, DW, DS series
  16885. //check connector / socket type (index: 8, 9, 10)
  16886. for(int index=7; index <10 ; index++)
  16887. {
  16888. if(index != 8)
  16889. {
  16890. // DC Connector
  16891. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16892. {
  16893. SystemInitial = SystemInitial + 1;
  16894. gunTotalNumber = gunTotalNumber + 1;
  16895. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16896. connectorIndex = connectorIndex + 1;
  16897. }
  16898. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16899. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16900. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16901. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16902. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16903. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16904. {
  16905. SystemInitial = SystemInitial + 1;
  16906. gunTotalNumber = gunTotalNumber + 1;
  16907. gunType[connectorIndex] = GUN_TYPE_CCS;
  16908. connectorIndex = connectorIndex + 1;
  16909. }
  16910. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16911. {
  16912. SystemInitial = SystemInitial + 1;
  16913. gunTotalNumber = gunTotalNumber + 1;
  16914. gunType[connectorIndex] = GUN_TYPE_GBT;
  16915. connectorIndex = connectorIndex + 1;
  16916. }
  16917. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16918. {
  16919. SystemInitial = SystemInitial + 1;
  16920. gunTotalNumber = gunTotalNumber + 1;
  16921. gunType[connectorIndex] = GUN_TYPE_DO;
  16922. connectorIndex = connectorIndex + 1;
  16923. }
  16924. }
  16925. else
  16926. {
  16927. // AC Connector
  16928. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16929. {
  16930. SystemInitial = SystemInitial + 1;
  16931. gunTotalNumber = gunTotalNumber + 1;
  16932. gunType[connectorIndex] = GUN_TYPE_AC;
  16933. connectorIndex = connectorIndex + 1;
  16934. }
  16935. }
  16936. }
  16937. }
  16938. //DEBUG_INFO("DC ...\n");
  16939. }
  16940. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16941. {
  16942. //check connector / socket type (index: 8, 9, 10)
  16943. for(int index=7; index <10 ; index++)
  16944. {
  16945. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16946. {
  16947. SystemInitial = SystemInitial + 1;
  16948. gunTotalNumber = gunTotalNumber + 1;
  16949. gunType[connectorIndex] = GUN_TYPE_AC;
  16950. connectorIndex = connectorIndex + 1;
  16951. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16952. }
  16953. }
  16954. }
  16955. //Status && ConnectorPlugIn Setting
  16956. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16957. {
  16958. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16959. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16960. }
  16961. for (int index = 0; index < CCS_QUANTITY; index++)
  16962. {
  16963. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16964. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16965. }
  16966. for (int index = 0; index < GB_QUANTITY; index++)
  16967. {
  16968. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16969. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16970. }
  16971. for (int index = 0; index < AC_QUANTITY; index++)
  16972. {
  16973. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16974. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16975. }
  16976. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16977. {
  16978. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16979. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16980. }
  16981. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16982. {
  16983. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16984. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16985. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16986. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16987. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16988. }
  16989. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16990. clientTime.Heartbeat=time((time_t*)NULL);
  16991. sleep(1);
  16992. }
  16993. void LWS_Send(char *str)
  16994. {
  16995. //=====================================================
  16996. // Check InternetConn 0: disconnected, 1: connected
  16997. //====================================================
  16998. if(GetOcppConnStatus() == 0)
  16999. {
  17000. DEBUG_INFO("offline now !!!\n");
  17001. return;
  17002. }
  17003. // Only disable isWebsocketSendable operation initiated by charger
  17004. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17005. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17006. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17007. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17008. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17009. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17010. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17011. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17012. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17013. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17014. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17015. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17016. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17017. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17018. {
  17019. isWebsocketSendable = 0;
  17020. }
  17021. pthread_mutex_lock(&lock_send);
  17022. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17023. sprintf((char *)SendBuffer, "%s", str);
  17024. SendBufLen = strlen(str);
  17025. pthread_mutex_unlock(&lock_send);
  17026. lws_callback_on_writable(wsi_client);
  17027. //lws_service(context, 0);
  17028. //sleep(1);
  17029. }
  17030. void LWS_SendNow(char *str)
  17031. {
  17032. //=====================================================
  17033. // Check InternetConn 0: disconnected, 1: connected
  17034. //====================================================
  17035. if(GetOcppConnStatus() == 0)
  17036. {
  17037. DEBUG_INFO("offline now !!!\n");
  17038. return;
  17039. }
  17040. // Only disable isWebsocketSendable operation initiated by charger
  17041. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17042. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17043. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17044. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17045. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17046. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17047. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17048. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17049. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17050. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17051. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17052. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17053. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17054. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17055. {
  17056. isWebsocketSendable = 0;
  17057. }
  17058. pthread_mutex_lock(&lock_send);
  17059. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17060. sprintf((char *)SendBuffer, "%s", str);
  17061. SendBufLen = strlen(str);
  17062. pthread_mutex_unlock(&lock_send);
  17063. lws_callback_on_writable(wsi_client);
  17064. lws_service(context, 0);
  17065. //sleep(1);
  17066. }