MessageHandler.c 895 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416
  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 ParsingRatedCur modelnameInfo = {0};
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct InterLock
  93. {
  94. unsigned char isGetDiagnosticGoing:1;
  95. unsigned char isUpdateFirmwareGoing:1;
  96. }interLock;
  97. struct ClientTime
  98. {
  99. struct timespec Heartbeat;
  100. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  101. struct timespec StartTransaction;
  102. struct timespec StopTransaction;
  103. struct timespec MeterValues[CONNECTOR_QUANTITY];
  104. struct timespec RemoteStartWait;
  105. }clientTime;
  106. typedef union
  107. {
  108. //Operations Initiated by Central System
  109. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  110. struct
  111. {
  112. //CsMsgValue[0]
  113. unsigned char StatusNotificationReq:1; //bit 0,
  114. unsigned char StatusNotificationConf:1; //bit 1,
  115. unsigned char TriggerMeterValue:1; //bit 2,
  116. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  117. unsigned char isOnCharging:1; //bit 4,
  118. unsigned char :3; //bit5~7
  119. }bits[CONNECTOR_QUANTITY];
  120. }CpinitiateMsg;
  121. CpinitiateMsg cpinitateMsg;
  122. //GetConfiguration Array
  123. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  125. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  126. struct StructLocalAuthorizationList staticLocalAuthorizationList[1]={0};
  127. #if 0
  128. static char *ChargePointErrorCodeStr[] = {
  129. MACROSTR(ConnectorLockFailure),
  130. MACROSTR(EVCommunicationError),
  131. MACROSTR(GroundFailure),
  132. MACROSTR(HighTemperature),
  133. MACROSTR(InternalError),
  134. MACROSTR(LocalListConflict),
  135. MACROSTR(NoError),
  136. MACROSTR(OtherError),
  137. MACROSTR(OverCurrentFailure),
  138. MACROSTR(OverVoltage),
  139. MACROSTR(PowerMeterFailure),
  140. MACROSTR(PowerSwitchFailure),
  141. MACROSTR(ReaderFailure),
  142. MACROSTR(ResetFailure),
  143. MACROSTR(UnderVoltage),
  144. MACROSTR(WeakSignal)
  145. };
  146. #endif
  147. static char * ChargePointStatusStr[] = {
  148. MACROSTR(Available),
  149. MACROSTR(Preparing),
  150. MACROSTR(Charging),
  151. MACROSTR(SuspendedEVSE),
  152. MACROSTR(SuspendedEV),
  153. MACROSTR(Finishing),
  154. MACROSTR(Reserved),
  155. MACROSTR(Unavailable),
  156. MACROSTR(Faulted)
  157. };
  158. static char *RegistrationStatusStr[] = {
  159. MACROSTR(Accepted),
  160. MACROSTR(Pending),
  161. MACROSTR(Rejected)
  162. };
  163. static char *AvailabilityTypeStr[] = {
  164. MACROSTR(Inoperative),
  165. MACROSTR(Operative)
  166. };
  167. static char *AvailabilityStatusStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Rejected),
  170. MACROSTR(Scheduled)
  171. };
  172. static char *ConfigurationStatusStr[] = {
  173. MACROSTR(Accepted),
  174. MACROSTR(Rejected),
  175. MACROSTR(RebootRequired),
  176. MACROSTR(NotSupported)
  177. };
  178. static char *ClearCacheStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected)
  181. };
  182. static char *ChargingProfilePurposeTypeStr[] = {
  183. MACROSTR(ChargePointMaxProfile),
  184. MACROSTR(TxDefaultProfile),
  185. MACROSTR(TxProfile)
  186. };
  187. static char *ChargingProfileStatusStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(NotSupported)
  191. };
  192. static char *ClearChargingProfileStatusStr[] = {
  193. MACROSTR(Accepted),
  194. MACROSTR(Unknown)
  195. };
  196. static char *GetCompositeScheduleStatusStr[] = {
  197. MACROSTR(Accepted),
  198. MACROSTR(Rejected)
  199. };
  200. static char *UpdateTypeStr[] = {
  201. MACROSTR(Differential),
  202. MACROSTR(Full)
  203. };
  204. static char *UpdateStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Failed),
  207. MACROSTR(NotSupported),
  208. MACROSTR(VersionMismatch)
  209. };
  210. static char *RemoteStartStopStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Rejected)
  213. };
  214. static char *ReservationStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Faulted),
  217. MACROSTR(Occupied),
  218. MACROSTR(Rejected),
  219. MACROSTR(Unavailable)
  220. };
  221. static char *ResetTypeStr[] = {
  222. MACROSTR(Hard),
  223. MACROSTR(Soft)
  224. };
  225. static char *ResetStatusStr[] = {
  226. MACROSTR(Accepted),
  227. MACROSTR(Rejected)
  228. };
  229. static char * DiagnosticsStatusStr[] = {
  230. MACROSTR(Idle),
  231. MACROSTR(Uploaded),
  232. MACROSTR(UploadFailed),
  233. MACROSTR(Uploading)
  234. };
  235. static char * FirmwareStatusStr[] = {
  236. MACROSTR(Downloaded),
  237. MACROSTR(DownloadFailed),
  238. MACROSTR(Downloading),
  239. MACROSTR(Idle),
  240. MACROSTR(InstallationFailed),
  241. MACROSTR(Installing),
  242. MACROSTR(Installed)
  243. };
  244. static char * MessageTriggerStr[] = {
  245. MACROSTR(BootNotification),
  246. MACROSTR(DiagnosticsStatusNotification),
  247. MACROSTR(FirmwareStatusNotification),
  248. MACROSTR(Heartbeat),
  249. MACROSTR(MeterValues),
  250. MACROSTR(StatusNotification)
  251. };
  252. static char * TriggerMessageStatusStr[] = {
  253. MACROSTR(Accepted),
  254. MACROSTR(Rejected),
  255. MACROSTR(NotImplemented)
  256. };
  257. static char * UnlockStatusStr[] = {
  258. MACROSTR(Unlocked),
  259. MACROSTR(UnlockFailed),
  260. MACROSTR(NotSupported)
  261. };
  262. #if 0
  263. static char * StopTransactionReasonStr[] = {
  264. MACROSTR(EmergencyStop),
  265. MACROSTR(EVDisconnected),
  266. MACROSTR(HardReset),
  267. MACROSTR(Local),
  268. MACROSTR(Other),
  269. MACROSTR(PowerLoss),
  270. MACROSTR(Reboot),
  271. MACROSTR(Remote),
  272. MACROSTR(SoftReset),
  273. MACROSTR(UnlockCommand),
  274. MACROSTR(DeAuthorized)
  275. };
  276. #endif
  277. static char * CancelReservationStatusStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(Rejected)
  280. };
  281. static char * ReadingContextStr[] = {
  282. MACROSTR(Interruption.Begin),
  283. MACROSTR(Interruption.End),
  284. MACROSTR(Other),
  285. MACROSTR(Sample.Clock),
  286. MACROSTR(Sample.Periodic),
  287. MACROSTR(Transaction.Begin),
  288. MACROSTR(Transaction.End),
  289. MACROSTR(Trigger)
  290. };
  291. static char * ValueFormatStr[] = {
  292. MACROSTR(Raw),
  293. MACROSTR(SignedData)
  294. };
  295. static char * MeasurandStr[] = {
  296. MACROSTR(Current.Export),
  297. MACROSTR(Current.Import),
  298. MACROSTR(Current.Offered),
  299. MACROSTR(Energy.Active.Export.Register),
  300. MACROSTR(Energy.Active.Import.Register),
  301. MACROSTR(Energy.Reactive.Export.Register),
  302. MACROSTR(Energy.Reactive.Import.Register),
  303. MACROSTR(Energy.Active.Export.Interval),
  304. MACROSTR(Energy.Active.Import.Interval),
  305. MACROSTR(Energy.Reactive.Export.Interval),
  306. MACROSTR(Energy.Reactive.Import.Interval),
  307. MACROSTR(Frequency),
  308. MACROSTR(Power.Active.Export),
  309. MACROSTR(Power.Active.Import),
  310. MACROSTR(Power.Factor),
  311. MACROSTR(Power.Offered),
  312. MACROSTR(Power.Reactive.ExportMACROSTR),
  313. MACROSTR(Power.Reactive.Import),
  314. MACROSTR(RPM),
  315. MACROSTR(SoC),
  316. MACROSTR(Temperature),
  317. MACROSTR(Voltage)
  318. };
  319. static char * LocationStr[] = {
  320. MACROSTR(Body),
  321. MACROSTR(Cable),
  322. MACROSTR(EV),
  323. MACROSTR(Inlet),
  324. MACROSTR(Outlet)
  325. };
  326. static char * PhaseStr[] = {
  327. MACROSTR(L1),
  328. MACROSTR(L2),
  329. MACROSTR(L3),
  330. MACROSTR(N),
  331. MACROSTR(L1-N),
  332. MACROSTR(L2-N),
  333. MACROSTR(L3-N),
  334. MACROSTR(L1-L2),
  335. MACROSTR(L2-L3),
  336. MACROSTR(L3-L1)
  337. };
  338. static char * UnitOfMeasureStr[] = {
  339. MACROSTR(Wh),
  340. MACROSTR(kWh),
  341. MACROSTR(varh),
  342. MACROSTR(kvarh),
  343. MACROSTR(W),
  344. MACROSTR(kW),
  345. MACROSTR(VA),
  346. MACROSTR(kVA),
  347. MACROSTR(var),
  348. MACROSTR(kvar),
  349. MACROSTR(A),
  350. MACROSTR(V),
  351. MACROSTR(Celsius),
  352. MACROSTR(Fahrenheit),
  353. MACROSTR(K),
  354. MACROSTR(Percent)
  355. };
  356. //=========================================
  357. // TTIA routine
  358. //=========================================
  359. int sendTTIAInfo(uint8_t gun_index)
  360. {
  361. static int sn = 0;
  362. int result = FAIL;
  363. struct hostent *server;
  364. int udp_socket_fd;
  365. struct sockaddr_in dest_addr = {0};
  366. uint8_t tx_buf[80] = {0};
  367. uint8_t logBuf[256]= {0};
  368. uint8_t tx_len, tempIndex, socStart, socEnd;
  369. uint16_t PresentChargedEnergy;
  370. struct tm tmStart, tmEnd;
  371. DEBUG_INFO("sendTTIAInfo...\n");
  372. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  373. {
  374. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  375. {
  376. tempIndex = ((gun_index==2) ? 1: 0);
  377. }
  378. else
  379. {
  380. tempIndex = gun_index;
  381. }
  382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  383. {
  384. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  385. {
  386. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  387. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  388. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  389. }
  390. }
  391. }
  392. else if(gunType[gun_index] == GUN_TYPE_CCS)
  393. {
  394. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  395. {
  396. tempIndex = ((gun_index==2) ? 1: 0);
  397. }
  398. else
  399. {
  400. tempIndex = gun_index;
  401. }
  402. for (int index = 0; index < CCS_QUANTITY; index++)
  403. {
  404. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  405. {
  406. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  407. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  408. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  409. }
  410. }
  411. }
  412. else if(gunType[gun_index] == GUN_TYPE_GBT)
  413. {
  414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  415. {
  416. tempIndex = ((gun_index==2) ? 1: 0);
  417. }
  418. else
  419. {
  420. tempIndex = gun_index;
  421. }
  422. for (int index = 0; index < GB_QUANTITY; index++)
  423. {
  424. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  425. {
  426. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  427. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  428. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  429. }
  430. }
  431. }
  432. else if(gunType[gun_index] == GUN_TYPE_DO)
  433. {
  434. tempIndex = gun_index;
  435. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  436. {
  437. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  438. {
  439. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  440. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  441. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  442. }
  443. }
  444. }
  445. else
  446. {
  447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  448. {
  449. tempIndex = 2;
  450. }
  451. else
  452. {
  453. tempIndex = gun_index;
  454. }
  455. for (int index = 0; index < AC_QUANTITY; index++)
  456. {
  457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  458. {
  459. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  460. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  461. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  462. }
  463. }// END
  464. }
  465. // Message assembly
  466. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  467. tx_buf[4] = 0x02; // Protocol Version
  468. tx_buf[5] = 0xb0; // Message ID
  469. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  470. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  471. tx_buf[8] = 0x00; // CarID low byte
  472. tx_buf[9] = 0x00; // CarID high byte
  473. tx_buf[10] = 0x00; // ID Storage
  474. tx_buf[11] = 0x00; // Driver lowest byte
  475. tx_buf[12] = 0x00; // Driver 2nd byte
  476. tx_buf[13] = 0x00; // Driver 3rd byte
  477. tx_buf[14] = 0x00; // Driver highest byte
  478. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  479. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  480. tx_buf[17] = 0x00; // Reserve
  481. tx_buf[18] = 60 & 0xff; // Payload length low byte
  482. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  483. // EVSE provider
  484. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  485. // EVSE provider
  486. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  487. // EVSE id
  488. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  489. // Connector id
  490. tx_buf[37] = gun_index;
  491. // EVSE station
  492. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  493. // Vehicle SN
  494. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  495. // Mileage
  496. tx_buf[61] = 0x00; // lowest byte
  497. tx_buf[62] = 0x00; // 2nd byte
  498. tx_buf[63] = 0x00; // highest byte
  499. // Start date time 6 bytes
  500. 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))
  501. {
  502. struct tm *tmTarget;
  503. struct timeb tbTarget;
  504. tmStart.tm_year -= 1900;
  505. tmStart.tm_mon -= 1;
  506. tmStart.tm_gmtoff = 0;
  507. tbTarget.time = mktime(&tmStart);
  508. tbTarget.timezone = 0;
  509. tbTarget.time += (8*3600);
  510. tmTarget = gmtime(&tbTarget.time);
  511. tx_buf[64] = ((tmTarget->tm_year+1900)-2000);
  512. tx_buf[65] = (tmTarget->tm_mon+1);
  513. tx_buf[66] = tmTarget->tm_mday;
  514. tx_buf[67] = tmTarget->tm_hour;
  515. tx_buf[68] = tmTarget->tm_min;
  516. tx_buf[69] = tmTarget->tm_sec;
  517. }
  518. // Stop date time 6 bytes
  519. 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))
  520. {
  521. struct tm *tmTarget;
  522. struct timeb tbTarget;
  523. tmEnd.tm_year -= 1900;
  524. tmEnd.tm_mon -= 1;
  525. tmEnd.tm_gmtoff = 0;
  526. tbTarget.time = mktime(&tmEnd);
  527. tbTarget.timezone = 0;
  528. tbTarget.time += (8*3600);
  529. tmTarget = gmtime(&tbTarget.time);
  530. tx_buf[70] = ((tmTarget->tm_year+1900)-2000);
  531. tx_buf[71] = (tmTarget->tm_mon+1);
  532. tx_buf[72] = tmTarget->tm_mday;
  533. tx_buf[73] = tmTarget->tm_hour;
  534. tx_buf[74] = tmTarget->tm_min;
  535. tx_buf[75] = tmTarget->tm_sec;
  536. }
  537. // Session energy 2 bytes
  538. tx_buf[76] = PresentChargedEnergy & 0xff;
  539. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  540. // Start SOC 1 byte
  541. tx_buf[78] = socStart;
  542. // Stop SOC 1 byte
  543. tx_buf[79] = socEnd;
  544. // Open socket
  545. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  546. if(udp_socket_fd == -1)
  547. {
  548. DEBUG_ERROR("UDP socket create failed!\n");
  549. }
  550. else
  551. {
  552. // Get server DNS entry
  553. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  554. if (server == NULL)
  555. {
  556. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  557. }
  558. else
  559. {
  560. // Build the server's Internet address
  561. bzero((char *) &dest_addr, sizeof(dest_addr));
  562. dest_addr.sin_family = AF_INET;
  563. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  564. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  565. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  566. {
  567. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  568. {
  569. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  570. }
  571. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  572. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  573. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  574. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  575. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  576. DEBUG_TTIA_INFO("---------- Header ----------\n");
  577. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  578. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  579. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  580. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  581. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  582. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  583. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  584. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  585. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  586. DEBUG_TTIA_INFO("Len: 0x3C\n");
  587. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  588. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  589. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  590. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  591. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  592. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  593. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  594. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  595. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  596. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  597. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  598. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  599. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  600. DEBUG_TTIA_INFO("=========================================\n");
  601. sn++;
  602. result = PASS;
  603. }
  604. else
  605. {
  606. DEBUG_ERROR("UDP sent out fail.\n");
  607. }
  608. }
  609. }
  610. return result;
  611. }
  612. //=========================================
  613. // Save configuration
  614. //=========================================
  615. int runShellCmd(const char*cmd)
  616. {
  617. int result = FAIL;
  618. char buf[256];
  619. FILE *fp;
  620. fp = popen(cmd, "r");
  621. if(fp != NULL)
  622. {
  623. while(fgets(buf, sizeof(buf), fp) != NULL)
  624. {
  625. DEBUG_INFO("%s\n", buf);
  626. }
  627. result = PASS;
  628. }
  629. pclose(fp);
  630. return result;
  631. }
  632. int StoreUsrConfigData(struct SysConfigData *UsrData)
  633. {
  634. int result = PASS;
  635. int fd,wrd;
  636. unsigned int i,Chk;
  637. unsigned char *ptr, *BufTmp;
  638. int MtdBlockSize = 0x300000;
  639. Chk=0;
  640. ptr=(unsigned char *)UsrData;
  641. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  642. {
  643. memset(BufTmp,0,MtdBlockSize);
  644. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  645. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  646. Chk+=*(BufTmp+i);
  647. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  648. // Output configuration to file.
  649. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  650. if (fd < 0)
  651. {
  652. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  653. free(BufTmp);
  654. return 0;
  655. }
  656. wrd=write(fd, BufTmp, MtdBlockSize);
  657. close(fd);
  658. if(wrd<MtdBlockSize)
  659. {
  660. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  661. free(BufTmp);
  662. return 0;
  663. }
  664. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  665. DEBUG_INFO("Erase /dev/mtd10.\n");
  666. runShellCmd("flash_erase /dev/mtd10 0 0");
  667. DEBUG_INFO("Write /dev/mtd10.\n");
  668. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  669. DEBUG_INFO("Erase /dev/mtd11.\n");
  670. runShellCmd("flash_erase /dev/mtd11 0 0");
  671. DEBUG_INFO("Write /dev/mtd11.\n");
  672. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  673. system("rm -f /mnt/EvseConfig.bin");
  674. DEBUG_INFO("EvseConfig write to flash OK\n");
  675. }
  676. else
  677. {
  678. DEBUG_ERROR("alloc BlockSize NG\r\n");
  679. result = FAIL;
  680. }
  681. if(BufTmp!=NULL)
  682. free(BufTmp);
  683. return result;
  684. }
  685. //=========================================
  686. // Sqlite3 related function
  687. //=========================================
  688. static int selectSqlCount = 0;
  689. static int callback(void *data, int argc, char **argv, char **azColName){
  690. int i;
  691. //printf("%s: ", (const char*)data);
  692. selectSqlCount = argc;
  693. for(i = 0; i<argc; i++){
  694. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  695. }
  696. //printf("\n");
  697. return 0;
  698. }
  699. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  700. //int i;
  701. //printf("%s:\n", (const char*)data);
  702. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  703. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  704. return 0;
  705. }
  706. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  707. //printf("%s:\n", (const char*)data);
  708. //idTag
  709. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  710. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  711. //parentIdTag
  712. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  713. //expir_date
  714. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  715. //status
  716. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  717. //version
  718. if(columenCount > 5)
  719. idTagQuery.listVersionInt = atoi(columnValue[5]);
  720. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  721. return 0;
  722. }
  723. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  724. {
  725. // localversion = argv[5] ? atoi(argv[5]) : 0;
  726. // printf("localversion=%d\n", localversion);
  727. return 0;
  728. }
  729. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  730. {
  731. for (int i = 0; i < n_columns; i++)
  732. {
  733. DEBUG_INFO("%s\t", col_values[i]);
  734. }
  735. DEBUG_INFO("\n");
  736. return 0;
  737. }
  738. int OCPP_cleanLocalCache()
  739. {
  740. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  741. char *errMsg = 0;
  742. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  743. if (SQLITE_OK != rc)
  744. {
  745. DEBUG_INFO("SQL error: %s\n",errMsg);
  746. return FALSE;
  747. }
  748. return TRUE;
  749. }
  750. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  751. {
  752. int isSuccess = TRUE;
  753. int ret = 0;
  754. //const char* data = "Callback function called";
  755. char sql[300];
  756. char zErrMsg[200];
  757. memset(sql, 0, 300);
  758. memset(zErrMsg, 0, 200);
  759. 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);
  760. //* Execute SQL statement */
  761. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  762. if( ret != SQLITE_OK )
  763. {
  764. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  765. isSuccess = FALSE;
  766. }
  767. return isSuccess;
  768. }
  769. void OCPP_getIdTagFromLocalCache(char idTag[])
  770. {
  771. int rc = 0;
  772. char sql[100];
  773. char zErrMsg[100];
  774. memset(sql, 0, 100);
  775. memset(zErrMsg, 0, 100);
  776. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  777. memset(&idTagQuery, 0, sizeof(idTagQuery));
  778. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  779. /* Execute SQL statement */
  780. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  781. if( rc != SQLITE_OK )
  782. {
  783. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  784. }
  785. }
  786. void OCPP_getListVerion()
  787. {
  788. int rc = 0;
  789. // const char* data = "Callback function called";
  790. char sql[100];
  791. char zErrMsg[100];
  792. memset(sql, 0, 100);
  793. memset(zErrMsg, 0, 100);
  794. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  795. /* Execute SQL statement */
  796. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  797. if( rc != SQLITE_OK )
  798. {
  799. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  800. }
  801. }
  802. void OCPP_get_TableAuthlocalAllData(void)
  803. {
  804. int rc = 0;
  805. char sql[100];
  806. char zErrMsg[100];
  807. memset(sql, 0, 100);
  808. memset(zErrMsg, 0, 100);
  809. sprintf(sql,"select * from ocpp_auth_local ");
  810. /* Execute SQL statement */
  811. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  812. if( rc != SQLITE_OK )
  813. {
  814. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  815. }
  816. //return ver;
  817. }
  818. int OCPP_cleanLocalList()
  819. {
  820. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  821. char *errMsg = 0;
  822. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  823. if (SQLITE_OK != rc)
  824. {
  825. DEBUG_INFO("%s\n",errMsg);
  826. return FALSE;
  827. }
  828. return TRUE;
  829. }
  830. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  831. {
  832. int isSuccess = FALSE;
  833. int ret = 0;
  834. //const char* data = "Callback function called";
  835. char sql[300];
  836. char zErrMsg[200];
  837. memset(sql, 0, 300);
  838. memset(zErrMsg, 0, 200);
  839. 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);
  840. //* Execute SQL statement */
  841. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  842. if( ret != SQLITE_OK )
  843. {
  844. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  845. return isSuccess;
  846. }
  847. memset(sql, 0, 300);
  848. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  849. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  850. if( ret != SQLITE_OK )
  851. {
  852. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  853. return isSuccess;
  854. }
  855. isSuccess = TRUE;
  856. return isSuccess;
  857. }
  858. void OCPP_getIdTagFromLocalList(char idTag[])
  859. {
  860. int rc = 0;
  861. // const char* data = "Callback function called";
  862. char sql[100];
  863. char zErrMsg[100];
  864. memset(sql, 0, 100);
  865. memset(zErrMsg, 0, 100);
  866. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  867. memset(&idTagQuery, 0, sizeof(idTagQuery));
  868. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  869. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  870. /* Execute SQL statement */
  871. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  872. if( rc != SQLITE_OK )
  873. {
  874. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  875. }
  876. //return ver;
  877. }
  878. void OCPP_deleteIdTagFromLocalList(char idTag[])
  879. {
  880. //int ver = 0;
  881. //int isSuccess = FALSE;
  882. int rc = 0;
  883. char sql[100];
  884. char zErrMsg[100];
  885. memset(sql, 0, 100);
  886. memset(zErrMsg, 0, 100);
  887. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  888. //* Execute SQL statement */
  889. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  890. if( rc != SQLITE_OK )
  891. {
  892. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  893. }
  894. }
  895. int getCurrentYear()
  896. {
  897. int result = 0;
  898. time_t CurrentTime;
  899. struct tm *tm;
  900. CurrentTime = time(NULL);
  901. tm=localtime(&CurrentTime);
  902. result = (tm->tm_year + 1900);
  903. return result;
  904. }
  905. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  906. {
  907. int result = PASS;
  908. char* errMsg = NULL;
  909. char sqlStr[8192];
  910. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  911. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  912. {
  913. result = FAIL;
  914. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  915. }
  916. 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));
  917. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  918. {
  919. result = FAIL;
  920. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  921. }
  922. return result;
  923. }
  924. //==========================================
  925. // Check time passed since today
  926. //==========================================
  927. long long DiffTimebWithNow(struct timeb ST)
  928. {
  929. //return milli-second
  930. struct timeb ET;
  931. long long StartTime,StopTime;
  932. ftime(&ET);
  933. StartTime=(long long)ST.time;
  934. StopTime=(long long)ET.time;
  935. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  936. }
  937. int getTimePassSinceToday(uint8_t gun_index)
  938. {
  939. int result = -1;
  940. static time_t lastTime[4];
  941. time_t t;
  942. struct tm *tmStartToday;
  943. struct timeb tbStartToday;
  944. t=time(NULL);
  945. if(difftime(t, lastTime[gun_index])>0)
  946. {
  947. tmStartToday=localtime(&t);
  948. tmStartToday->tm_hour = 0;
  949. tmStartToday->tm_min = 0;
  950. tmStartToday->tm_sec = 0;
  951. tbStartToday.time = mktime(tmStartToday);
  952. tbStartToday.millitm = 0;
  953. result = DiffTimebWithNow(tbStartToday)/1000;
  954. lastTime[gun_index] = t;
  955. }
  956. return result;
  957. }
  958. void getNowDatetime(uint8_t *data)
  959. {
  960. time_t t = time(NULL);
  961. struct tm tm = *localtime(&t);
  962. 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);
  963. }
  964. int syncDateTimeRTC(uint8_t *data)
  965. {
  966. struct ParsingResult
  967. {
  968. int result;
  969. int scanedElement;
  970. int year;
  971. int month;
  972. int mday;
  973. int hour;
  974. int min;
  975. int sec;
  976. int tz_hour;
  977. int tz_min;
  978. float minSec;
  979. }result;
  980. struct tm tmOrg;
  981. struct tm *tmTarget;
  982. struct timeb tbTarget;
  983. char buf[128];
  984. memset(&result, 0x00, sizeof(struct ParsingResult));
  985. result.result = PASS;
  986. if(strstr((char*)data, ".") != NULL)
  987. {
  988. // Original data with mini second
  989. if(strstr((char*)data, "Z") != NULL)
  990. {
  991. // Original data with Z
  992. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  993. &result.year,
  994. &result.month,
  995. &result.mday,
  996. &result.hour,
  997. &result.min,
  998. &result.sec,
  999. &result.minSec);
  1000. }
  1001. else
  1002. {
  1003. // Original data without Z
  1004. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1005. &result.year,
  1006. &result.month,
  1007. &result.mday,
  1008. &result.hour,
  1009. &result.min,
  1010. &result.sec,
  1011. &result.minSec,
  1012. &result.tz_hour,
  1013. &result.tz_min);
  1014. }
  1015. }
  1016. else
  1017. {
  1018. // Original data without mini second
  1019. if(strstr((char*)data, "Z") != NULL)
  1020. {
  1021. // Original data with Z
  1022. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1023. &result.year,
  1024. &result.month,
  1025. &result.mday,
  1026. &result.hour,
  1027. &result.min,
  1028. &result.sec);
  1029. }
  1030. else
  1031. {
  1032. // Original data without Z
  1033. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1034. &result.year,
  1035. &result.month,
  1036. &result.mday,
  1037. &result.hour,
  1038. &result.min,
  1039. &result.sec,
  1040. &result.tz_hour,
  1041. &result.tz_min);
  1042. }
  1043. }
  1044. tmOrg.tm_year = result.year - 1900;
  1045. tmOrg.tm_mon = result.month - 1;
  1046. tmOrg.tm_mday = result.mday;
  1047. tmOrg.tm_hour = result.hour;
  1048. tmOrg.tm_min = result.min;
  1049. tmOrg.tm_sec = result.sec;
  1050. tmOrg.tm_gmtoff = 0;
  1051. tbTarget.time = mktime(&tmOrg);
  1052. tbTarget.timezone = 0;
  1053. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1054. tmTarget = gmtime(&tbTarget.time);
  1055. 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);
  1056. //DEBUG_INFO(" org date time: %s\n", data);
  1057. //DEBUG_INFO("parse date time: %s\n", buf);
  1058. system(buf);
  1059. system("/sbin/hwclock -w --systohc");
  1060. if(result.scanedElement < 6)
  1061. result.result = FAIL;
  1062. return result.result;
  1063. }
  1064. //==========================================
  1065. // GetCompositeSchedule logic related function
  1066. //==========================================
  1067. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1068. {
  1069. //return milli-second
  1070. unsigned int StartTime,StopTime;
  1071. StartTime=(unsigned int)ST.time;
  1072. StopTime=(unsigned int)ET.time;
  1073. return (StopTime-StartTime);
  1074. }
  1075. int DiffTimebWithNowSec(struct timeb ST)
  1076. {
  1077. //return milli-second
  1078. struct timeb ET;
  1079. unsigned int StartTime,StopTime;
  1080. ftime(&ET);
  1081. StartTime=(unsigned int)ST.time;
  1082. StopTime=(unsigned int)ET.time;
  1083. return (StopTime-StartTime);
  1084. }
  1085. int getStartStop(uint8_t *start, uint8_t *stop)
  1086. {
  1087. int result = -1;
  1088. struct tm tmStart;
  1089. struct timeb tbStart;
  1090. struct tm tmStop;
  1091. struct timeb tbStop;
  1092. 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) &&
  1093. (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))
  1094. {
  1095. //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);
  1096. //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);
  1097. tmStart.tm_year -= 1900;
  1098. tmStart.tm_mon -= 1;
  1099. tbStart.time = mktime(&tmStart);
  1100. tbStart.millitm = 0;
  1101. tmStop.tm_year -= 1900;
  1102. tmStop.tm_mon -= 1;
  1103. tbStop.time = mktime(&tmStop);
  1104. tbStop.millitm = 0;
  1105. result = DiffTimebSec(tbStart, tbStop);
  1106. //DEBUG_INFO("getStartStop(): %d\n", result);
  1107. }
  1108. else
  1109. {
  1110. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1111. }
  1112. return result;
  1113. }
  1114. int isOvertNow(uint8_t *start)
  1115. {
  1116. int result = NO;
  1117. struct ParsingResult
  1118. {
  1119. int result;
  1120. int scanedElement;
  1121. int year;
  1122. int month;
  1123. int mday;
  1124. int hour;
  1125. int min;
  1126. int sec;
  1127. int tz_hour;
  1128. int tz_min;
  1129. float minSec;
  1130. }parsingResult;
  1131. struct tm tmStart;
  1132. struct timeb tbStart;
  1133. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  1134. if(strstr((char*)start, ".") != NULL)
  1135. {
  1136. // Original data with mini second
  1137. if(strstr((char*)start, "Z") != NULL)
  1138. {
  1139. // Original data with Z
  1140. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1141. &parsingResult.year,
  1142. &parsingResult.month,
  1143. &parsingResult.mday,
  1144. &parsingResult.hour,
  1145. &parsingResult.min,
  1146. &parsingResult.sec,
  1147. &parsingResult.minSec);
  1148. }
  1149. else
  1150. {
  1151. // Original data without Z
  1152. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1153. &parsingResult.year,
  1154. &parsingResult.month,
  1155. &parsingResult.mday,
  1156. &parsingResult.hour,
  1157. &parsingResult.min,
  1158. &parsingResult.sec,
  1159. &parsingResult.minSec,
  1160. &parsingResult.tz_hour,
  1161. &parsingResult.tz_min);
  1162. }
  1163. }
  1164. else
  1165. {
  1166. // Original data without mini second
  1167. if(strstr((char*)start, "Z") != NULL)
  1168. {
  1169. // Original data with Z
  1170. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1171. &parsingResult.year,
  1172. &parsingResult.month,
  1173. &parsingResult.mday,
  1174. &parsingResult.hour,
  1175. &parsingResult.min,
  1176. &parsingResult.sec);
  1177. }
  1178. else
  1179. {
  1180. // Original data without Z
  1181. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1182. &parsingResult.year,
  1183. &parsingResult.month,
  1184. &parsingResult.mday,
  1185. &parsingResult.hour,
  1186. &parsingResult.min,
  1187. &parsingResult.sec,
  1188. &parsingResult.tz_hour,
  1189. &parsingResult.tz_min);
  1190. }
  1191. }
  1192. if(parsingResult.scanedElement >= 6)
  1193. {
  1194. tmStart.tm_year = parsingResult.year - 1900;
  1195. tmStart.tm_mon = parsingResult.month - 1;
  1196. tmStart.tm_mday = parsingResult.mday;
  1197. tmStart.tm_hour = parsingResult.hour;
  1198. tmStart.tm_min = parsingResult.min;
  1199. tmStart.tm_sec = parsingResult.sec;
  1200. tmStart.tm_gmtoff = 0;
  1201. tbStart.time = mktime(&tmStart);
  1202. tbStart.timezone = 0;
  1203. tbStart.millitm = 0;
  1204. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1205. if(DiffTimebWithNowSec(tbStart) <= 0)
  1206. result = NO;
  1207. else
  1208. result = YES;
  1209. }
  1210. else
  1211. {
  1212. DEBUG_WARN("Start date parsing error.\n");
  1213. }
  1214. return result;
  1215. }
  1216. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1217. {
  1218. int result = -1;
  1219. struct tm tmStart;
  1220. struct timeb tbStart;
  1221. struct tm tmStop;
  1222. struct timeb tbStop;
  1223. 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) &&
  1224. (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))
  1225. {
  1226. tmStart.tm_year -= 1900;
  1227. tmStart.tm_mon -= 1;
  1228. tbStart.time = mktime(&tmStart);
  1229. tbStart.millitm = 0;
  1230. tmStop.tm_year -= 1900;
  1231. tmStop.tm_mon -= 1;
  1232. tbStop.time = mktime(&tmStop);
  1233. tbStop.millitm = 0;
  1234. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1235. }
  1236. return result;
  1237. }
  1238. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1239. {
  1240. FILE *fp;
  1241. char profileFileName[128];
  1242. char *line = NULL;
  1243. size_t len = 0;
  1244. time_t CurrentTime;
  1245. struct tm *tmComposite;
  1246. struct StructChargingProfile maxProfile;
  1247. uint8_t limitMax=0;
  1248. int compositePeriodIdx = 0;
  1249. CurrentTime = time(NULL);
  1250. tmComposite=localtime(&CurrentTime);
  1251. 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);
  1252. if(isUnitA)
  1253. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1254. else
  1255. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1256. compositeProfile->ChargingSchedule.Duration = durationReq;
  1257. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1258. {
  1259. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1260. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1261. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1262. }
  1263. compositeProfile->ChargingProfileId = 0;
  1264. compositeProfile->StackLevel = 99 ;
  1265. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1266. maxProfile.ChargingProfileId = -1;
  1267. maxProfile.ChargingSchedule.Duration = -1;
  1268. system("rm -f /tmp/*.json");
  1269. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1270. // Search max profile
  1271. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1272. if((access(profileFileName, F_OK))!=-1)
  1273. {
  1274. fp = fopen(profileFileName, "r");
  1275. while(getline(&line, &len, fp) != -1)
  1276. {
  1277. json_object *obj = NULL;
  1278. obj = json_tokener_parse(line);
  1279. if(is_error(obj))
  1280. {
  1281. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1282. }
  1283. else
  1284. {
  1285. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1286. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1287. )
  1288. {
  1289. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1290. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1291. )
  1292. {
  1293. struct tm tmFrom, tmTo;
  1294. struct timeb tbFrom, tbTo;
  1295. 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) &&
  1296. (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))
  1297. {
  1298. tmFrom.tm_year -= 1900;
  1299. tmFrom.tm_mon -= 1;
  1300. tbFrom.time = mktime(&tmFrom);
  1301. tmTo.tm_year -= 1900;
  1302. tmTo.tm_mon -= 1;
  1303. tbTo.time = mktime(&tmTo);
  1304. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1305. {
  1306. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1307. {
  1308. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1309. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1310. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1311. }
  1312. maxProfile.ChargingProfileId = -1;
  1313. maxProfile.StackLevel = -1;
  1314. if(maxProfile.ChargingProfileId == -1)
  1315. DEBUG_INFO("MaxProfile found.\n");
  1316. else
  1317. DEBUG_INFO("MaxProfile updated.\n");
  1318. // Required item
  1319. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1320. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1321. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1322. if(isUnitA)
  1323. {
  1324. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1325. 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++)
  1326. {
  1327. 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"));
  1328. 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?
  1329. 3:
  1330. 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")));
  1331. 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")));
  1332. }
  1333. }
  1334. else
  1335. {
  1336. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1337. 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++)
  1338. {
  1339. 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"));
  1340. 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?
  1341. 3:
  1342. 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")));
  1343. 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));
  1344. }
  1345. }
  1346. // Optional item
  1347. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1348. {
  1349. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1350. }
  1351. else
  1352. {
  1353. sprintf((char*)maxProfile.ValidFrom, " ");
  1354. }
  1355. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1356. {
  1357. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1358. }
  1359. else
  1360. {
  1361. sprintf((char*)maxProfile.ValidTo, " ");
  1362. }
  1363. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1364. {
  1365. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1366. }
  1367. else
  1368. {
  1369. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1370. }
  1371. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1372. {
  1373. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1374. }
  1375. else
  1376. {
  1377. maxProfile.TransactionId = -1;
  1378. }
  1379. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1380. {
  1381. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1382. }
  1383. else
  1384. {
  1385. maxProfile.ChargingSchedule.Duration = 86400;
  1386. }
  1387. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1388. {
  1389. 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")));
  1390. }
  1391. else
  1392. {
  1393. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1394. }
  1395. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1396. {
  1397. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1398. }
  1399. else
  1400. {
  1401. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1402. }
  1403. }
  1404. }
  1405. }
  1406. else
  1407. {
  1408. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1409. {
  1410. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1411. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1412. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1413. }
  1414. maxProfile.ChargingProfileId = -1;
  1415. maxProfile.StackLevel = -1;
  1416. if(maxProfile.ChargingProfileId == -1)
  1417. DEBUG_INFO("MaxProfile found.\n");
  1418. else
  1419. DEBUG_INFO("MaxProfile updated.\n");
  1420. // Required item
  1421. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1422. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1423. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1424. if(isUnitA)
  1425. {
  1426. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1427. 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++)
  1428. {
  1429. 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"));
  1430. 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?
  1431. 3:
  1432. 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")));
  1433. 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")));
  1434. }
  1435. }
  1436. else
  1437. {
  1438. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1439. 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++)
  1440. {
  1441. 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"));
  1442. 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?
  1443. 3:
  1444. 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")));
  1445. 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));
  1446. }
  1447. }
  1448. // Optional item
  1449. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1450. {
  1451. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1452. }
  1453. else
  1454. {
  1455. sprintf((char*)maxProfile.ValidFrom, " ");
  1456. }
  1457. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1458. {
  1459. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1460. }
  1461. else
  1462. {
  1463. sprintf((char*)maxProfile.ValidTo, " ");
  1464. }
  1465. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1466. {
  1467. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1468. }
  1469. else
  1470. {
  1471. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1472. }
  1473. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1474. {
  1475. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1476. }
  1477. else
  1478. {
  1479. maxProfile.TransactionId = -1;
  1480. }
  1481. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1482. {
  1483. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1484. }
  1485. else
  1486. {
  1487. maxProfile.ChargingSchedule.Duration = 86400;
  1488. }
  1489. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1490. {
  1491. 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")));
  1492. }
  1493. else
  1494. {
  1495. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1496. }
  1497. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1498. {
  1499. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1500. }
  1501. else
  1502. {
  1503. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1504. }
  1505. }
  1506. }
  1507. }
  1508. json_object_put(obj);
  1509. }
  1510. fclose(fp);
  1511. /*
  1512. if(maxProfile.ChargingProfileId !=-1)
  1513. {
  1514. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1515. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1516. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1517. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1518. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1519. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1520. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1521. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1522. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1523. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1524. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1525. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1526. {
  1527. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1528. {
  1529. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1530. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1531. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1532. }
  1533. }
  1534. }
  1535. else
  1536. DEBUG_INFO("MaxProfile not found.\n");
  1537. DEBUG_INFO("------------------------------------\n");*/
  1538. }
  1539. if(maxProfile.ChargingProfileId != -1)
  1540. {
  1541. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1542. {
  1543. if(maxProfile.ChargingSchedule.Duration != -1)
  1544. {
  1545. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1546. 0:
  1547. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1548. }
  1549. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1550. {
  1551. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1552. {
  1553. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1554. 0:
  1555. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1556. if(idxPeriod > 0)
  1557. {
  1558. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1559. {
  1560. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1561. }
  1562. }
  1563. }
  1564. }
  1565. }
  1566. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1567. {
  1568. if(maxProfile.ChargingSchedule.Duration != -1)
  1569. {
  1570. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1571. }
  1572. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1573. {
  1574. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1575. {
  1576. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1577. if(idxPeriod > 0)
  1578. {
  1579. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1580. {
  1581. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1582. }
  1583. }
  1584. }
  1585. }
  1586. }
  1587. else
  1588. {
  1589. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1590. {
  1591. if(maxProfile.ChargingSchedule.Duration != -1)
  1592. {
  1593. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1594. 0:
  1595. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1596. }
  1597. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1598. {
  1599. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1600. {
  1601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1602. 0:
  1603. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1604. if(idxPeriod > 0)
  1605. {
  1606. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1607. {
  1608. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1609. }
  1610. }
  1611. }
  1612. }
  1613. }
  1614. else
  1615. {
  1616. if(maxProfile.ChargingSchedule.Duration != -1)
  1617. {
  1618. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1619. 0:
  1620. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1621. }
  1622. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1623. {
  1624. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1625. {
  1626. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1627. 0:
  1628. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1629. if(idxPeriod > 0)
  1630. {
  1631. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1632. {
  1633. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1634. }
  1635. }
  1636. }
  1637. }
  1638. }
  1639. }
  1640. /*
  1641. DEBUG_INFO("MaxProfile after align.\n");
  1642. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1643. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1644. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1645. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1646. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1647. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1648. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1649. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1650. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1651. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1652. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1653. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1654. {
  1655. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1656. {
  1657. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1658. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1659. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1660. }
  1661. }
  1662. DEBUG_INFO("------------------------------------\n");*/
  1663. }
  1664. // Find each profile period quantity
  1665. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1666. {
  1667. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1668. limitMax = idx+1;
  1669. }
  1670. if(maxProfile.ChargingProfileId != -1)
  1671. {
  1672. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1673. {
  1674. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1675. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1676. (maxProfile.ChargingSchedule.Duration > 0))
  1677. {
  1678. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1679. {
  1680. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1681. compositePeriodIdx++;
  1682. }
  1683. else
  1684. {
  1685. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1686. }
  1687. }
  1688. }
  1689. }
  1690. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1691. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1692. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1693. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1694. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1695. {
  1696. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1697. {
  1698. compositeProfile->ChargingProfileId = 1;
  1699. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1700. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1701. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1702. }
  1703. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1704. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1705. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1706. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1707. }
  1708. if(line)
  1709. free(line);
  1710. }
  1711. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1712. {
  1713. FILE *fp;
  1714. char profileFileName[128];
  1715. char *line = NULL;
  1716. size_t len = 0;
  1717. time_t CurrentTime;
  1718. struct tm *tmComposite;
  1719. struct StructChargingProfile maxProfile;
  1720. struct StructChargingProfile defaultTxProfile;
  1721. struct StructChargingProfile txProfile;
  1722. struct StructChargingSchedulePeriod tmpPeriod;
  1723. uint8_t limitMax=0;
  1724. uint8_t limitDef=0;
  1725. uint8_t limitTx=0;
  1726. int compositePeriodIdx = 0;
  1727. CurrentTime = time(NULL);
  1728. tmComposite=localtime(&CurrentTime);
  1729. 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);
  1730. if(isUnitA)
  1731. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1732. else
  1733. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1734. compositeProfile->ChargingSchedule.Duration = durationReq;
  1735. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1736. {
  1737. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1738. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1739. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1740. }
  1741. compositeProfile->ChargingProfileId = 0;
  1742. compositeProfile->StackLevel = 99 ;
  1743. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1744. maxProfile.ChargingProfileId = -1;
  1745. defaultTxProfile.ChargingProfileId = -1;
  1746. txProfile.ChargingProfileId = -1;
  1747. maxProfile.ChargingSchedule.Duration = -1;
  1748. defaultTxProfile.ChargingSchedule.Duration = -1;
  1749. txProfile.ChargingSchedule.Duration = -1;
  1750. system("rm -f /tmp/*.json");
  1751. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1752. /*
  1753. * Search valid charging profile
  1754. */
  1755. //DEBUG_INFO("====================================\n");
  1756. // Search tx profile
  1757. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1758. if((access(profileFileName, F_OK))!=-1)
  1759. {
  1760. fp = fopen(profileFileName, "r");
  1761. while(getline(&line, &len, fp) != -1)
  1762. {
  1763. json_object *obj = NULL;
  1764. obj = json_tokener_parse(line);
  1765. if(is_error(obj))
  1766. {
  1767. DEBUG_ERROR("Parse txProfile from file error.\n");
  1768. }
  1769. else
  1770. {
  1771. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1772. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1773. )
  1774. {
  1775. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1776. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1777. )
  1778. {
  1779. struct tm tmFrom, tmTo;
  1780. struct timeb tbFrom, tbTo;
  1781. 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) &&
  1782. (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))
  1783. {
  1784. tmFrom.tm_year -= 1900;
  1785. tmFrom.tm_mon -= 1;
  1786. tbFrom.time = mktime(&tmFrom);
  1787. tmTo.tm_year -= 1900;
  1788. tmTo.tm_mon -= 1;
  1789. tbTo.time = mktime(&tmTo);
  1790. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1791. {
  1792. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1793. {
  1794. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1795. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1796. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1797. }
  1798. txProfile.ChargingProfileId = -1;
  1799. txProfile.StackLevel = -1;
  1800. if(txProfile.ChargingProfileId == -1)
  1801. DEBUG_INFO("TxProfile found.\n");
  1802. else
  1803. DEBUG_INFO("TxProfile updated.\n");
  1804. // Required item
  1805. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1806. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1807. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1808. if(isUnitA)
  1809. {
  1810. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1811. 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++)
  1812. {
  1813. 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"));
  1814. 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?
  1815. 3:
  1816. 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")));
  1817. 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")));
  1818. }
  1819. }
  1820. else
  1821. {
  1822. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1823. 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++)
  1824. {
  1825. 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"));
  1826. 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?
  1827. 3:
  1828. 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")));
  1829. 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));
  1830. }
  1831. }
  1832. // Optional item
  1833. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1834. {
  1835. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1836. }
  1837. else
  1838. {
  1839. sprintf((char*)txProfile.ValidFrom, " ");
  1840. }
  1841. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1842. {
  1843. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1844. }
  1845. else
  1846. {
  1847. sprintf((char*)txProfile.ValidTo, " ");
  1848. }
  1849. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1850. {
  1851. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1852. }
  1853. else
  1854. {
  1855. sprintf((char*)txProfile.RecurrencyKind, " ");
  1856. }
  1857. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1858. {
  1859. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1860. }
  1861. else
  1862. {
  1863. txProfile.TransactionId = -1;
  1864. }
  1865. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1866. {
  1867. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1868. }
  1869. else
  1870. {
  1871. txProfile.ChargingSchedule.Duration = 86400;
  1872. }
  1873. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1874. {
  1875. 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")));
  1876. }
  1877. else
  1878. {
  1879. 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));
  1880. }
  1881. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1882. {
  1883. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1884. }
  1885. else
  1886. {
  1887. txProfile.ChargingSchedule.MinChargingRate = -1;
  1888. }
  1889. }
  1890. }
  1891. }
  1892. else
  1893. {
  1894. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1895. {
  1896. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1897. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1898. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1899. }
  1900. txProfile.ChargingProfileId = -1;
  1901. txProfile.StackLevel = -1;
  1902. if(txProfile.ChargingProfileId == -1)
  1903. DEBUG_INFO("TxProfile found.\n");
  1904. else
  1905. DEBUG_INFO("TxProfile updated.\n");
  1906. // Required item
  1907. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1908. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1909. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1910. if(isUnitA)
  1911. {
  1912. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1913. 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++)
  1914. {
  1915. 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"));
  1916. 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?
  1917. 3:
  1918. 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")));
  1919. 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")));
  1920. }
  1921. }
  1922. else
  1923. {
  1924. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1925. 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++)
  1926. {
  1927. 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"));
  1928. 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?
  1929. 3:
  1930. 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")));
  1931. 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));
  1932. }
  1933. }
  1934. // Optional item
  1935. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1936. {
  1937. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1938. }
  1939. else
  1940. {
  1941. sprintf((char*)txProfile.ValidFrom, " ");
  1942. }
  1943. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1944. {
  1945. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1946. }
  1947. else
  1948. {
  1949. sprintf((char*)txProfile.ValidTo, " ");
  1950. }
  1951. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1952. {
  1953. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1954. }
  1955. else
  1956. {
  1957. sprintf((char*)txProfile.RecurrencyKind, " ");
  1958. }
  1959. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1960. {
  1961. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1962. }
  1963. else
  1964. {
  1965. txProfile.TransactionId = -1;
  1966. }
  1967. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1968. {
  1969. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1970. }
  1971. else
  1972. {
  1973. txProfile.ChargingSchedule.Duration = 86400;
  1974. }
  1975. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1976. {
  1977. 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")));
  1978. }
  1979. else
  1980. {
  1981. 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));
  1982. }
  1983. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1984. {
  1985. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1986. }
  1987. else
  1988. {
  1989. txProfile.ChargingSchedule.MinChargingRate = -1;
  1990. }
  1991. }
  1992. }
  1993. }
  1994. json_object_put(obj);
  1995. }
  1996. fclose(fp);
  1997. /*
  1998. if(txProfile.ChargingProfileId != -1)
  1999. {
  2000. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2001. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2002. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2003. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2004. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2005. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2006. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2007. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  2008. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2009. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2010. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2011. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2012. {
  2013. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2014. {
  2015. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2016. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2017. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2018. }
  2019. }
  2020. }
  2021. else
  2022. DEBUG_INFO("TxProfile not found.\n");*/
  2023. }
  2024. // Search default tx profile
  2025. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  2026. if((access(profileFileName, F_OK))==-1)
  2027. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  2028. if((access(profileFileName, F_OK))!=-1)
  2029. {
  2030. fp = fopen(profileFileName, "r");
  2031. while(getline(&line, &len, fp) != -1)
  2032. {
  2033. json_object *obj = NULL;
  2034. obj = json_tokener_parse(line);
  2035. if(is_error(obj))
  2036. {
  2037. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2038. }
  2039. else
  2040. {
  2041. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2042. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2043. )
  2044. {
  2045. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2046. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2047. )
  2048. {
  2049. struct tm tmFrom, tmTo;
  2050. struct timeb tbFrom, tbTo;
  2051. 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) &&
  2052. (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))
  2053. {
  2054. tmFrom.tm_year -= 1900;
  2055. tmFrom.tm_mon -= 1;
  2056. tbFrom.time = mktime(&tmFrom);
  2057. tmTo.tm_year -= 1900;
  2058. tmTo.tm_mon -= 1;
  2059. tbTo.time = mktime(&tmTo);
  2060. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2061. {
  2062. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2063. {
  2064. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2065. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2066. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2067. }
  2068. defaultTxProfile.ChargingProfileId = -1;
  2069. defaultTxProfile.StackLevel = -1;
  2070. if(defaultTxProfile.ChargingProfileId == -1)
  2071. DEBUG_INFO("TxDefaultProfile found.\n");
  2072. else
  2073. DEBUG_INFO("TxDefaultProfile updated.\n");
  2074. // Required item
  2075. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2076. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2077. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2078. if(isUnitA)
  2079. {
  2080. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2081. 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++)
  2082. {
  2083. 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"));
  2084. 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?
  2085. 3:
  2086. 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")));
  2087. 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")));
  2088. }
  2089. }
  2090. else
  2091. {
  2092. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2093. 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++)
  2094. {
  2095. 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"));
  2096. 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?
  2097. 3:
  2098. 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")));
  2099. 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));
  2100. }
  2101. }
  2102. // Optional item
  2103. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2104. {
  2105. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2106. }
  2107. else
  2108. {
  2109. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2110. }
  2111. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2112. {
  2113. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2114. }
  2115. else
  2116. {
  2117. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2118. }
  2119. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2120. {
  2121. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2122. }
  2123. else
  2124. {
  2125. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2126. }
  2127. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2128. {
  2129. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2130. }
  2131. else
  2132. {
  2133. defaultTxProfile.TransactionId = -1;
  2134. }
  2135. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2136. {
  2137. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2138. }
  2139. else
  2140. {
  2141. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2142. }
  2143. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2144. {
  2145. 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")));
  2146. }
  2147. else
  2148. {
  2149. 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));
  2150. }
  2151. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2152. {
  2153. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2154. }
  2155. else
  2156. {
  2157. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2158. }
  2159. }
  2160. }
  2161. }
  2162. else
  2163. {
  2164. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2165. {
  2166. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2167. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2168. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2169. }
  2170. defaultTxProfile.ChargingProfileId = -1;
  2171. defaultTxProfile.StackLevel = -1;
  2172. if(defaultTxProfile.ChargingProfileId == -1)
  2173. DEBUG_INFO("TxDefaultProfile found.\n");
  2174. else
  2175. DEBUG_INFO("TxDefaultProfile updated.\n");
  2176. // Required item
  2177. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2178. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2179. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2180. if(isUnitA)
  2181. {
  2182. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2183. 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++)
  2184. {
  2185. 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"));
  2186. 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?
  2187. 3:
  2188. 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")));
  2189. 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")));
  2190. }
  2191. }
  2192. else
  2193. {
  2194. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2195. 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++)
  2196. {
  2197. 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"));
  2198. 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?
  2199. 3:
  2200. 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")));
  2201. 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));
  2202. }
  2203. }
  2204. // Optional item
  2205. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2206. {
  2207. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2208. }
  2209. else
  2210. {
  2211. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2212. }
  2213. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2214. {
  2215. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2216. }
  2217. else
  2218. {
  2219. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2220. }
  2221. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2222. {
  2223. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2224. }
  2225. else
  2226. {
  2227. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2228. }
  2229. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2230. {
  2231. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2232. }
  2233. else
  2234. {
  2235. defaultTxProfile.TransactionId = -1;
  2236. }
  2237. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2238. {
  2239. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2240. }
  2241. else
  2242. {
  2243. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2244. }
  2245. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2246. {
  2247. 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")));
  2248. }
  2249. else
  2250. {
  2251. 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));
  2252. }
  2253. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2254. {
  2255. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2256. }
  2257. else
  2258. {
  2259. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2260. }
  2261. }
  2262. }
  2263. }
  2264. json_object_put(obj);
  2265. }
  2266. fclose(fp);
  2267. /*
  2268. if(defaultTxProfile.ChargingProfileId != -1)
  2269. {
  2270. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2271. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2272. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2273. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2274. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2275. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2276. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2277. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2278. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2279. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2280. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2281. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2282. {
  2283. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2284. {
  2285. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2286. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2287. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2288. }
  2289. }
  2290. }
  2291. else
  2292. DEBUG_INFO("TxDefaultProfile not found.\n");
  2293. DEBUG_INFO("------------------------------------\n");*/
  2294. }
  2295. // Search max profile
  2296. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2297. if((access(profileFileName, F_OK))!=-1)
  2298. {
  2299. fp = fopen(profileFileName, "r");
  2300. while(getline(&line, &len, fp) != -1)
  2301. {
  2302. json_object *obj = NULL;
  2303. obj = json_tokener_parse(line);
  2304. if(is_error(obj))
  2305. {
  2306. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2307. }
  2308. else
  2309. {
  2310. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2311. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2312. )
  2313. {
  2314. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2315. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2316. )
  2317. {
  2318. struct tm tmFrom, tmTo;
  2319. struct timeb tbFrom, tbTo;
  2320. 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) &&
  2321. (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))
  2322. {
  2323. tmFrom.tm_year -= 1900;
  2324. tmFrom.tm_mon -= 1;
  2325. tbFrom.time = mktime(&tmFrom);
  2326. tmTo.tm_year -= 1900;
  2327. tmTo.tm_mon -= 1;
  2328. tbTo.time = mktime(&tmTo);
  2329. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2330. {
  2331. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2332. {
  2333. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2334. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2335. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2336. }
  2337. maxProfile.ChargingProfileId = -1;
  2338. maxProfile.StackLevel = -1;
  2339. if(maxProfile.ChargingProfileId == -1)
  2340. DEBUG_INFO("MaxProfile found.\n");
  2341. else
  2342. DEBUG_INFO("MaxProfile updated.\n");
  2343. // Required item
  2344. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2345. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2346. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2347. if(isUnitA)
  2348. {
  2349. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2350. 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++)
  2351. {
  2352. 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"));
  2353. 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?
  2354. 3:
  2355. 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")));
  2356. 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")));
  2357. }
  2358. }
  2359. else
  2360. {
  2361. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2362. 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++)
  2363. {
  2364. 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"));
  2365. 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?
  2366. 3:
  2367. 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")));
  2368. 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));
  2369. }
  2370. }
  2371. // Optional item
  2372. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2373. {
  2374. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2375. }
  2376. else
  2377. {
  2378. sprintf((char*)maxProfile.ValidFrom, " ");
  2379. }
  2380. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2381. {
  2382. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2383. }
  2384. else
  2385. {
  2386. sprintf((char*)maxProfile.ValidTo, " ");
  2387. }
  2388. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2389. {
  2390. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2391. }
  2392. else
  2393. {
  2394. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2395. }
  2396. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2397. {
  2398. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2399. }
  2400. else
  2401. {
  2402. maxProfile.TransactionId = -1;
  2403. }
  2404. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2405. {
  2406. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2407. }
  2408. else
  2409. {
  2410. maxProfile.ChargingSchedule.Duration = 86400;
  2411. }
  2412. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2413. {
  2414. 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")));
  2415. }
  2416. else
  2417. {
  2418. 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));
  2419. }
  2420. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2421. {
  2422. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2423. }
  2424. else
  2425. {
  2426. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2427. }
  2428. }
  2429. }
  2430. }
  2431. else
  2432. {
  2433. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2434. {
  2435. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2436. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2437. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2438. }
  2439. maxProfile.ChargingProfileId = -1;
  2440. maxProfile.StackLevel = -1;
  2441. if(maxProfile.ChargingProfileId == -1)
  2442. DEBUG_INFO("MaxProfile found.\n");
  2443. else
  2444. DEBUG_INFO("MaxProfile updated.\n");
  2445. // Required item
  2446. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2447. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2448. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2449. if(isUnitA)
  2450. {
  2451. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2452. 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++)
  2453. {
  2454. 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"));
  2455. 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?
  2456. 3:
  2457. 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")));
  2458. 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")));
  2459. }
  2460. }
  2461. else
  2462. {
  2463. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2464. 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++)
  2465. {
  2466. 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"));
  2467. 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?
  2468. 3:
  2469. 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")));
  2470. 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));
  2471. }
  2472. }
  2473. // Optional item
  2474. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2475. {
  2476. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2477. }
  2478. else
  2479. {
  2480. sprintf((char*)maxProfile.ValidFrom, " ");
  2481. }
  2482. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2483. {
  2484. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2485. }
  2486. else
  2487. {
  2488. sprintf((char*)maxProfile.ValidTo, " ");
  2489. }
  2490. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2491. {
  2492. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2493. }
  2494. else
  2495. {
  2496. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2497. }
  2498. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2499. {
  2500. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2501. }
  2502. else
  2503. {
  2504. maxProfile.TransactionId = -1;
  2505. }
  2506. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2507. {
  2508. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2509. }
  2510. else
  2511. {
  2512. maxProfile.ChargingSchedule.Duration = 86400;
  2513. }
  2514. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2515. {
  2516. 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")));
  2517. }
  2518. else
  2519. {
  2520. 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));
  2521. }
  2522. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2523. {
  2524. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2525. }
  2526. else
  2527. {
  2528. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2529. }
  2530. }
  2531. }
  2532. }
  2533. json_object_put(obj);
  2534. }
  2535. fclose(fp);
  2536. /*
  2537. if(maxProfile.ChargingProfileId !=-1)
  2538. {
  2539. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2540. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2541. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2542. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2543. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2544. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2545. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2546. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2547. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2548. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2549. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2550. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2551. {
  2552. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2553. {
  2554. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2555. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2556. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2557. }
  2558. }
  2559. }
  2560. else
  2561. DEBUG_INFO("MaxProfile not found.\n");
  2562. DEBUG_INFO("------------------------------------\n");*/
  2563. }
  2564. /*
  2565. * Align found profile start schedule & periods
  2566. */
  2567. //DEBUG_INFO("====================================\n");
  2568. /*
  2569. // For local test usage, force modify found profile start schedule info
  2570. 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);
  2571. 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);
  2572. 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);
  2573. */
  2574. if(txProfile.ChargingProfileId != -1)
  2575. {
  2576. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2577. {
  2578. if(txProfile.ChargingSchedule.Duration != -1)
  2579. {
  2580. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2581. 0:
  2582. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2583. }
  2584. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2585. {
  2586. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2587. {
  2588. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2589. 0:
  2590. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2591. if(idxPeriod > 0)
  2592. {
  2593. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2594. {
  2595. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2596. }
  2597. }
  2598. }
  2599. }
  2600. }
  2601. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2602. {
  2603. if(txProfile.ChargingSchedule.Duration != -1)
  2604. {
  2605. 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?
  2606. 0:
  2607. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2608. }
  2609. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2610. {
  2611. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2612. {
  2613. 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?
  2614. 0:
  2615. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2616. if(idxPeriod > 0)
  2617. {
  2618. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2619. {
  2620. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2621. }
  2622. }
  2623. }
  2624. }
  2625. }
  2626. else
  2627. {
  2628. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2629. {
  2630. if(txProfile.ChargingSchedule.Duration != -1)
  2631. {
  2632. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2633. 0:
  2634. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2635. }
  2636. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2637. {
  2638. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2639. {
  2640. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2641. 0:
  2642. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2643. if(idxPeriod > 0)
  2644. {
  2645. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2646. {
  2647. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2648. }
  2649. }
  2650. }
  2651. }
  2652. }
  2653. else
  2654. {
  2655. if(txProfile.ChargingSchedule.Duration != -1)
  2656. {
  2657. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2658. 0:
  2659. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2660. }
  2661. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2662. {
  2663. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2664. {
  2665. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2666. 0:
  2667. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2668. if(idxPeriod > 0)
  2669. {
  2670. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2671. {
  2672. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. }
  2679. /*
  2680. DEBUG_INFO("txProfile after align.\n");
  2681. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2682. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2683. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2684. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2685. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2686. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2687. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2688. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2689. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2690. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2691. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2692. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2693. {
  2694. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2695. {
  2696. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2697. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2698. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2699. }
  2700. }*/
  2701. }
  2702. if(defaultTxProfile.ChargingProfileId != -1)
  2703. {
  2704. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2705. {
  2706. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2707. {
  2708. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2709. 0:
  2710. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2711. }
  2712. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2713. {
  2714. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2715. {
  2716. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2717. 0:
  2718. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2719. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2720. {
  2721. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2722. }
  2723. if(idxPeriod > 0)
  2724. {
  2725. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2726. {
  2727. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2728. }
  2729. }
  2730. }
  2731. }
  2732. }
  2733. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2734. {
  2735. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2736. {
  2737. 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?
  2738. 0:
  2739. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2740. }
  2741. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2742. {
  2743. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2744. {
  2745. 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?
  2746. 0:
  2747. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2748. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2749. {
  2750. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2751. }
  2752. if(idxPeriod > 0)
  2753. {
  2754. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2755. {
  2756. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2757. }
  2758. }
  2759. }
  2760. }
  2761. }
  2762. else
  2763. {
  2764. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2765. {
  2766. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2767. {
  2768. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2769. 0:
  2770. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2771. }
  2772. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2773. {
  2774. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2775. {
  2776. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2777. 0:
  2778. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2779. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2780. {
  2781. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2782. }
  2783. if(idxPeriod > 0)
  2784. {
  2785. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2786. {
  2787. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2788. }
  2789. }
  2790. }
  2791. }
  2792. }
  2793. else
  2794. {
  2795. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2796. {
  2797. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2798. 0:
  2799. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2800. }
  2801. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2802. {
  2803. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2804. {
  2805. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2806. 0:
  2807. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2808. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2809. {
  2810. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2811. }
  2812. if(idxPeriod > 0)
  2813. {
  2814. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2815. {
  2816. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2817. }
  2818. }
  2819. }
  2820. }
  2821. }
  2822. }
  2823. /*
  2824. DEBUG_INFO("defaultTxProfile after align.\n");
  2825. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2826. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2827. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2828. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2829. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2830. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2831. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2832. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2833. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2834. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2835. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2836. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2837. {
  2838. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2839. {
  2840. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2841. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2842. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2843. }
  2844. }
  2845. DEBUG_INFO("------------------------------------\n");*/
  2846. }
  2847. if(maxProfile.ChargingProfileId != -1)
  2848. {
  2849. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2850. {
  2851. if(maxProfile.ChargingSchedule.Duration != -1)
  2852. {
  2853. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2854. 0:
  2855. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2856. }
  2857. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2858. {
  2859. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2860. {
  2861. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2862. 0:
  2863. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2864. if(idxPeriod > 0)
  2865. {
  2866. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2867. {
  2868. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2869. }
  2870. }
  2871. }
  2872. }
  2873. }
  2874. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2875. {
  2876. if(maxProfile.ChargingSchedule.Duration != -1)
  2877. {
  2878. 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?
  2879. 0:
  2880. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2881. }
  2882. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2883. {
  2884. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2885. {
  2886. 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?
  2887. 0:
  2888. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2889. if(idxPeriod > 0)
  2890. {
  2891. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2892. {
  2893. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2894. }
  2895. }
  2896. }
  2897. }
  2898. }
  2899. else
  2900. {
  2901. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2902. {
  2903. if(maxProfile.ChargingSchedule.Duration != -1)
  2904. {
  2905. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2906. 0:
  2907. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2908. }
  2909. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2910. {
  2911. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2912. {
  2913. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2914. 0:
  2915. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2916. if(idxPeriod > 0)
  2917. {
  2918. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2919. {
  2920. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2921. }
  2922. }
  2923. }
  2924. }
  2925. }
  2926. else
  2927. {
  2928. if(maxProfile.ChargingSchedule.Duration != -1)
  2929. {
  2930. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2931. 0:
  2932. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2933. }
  2934. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2935. {
  2936. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2937. {
  2938. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2939. 0:
  2940. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2941. if(idxPeriod > 0)
  2942. {
  2943. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2944. {
  2945. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2946. }
  2947. }
  2948. }
  2949. }
  2950. }
  2951. }
  2952. /*
  2953. DEBUG_INFO("MaxProfile after align.\n");
  2954. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2955. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2956. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2957. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2958. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2959. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2960. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2961. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2962. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2963. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2964. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2965. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2966. {
  2967. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2968. {
  2969. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2970. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2971. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2972. }
  2973. }
  2974. DEBUG_INFO("------------------------------------\n");*/
  2975. }
  2976. /*
  2977. * Merge to conposite schedule
  2978. */
  2979. //DEBUG_INFO("====================================\n");
  2980. // Find each profile period quantity
  2981. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2982. {
  2983. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2984. limitMax = idx+1;
  2985. }
  2986. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2987. {
  2988. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2989. limitDef = idx+1;
  2990. }
  2991. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2992. {
  2993. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2994. limitTx = idx+1;
  2995. }
  2996. // TxProfile found, composite schedule based on it
  2997. if(txProfile.ChargingProfileId != -1)
  2998. {
  2999. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  3000. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  3001. {
  3002. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  3003. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  3004. (txProfile.ChargingSchedule.Duration > 0))
  3005. {
  3006. if(maxProfile.ChargingProfileId != -1)
  3007. {
  3008. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3009. {
  3010. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  3011. {
  3012. if((maxProfile.ChargingSchedule.Duration > 0))
  3013. {
  3014. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3015. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3016. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3017. }
  3018. else
  3019. {
  3020. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  3021. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  3022. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  3023. }
  3024. }
  3025. if(idxMaxPeriod == (limitMax-1))
  3026. {
  3027. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3028. {
  3029. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3030. {
  3031. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3032. compositePeriodIdx++;
  3033. }
  3034. else
  3035. {
  3036. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3037. }
  3038. }
  3039. }
  3040. }
  3041. }
  3042. else
  3043. {
  3044. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3045. {
  3046. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3047. compositePeriodIdx++;
  3048. }
  3049. else
  3050. {
  3051. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3052. }
  3053. }
  3054. }
  3055. if(idxTxPeriod == (limitTx-1))
  3056. {
  3057. if(defaultTxProfile.ChargingProfileId != -1)
  3058. {
  3059. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  3060. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3061. {
  3062. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3063. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3064. (defaultTxProfile.ChargingSchedule.Duration>0))
  3065. {
  3066. if(maxProfile.ChargingProfileId != -1)
  3067. {
  3068. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3069. {
  3070. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3071. {
  3072. if((maxProfile.ChargingSchedule.Duration > 0))
  3073. {
  3074. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3075. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3076. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3077. }
  3078. else
  3079. {
  3080. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3081. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3082. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3083. }
  3084. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3085. {
  3086. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3087. {
  3088. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3089. compositePeriodIdx++;
  3090. }
  3091. else
  3092. {
  3093. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3094. }
  3095. }
  3096. // Delete duplicate period
  3097. if(compositePeriodIdx > 1)
  3098. {
  3099. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3100. {
  3101. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3102. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3103. compositePeriodIdx -= 1;
  3104. }
  3105. }
  3106. }
  3107. else
  3108. {
  3109. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3110. {
  3111. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3112. compositePeriodIdx++;
  3113. }
  3114. else
  3115. {
  3116. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3117. }
  3118. break;
  3119. }
  3120. }
  3121. }
  3122. else
  3123. {
  3124. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3125. {
  3126. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3127. compositePeriodIdx++;
  3128. }
  3129. else
  3130. {
  3131. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3132. }
  3133. }
  3134. }
  3135. }
  3136. }
  3137. }
  3138. }
  3139. }
  3140. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3141. else if(defaultTxProfile.ChargingProfileId != -1)
  3142. {
  3143. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  3144. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3145. {
  3146. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3147. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3148. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3149. {
  3150. if(maxProfile.ChargingProfileId != -1)
  3151. {
  3152. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3153. {
  3154. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3155. {
  3156. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3157. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3158. if((maxProfile.ChargingSchedule.Duration > 0))
  3159. {
  3160. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3161. }
  3162. else
  3163. {
  3164. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3165. }
  3166. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3167. {
  3168. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3169. {
  3170. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3171. compositePeriodIdx++;
  3172. }
  3173. else
  3174. {
  3175. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3176. }
  3177. }
  3178. // Delete duplicate period
  3179. if(compositePeriodIdx > 1)
  3180. {
  3181. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3182. {
  3183. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3184. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3185. compositePeriodIdx -= 1;
  3186. }
  3187. }
  3188. }
  3189. else
  3190. {
  3191. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3192. {
  3193. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3194. compositePeriodIdx++;
  3195. }
  3196. else
  3197. {
  3198. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3199. }
  3200. break;
  3201. }
  3202. }
  3203. }
  3204. else
  3205. {
  3206. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3207. {
  3208. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3209. compositePeriodIdx++;
  3210. }
  3211. else
  3212. {
  3213. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3214. }
  3215. }
  3216. }
  3217. }
  3218. }
  3219. // Fill other period by MaxProfile
  3220. if(maxProfile.ChargingProfileId != -1)
  3221. {
  3222. if(compositePeriodIdx==0)
  3223. {
  3224. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  3225. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  3226. {
  3227. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3228. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3229. (maxProfile.ChargingSchedule.Duration > 0))
  3230. {
  3231. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3232. {
  3233. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3234. compositePeriodIdx++;
  3235. }
  3236. else
  3237. {
  3238. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  3239. }
  3240. }
  3241. }
  3242. }
  3243. else
  3244. {
  3245. int lastCompositePeriodIdx = compositePeriodIdx;
  3246. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3247. {
  3248. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3249. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3250. (maxProfile.ChargingSchedule.Duration > 0))
  3251. {
  3252. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  3253. {
  3254. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  3255. {
  3256. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3257. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3258. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3259. }
  3260. else
  3261. {
  3262. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3263. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3264. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3265. }
  3266. }
  3267. if(tmpPeriod.Limit != -1)
  3268. {
  3269. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3270. {
  3271. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3272. {
  3273. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3274. compositePeriodIdx++;
  3275. }
  3276. else
  3277. {
  3278. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3279. }
  3280. }
  3281. // Delete duplicate period
  3282. if(compositePeriodIdx > 1)
  3283. {
  3284. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3285. {
  3286. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3287. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3288. compositePeriodIdx -= 1;
  3289. }
  3290. }
  3291. }
  3292. }
  3293. }
  3294. }
  3295. }
  3296. compositeProfile->ChargingSchedule.Duration = durationReq;
  3297. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3298. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3299. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3300. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3301. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3302. {
  3303. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3304. {
  3305. compositeProfile->ChargingProfileId = 1;
  3306. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3307. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3308. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3309. }
  3310. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3311. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3312. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3313. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3314. }
  3315. if(line)
  3316. free(line);
  3317. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3318. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3319. }
  3320. //==========================================
  3321. // Init all share memory
  3322. //==========================================
  3323. int InitShareMemory()
  3324. {
  3325. int result = PASS;
  3326. int MeterSMId;
  3327. //creat ShmSysConfigAndInfo
  3328. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3329. {
  3330. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3331. result = FAIL;
  3332. }
  3333. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3334. {
  3335. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3336. result = FAIL;
  3337. }
  3338. else
  3339. {}
  3340. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3341. {
  3342. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3343. result = FAIL;
  3344. }
  3345. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3346. {
  3347. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3348. result = FAIL;
  3349. }
  3350. else
  3351. {}
  3352. //creat ShmPsuData
  3353. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3354. {
  3355. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3356. result = FAIL;
  3357. }
  3358. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3359. {
  3360. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3361. result = FAIL;
  3362. }
  3363. else
  3364. {}
  3365. //creat ShmOCPP16Data
  3366. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3367. {
  3368. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3369. result = FAIL;
  3370. }
  3371. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3372. {
  3373. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3374. result = FAIL;
  3375. }
  3376. else
  3377. {}
  3378. /****************************** For Initial Settings************************************************/
  3379. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3380. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3381. // allocate Configuration memory address
  3382. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3383. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3384. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3385. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3386. //offline MeterValue Interval
  3387. TempMeterValueInterval = 0;
  3388. return result;
  3389. }
  3390. int ProcessShareMemory()
  3391. {
  3392. int result = PASS;
  3393. if(InitShareMemory() == FAIL)
  3394. {
  3395. DEBUG_ERROR("InitShareMemory NG\n");
  3396. if(ShmStatusCodeData!=NULL)
  3397. {
  3398. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3399. }
  3400. result = FAIL;
  3401. }
  3402. // Model name parsing
  3403. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  3404. {
  3405. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  3406. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  3407. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  3408. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  3409. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  3410. ) // 'D' means DC
  3411. {
  3412. // DO series
  3413. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  3414. {
  3415. SystemInitial += 1;
  3416. gunTotalNumber += 1;
  3417. gunType[gun_index] = GUN_TYPE_DO;
  3418. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3419. {
  3420. case Gun_Type_Chademo:
  3421. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  3422. break;
  3423. case Gun_Type_CCS_2:
  3424. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  3425. break;
  3426. case Gun_Type_GB:
  3427. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  3428. break;
  3429. case Gun_Type_AC:
  3430. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  3431. break;
  3432. default:
  3433. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  3434. break;
  3435. }
  3436. }
  3437. }
  3438. else
  3439. {
  3440. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  3441. {
  3442. SystemInitial += 1;
  3443. gunTotalNumber += 1;
  3444. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  3445. {
  3446. case Gun_Type_Chademo:
  3447. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  3448. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  3449. break;
  3450. case Gun_Type_CCS_2:
  3451. gunType[gun_index] = GUN_TYPE_CCS;
  3452. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  3453. break;
  3454. case Gun_Type_GB:
  3455. gunType[gun_index] = GUN_TYPE_GBT;
  3456. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  3457. break;
  3458. case Gun_Type_AC:
  3459. gunType[gun_index] = GUN_TYPE_AC;
  3460. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  3461. break;
  3462. default:
  3463. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  3464. break;
  3465. }
  3466. }
  3467. }
  3468. }
  3469. else
  3470. {
  3471. DEBUG_ERROR("Model name parsing fail.\n");
  3472. result = FAIL;
  3473. }
  3474. if(result != PASS)sleep(5);
  3475. return result;
  3476. }
  3477. void checkRemoteStart(uint8_t connectorIdInt)
  3478. {
  3479. uint8_t tempIndex;
  3480. int result = PASS;
  3481. char cmdBuf[512];
  3482. //check Transaction active
  3483. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  3484. {
  3485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3486. {
  3487. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3488. }
  3489. else
  3490. {
  3491. tempIndex = connectorIdInt -1;
  3492. }
  3493. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3494. {
  3495. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3496. {
  3497. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3498. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3499. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3500. {
  3501. //Reserved
  3502. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  3503. }
  3504. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  3505. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  3506. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3507. {
  3508. //Reserved
  3509. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  3510. result = FAIL;
  3511. goto end;
  3512. }
  3513. else
  3514. {
  3515. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3516. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  3517. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  3518. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  3519. {
  3520. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  3521. result = FAIL;
  3522. goto end;
  3523. }
  3524. }//END FOR ELSE
  3525. }
  3526. }// END FOR CHAdeMO_QUANTITY
  3527. }
  3528. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  3529. {
  3530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3531. {
  3532. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3533. }
  3534. else
  3535. {
  3536. tempIndex = connectorIdInt -1;
  3537. }
  3538. for (int index = 0; index < CCS_QUANTITY; index++)
  3539. {
  3540. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3541. {
  3542. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3543. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3544. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3545. {
  3546. //Reserved
  3547. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  3548. }
  3549. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  3550. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  3551. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3552. {
  3553. //Reserved
  3554. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  3555. result = FAIL;
  3556. goto end;
  3557. }
  3558. else
  3559. {
  3560. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3561. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3562. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3563. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3564. {
  3565. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  3566. result = FAIL;
  3567. goto end;
  3568. }
  3569. }// END FOR ELSE
  3570. }
  3571. }// END FOR CCS_QUANTITY
  3572. }
  3573. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  3574. {
  3575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3576. {
  3577. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  3578. }
  3579. else
  3580. {
  3581. tempIndex = connectorIdInt -1;
  3582. }
  3583. for (int index = 0; index < GB_QUANTITY; index++)
  3584. {
  3585. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  3586. {
  3587. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3588. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3589. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3590. {
  3591. //Reserved
  3592. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  3593. }
  3594. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  3595. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  3596. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3597. {
  3598. //Reserved
  3599. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  3600. result = FAIL;
  3601. goto end;
  3602. }
  3603. else
  3604. {
  3605. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3606. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3607. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3608. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3609. {
  3610. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  3611. result = FAIL;
  3612. goto end;
  3613. }
  3614. }// END FOR ELSE
  3615. }
  3616. } // END FOR GB_QUANTITY
  3617. }
  3618. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  3619. {
  3620. tempIndex = connectorIdInt -1;
  3621. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3622. {
  3623. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  3624. {
  3625. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3626. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3627. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3628. {
  3629. //Reserved
  3630. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  3631. }
  3632. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  3633. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  3634. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3635. {
  3636. //Reserved
  3637. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  3638. result = FAIL;
  3639. goto end;
  3640. }
  3641. else
  3642. {
  3643. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3644. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3645. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3646. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3647. {
  3648. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  3649. result = FAIL;
  3650. goto end;
  3651. }
  3652. }// END FOR ELSE
  3653. }
  3654. } // END FOR GB_QUANTITY
  3655. }
  3656. else
  3657. {
  3658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  3659. {
  3660. tempIndex = 2;
  3661. }
  3662. else
  3663. {
  3664. tempIndex = connectorIdInt -1;
  3665. }
  3666. for (int index = 0; index < AC_QUANTITY; index++)
  3667. {
  3668. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  3669. {
  3670. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3671. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3672. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  3673. {
  3674. //Reserved
  3675. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  3676. }
  3677. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  3678. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  3679. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  3680. {
  3681. //Reserved
  3682. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  3683. result = FAIL;
  3684. goto end;
  3685. }
  3686. else
  3687. {
  3688. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  3689. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  3690. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  3691. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  3692. {
  3693. DEBUG_WARN("AC connector not allow start cause busy.\n");
  3694. result = FAIL;
  3695. goto end;
  3696. }
  3697. }//END FOR ELSE
  3698. }
  3699. }// END FOR AC_QUANTITY
  3700. }
  3701. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  3702. {
  3703. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  3704. {
  3705. if((access("/Storage/OCPP/TxProfile_Tmp.json", F_OK))!=-1)
  3706. {
  3707. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp.json /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  3708. system(cmdBuf);
  3709. }
  3710. }
  3711. else
  3712. {
  3713. DEBUG_WARN("Profile purpose not TxProfile.\n.");
  3714. result = FAIL;
  3715. }
  3716. }
  3717. end:
  3718. if(result == PASS)
  3719. {
  3720. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  3721. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, 0, 20);
  3722. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3723. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, 0, 20);
  3724. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  3725. }
  3726. }
  3727. void CheckSystemValue(void)
  3728. {
  3729. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3730. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3731. char filenmae[100]={0};
  3732. char str[100]={0};
  3733. int tempIndex = 0;
  3734. //===============================
  3735. // send Heartbeat
  3736. //===============================
  3737. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3738. {
  3739. //parameter for test
  3740. sendHeartbeatRequest(0);
  3741. //==============================================
  3742. // Reset Waiting Time
  3743. //==============================================
  3744. HeartBeatWithNOResponse += 1;
  3745. }
  3746. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3747. {
  3748. //==========================================
  3749. // Check remote start without connector id
  3750. //==========================================
  3751. if(ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq)
  3752. {
  3753. int connectorIdInt = -1;
  3754. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  3755. {
  3756. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  3757. {
  3758. connectorIdInt = (gun_index+1);
  3759. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  3760. checkRemoteStart(connectorIdInt);
  3761. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  3762. break;
  3763. }
  3764. }
  3765. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData))
  3766. {
  3767. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  3768. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 0;
  3769. }
  3770. }
  3771. //==========================================
  3772. // csu trigger DataTransferReq
  3773. //==========================================
  3774. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3775. {
  3776. sendDataTransferRequest(gun_index);
  3777. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3778. }
  3779. //==========================================
  3780. // CSU Trigger Authorize Request
  3781. //==========================================
  3782. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3783. {
  3784. sendAuthorizeRequest(0);
  3785. authorizeRetryTimes = authorizeRetryTimes + 1;
  3786. if(authorizeRetryTimes < 3)
  3787. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3788. }
  3789. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3790. {
  3791. authorizeRetryTimes = 0;
  3792. SetOcppConnStatus(FALSE);
  3793. server_sign = FALSE;
  3794. }
  3795. 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))
  3796. {
  3797. sendAuthorizeRequest(0);
  3798. }
  3799. //==========================================
  3800. // Charger start transaction
  3801. //==========================================
  3802. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3803. {
  3804. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3805. sendStartTransactionRequest(gun_index);
  3806. refreshStartTimer(&clientTime.StartTransaction);
  3807. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  3808. storeTempStopTransaction(gun_index);
  3809. }
  3810. //==========================================
  3811. // Charger stop transaction
  3812. //==========================================
  3813. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3814. {
  3815. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3816. sendStopTransactionRequest(gun_index);
  3817. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3818. refreshStartTimer(&clientTime.StopTransaction);
  3819. memset(&ShmOCPP16Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  3820. }
  3821. //==========================================
  3822. // Charger status report
  3823. //==========================================
  3824. //--- Check Mode Change ---//
  3825. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3826. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3827. {
  3828. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3829. {
  3830. tempIndex = ((gun_index==2) ? 1: 0);
  3831. }
  3832. else
  3833. {
  3834. tempIndex = gun_index;
  3835. }
  3836. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3837. {
  3838. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3839. {
  3840. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3841. {
  3842. // Sent unplug message for California pricing logic
  3843. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3844. {
  3845. uint8_t ts[20];
  3846. getNowDatetime(ts);
  3847. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3848. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3849. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3850. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3851. }
  3852. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3853. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3854. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3855. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3856. {
  3857. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3858. if((access(filenmae,F_OK))!=-1)
  3859. {
  3860. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3861. sprintf(str,"rm -f %s",filenmae);
  3862. system(str);
  3863. }
  3864. }
  3865. }
  3866. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3867. #if 1 // for TempStopTransaction
  3868. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3869. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3870. {
  3871. checkTempStopTransaction(gun_index);
  3872. }
  3873. #endif
  3874. }
  3875. }
  3876. }
  3877. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3878. {
  3879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3880. {
  3881. tempIndex = ((gun_index==2) ? 1: 0);
  3882. }
  3883. else
  3884. {
  3885. tempIndex = gun_index;
  3886. }
  3887. for (int index = 0; index < CCS_QUANTITY; index++)
  3888. {
  3889. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3890. {
  3891. 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]*/ )
  3892. {
  3893. // Sent unplug message for California pricing logic
  3894. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3895. {
  3896. uint8_t ts[20];
  3897. getNowDatetime(ts);
  3898. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3899. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3900. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3901. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3902. }
  3903. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3904. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3905. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3906. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3907. {
  3908. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3909. if((access(filenmae,F_OK))!=-1)
  3910. {
  3911. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3912. sprintf(str,"rm -f %s",filenmae);
  3913. system(str);
  3914. }
  3915. }
  3916. }
  3917. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3918. #if 1 // for TempStopTransaction
  3919. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3920. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3921. {
  3922. checkTempStopTransaction(gun_index);
  3923. }
  3924. #endif
  3925. }
  3926. }
  3927. }
  3928. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3929. {
  3930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3931. {
  3932. tempIndex = ((gun_index==2) ? 1: 0);
  3933. }
  3934. else
  3935. {
  3936. tempIndex = gun_index;
  3937. }
  3938. for (int index = 0; index < GB_QUANTITY; index++)
  3939. {
  3940. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3941. {
  3942. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3943. {
  3944. // Sent unplug message for California pricing logic
  3945. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3946. {
  3947. uint8_t ts[20];
  3948. getNowDatetime(ts);
  3949. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3950. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3951. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3952. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3953. }
  3954. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3955. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3956. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3957. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3958. {
  3959. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3960. if((access(filenmae,F_OK))!=-1)
  3961. {
  3962. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3963. sprintf(str,"rm -f %s",filenmae);
  3964. system(str);
  3965. }
  3966. }
  3967. }
  3968. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3969. #if 1 // for TempStopTransaction
  3970. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3971. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3972. {
  3973. checkTempStopTransaction(gun_index);
  3974. }
  3975. #endif
  3976. }
  3977. }
  3978. }
  3979. else if(gunType[gun_index] == GUN_TYPE_DO)
  3980. {
  3981. tempIndex = gun_index;
  3982. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3983. {
  3984. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3985. {
  3986. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3987. {
  3988. // Sent unplug message for California pricing logic
  3989. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3990. {
  3991. uint8_t ts[20];
  3992. getNowDatetime(ts);
  3993. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3994. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3995. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3996. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3997. }
  3998. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3999. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4000. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4001. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  4002. {
  4003. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4004. if((access(filenmae,F_OK))!=-1)
  4005. {
  4006. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4007. sprintf(str,"rm -f %s",filenmae);
  4008. system(str);
  4009. }
  4010. }
  4011. }
  4012. 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);
  4013. #if 1 // for TempStopTransaction
  4014. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  4015. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4016. {
  4017. checkTempStopTransaction(gun_index);
  4018. }
  4019. #endif
  4020. }
  4021. }
  4022. }
  4023. else
  4024. {
  4025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4026. {
  4027. tempIndex = 2;
  4028. }
  4029. else
  4030. {
  4031. tempIndex = gun_index;
  4032. }
  4033. for (int index = 0; index < AC_QUANTITY; index++)
  4034. {
  4035. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4036. {
  4037. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4038. {
  4039. // Sent unplug message for California pricing logic
  4040. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  4041. {
  4042. uint8_t ts[20];
  4043. getNowDatetime(ts);
  4044. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  4045. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  4046. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  4047. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  4048. }
  4049. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4050. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4051. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  4052. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  4053. {
  4054. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4055. if((access(filenmae,F_OK))!=-1)
  4056. {
  4057. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4058. sprintf(str,"rm -f %s",filenmae);
  4059. system(str);
  4060. }
  4061. }
  4062. }
  4063. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4064. #if 1 // for TempStopTransaction
  4065. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4066. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  4067. {
  4068. checkTempStopTransaction(gun_index);
  4069. }
  4070. #endif
  4071. }
  4072. }// END
  4073. }
  4074. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  4075. (
  4076. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  4077. )
  4078. )
  4079. {
  4080. if(SystemInitial > 0)
  4081. SystemInitial -= 1;
  4082. sendStatusNotificationRequest(gun_index);
  4083. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  4084. }
  4085. //==============================================
  4086. // CSU Trigger Smart Charging Profilw
  4087. //==============================================
  4088. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  4089. {
  4090. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  4091. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  4092. }
  4093. //==============================================
  4094. // Meter report
  4095. //==============================================
  4096. // Trigger MeterValue
  4097. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  4098. {
  4099. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  4100. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  4101. }
  4102. // ClockAlign MeterValue
  4103. 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))
  4104. {
  4105. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4106. {
  4107. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4108. {
  4109. tempIndex = ((gun_index==2) ? 1: 0);
  4110. }
  4111. else
  4112. {
  4113. tempIndex = gun_index;
  4114. }
  4115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4116. {
  4117. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4118. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4119. {
  4120. reqClockAlignMeter[gun_index] = 1;
  4121. }
  4122. }// End for CHAdeMO
  4123. }
  4124. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4125. {
  4126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4127. {
  4128. tempIndex = ((gun_index==2) ? 1: 0);
  4129. }
  4130. else
  4131. {
  4132. tempIndex = gun_index;
  4133. }
  4134. for (int index = 0; index < CCS_QUANTITY; index++)
  4135. {
  4136. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4137. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4138. {
  4139. reqClockAlignMeter[gun_index] = 1;
  4140. }
  4141. } // End for CCS
  4142. }
  4143. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4144. {
  4145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4146. {
  4147. tempIndex = ((gun_index==2) ? 1: 0);
  4148. }
  4149. else
  4150. {
  4151. tempIndex = gun_index;
  4152. }
  4153. for (int index = 0; index < GB_QUANTITY; index++)
  4154. {
  4155. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4156. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4157. {
  4158. reqClockAlignMeter[gun_index] = 1;
  4159. }
  4160. }// End for GB
  4161. }
  4162. else if(gunType[gun_index] == GUN_TYPE_DO)
  4163. {
  4164. tempIndex = gun_index;
  4165. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4166. {
  4167. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4168. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4169. {
  4170. reqClockAlignMeter[gun_index] = 1;
  4171. }
  4172. }
  4173. }
  4174. else
  4175. {
  4176. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4177. {
  4178. tempIndex = 2;
  4179. }
  4180. else
  4181. {
  4182. tempIndex = gun_index;
  4183. }
  4184. for (int index = 0; index < AC_QUANTITY; index++)
  4185. {
  4186. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4187. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4188. {
  4189. reqClockAlignMeter[gun_index] = 1;
  4190. }
  4191. }//End for AC
  4192. }
  4193. if(reqClockAlignMeter[gun_index] == 1)
  4194. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  4195. }
  4196. // Sample period MeterValue
  4197. if(((getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>5?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):5))))
  4198. {
  4199. //check Transaction active
  4200. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4201. {
  4202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4203. {
  4204. tempIndex = ((gun_index==2) ? 1: 0);
  4205. }
  4206. else
  4207. {
  4208. tempIndex = gun_index;
  4209. }
  4210. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4211. {
  4212. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4213. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4214. {
  4215. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4216. {
  4217. reqSampleMeter[gun_index] = 1;
  4218. }
  4219. }
  4220. }// End for CHAdeMO
  4221. }
  4222. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4223. {
  4224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4225. {
  4226. tempIndex = ((gun_index==2) ? 1: 0);
  4227. }
  4228. else
  4229. {
  4230. tempIndex = gun_index;
  4231. }
  4232. for (int index = 0; index < CCS_QUANTITY; index++)
  4233. {
  4234. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4235. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4236. {
  4237. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4238. {
  4239. reqSampleMeter[gun_index] = 1;
  4240. }
  4241. }
  4242. } // End for CCS
  4243. }
  4244. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4245. {
  4246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4247. {
  4248. tempIndex = ((gun_index==2) ? 1: 0);
  4249. }
  4250. else
  4251. {
  4252. tempIndex = gun_index;
  4253. }
  4254. for (int index = 0; index < GB_QUANTITY; index++)
  4255. {
  4256. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4257. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4258. {
  4259. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  4260. {
  4261. reqSampleMeter[gun_index] = 1;
  4262. }
  4263. }
  4264. }// End for GB
  4265. }
  4266. else if(gunType[gun_index] == GUN_TYPE_DO)
  4267. {
  4268. tempIndex = gun_index;
  4269. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4270. {
  4271. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4272. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4273. {
  4274. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  4275. {
  4276. reqSampleMeter[gun_index] = 1;
  4277. }
  4278. }
  4279. }
  4280. }
  4281. else
  4282. {
  4283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4284. {
  4285. tempIndex = 2;
  4286. }
  4287. else
  4288. {
  4289. tempIndex = gun_index;
  4290. }
  4291. for (int index = 0; index < AC_QUANTITY; index++)
  4292. {
  4293. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  4294. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4295. {
  4296. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  4297. {
  4298. reqSampleMeter[gun_index] = 1;
  4299. }
  4300. }
  4301. }//End for AC
  4302. }
  4303. if(reqSampleMeter[gun_index] == 1)
  4304. {
  4305. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  4306. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  4307. storeTempStopTransaction(gun_index);
  4308. }
  4309. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4310. }
  4311. //==============================================
  4312. // Check Connector reserved
  4313. //==============================================
  4314. //===============================
  4315. // Check if Reserve is expired
  4316. //===============================
  4317. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0))
  4318. {
  4319. if(isOvertNow(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate))
  4320. {
  4321. DEBUG_INFO("reserve expired.\n");
  4322. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  4323. }
  4324. }//END OF Check if Reserve is expired
  4325. //==========================================
  4326. // csu trigger FirmwareStatusNotificationReq
  4327. //==========================================
  4328. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  4329. {
  4330. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  4331. }
  4332. //==========================================
  4333. // csu trigger DiagnosticsStatusNotificationReq
  4334. //==========================================
  4335. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  4336. {
  4337. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  4338. }
  4339. //==========================================
  4340. // csu trigger CancelReservationConf
  4341. //==========================================
  4342. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  4343. {
  4344. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  4345. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  4346. }
  4347. //==========================================
  4348. // csu trigger ChangeAvailabilityConf
  4349. //==========================================
  4350. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  4351. {
  4352. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  4353. }
  4354. //==========================================
  4355. // csu trigger UnlockConnectorConf
  4356. //==========================================
  4357. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  4358. {
  4359. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  4360. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  4361. }
  4362. //==========================================
  4363. // csu trigger ReserveNowConf
  4364. //==========================================
  4365. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  4366. {
  4367. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  4368. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  4369. }
  4370. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  4371. {
  4372. sendSignCertificateRequest();
  4373. }
  4374. }
  4375. }
  4376. //==========================================
  4377. // send request routine
  4378. //==========================================
  4379. int sendAuthorizeRequest(int gun_index)
  4380. {
  4381. mtrace();
  4382. int result = FAIL;
  4383. char message[100]={0};
  4384. char guid[37];
  4385. char tempdata[65]={0};
  4386. DEBUG_INFO("sendAuthorizeRequest...\n");
  4387. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  4388. //Local Authorize
  4389. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  4390. {
  4391. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  4392. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  4393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  4394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  4395. result = PASS;
  4396. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4397. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4398. authorizeRetryTimes = 0;
  4399. return result;
  4400. }
  4401. 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))||
  4402. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  4403. {
  4404. // Query from cache
  4405. DEBUG_INFO("Authorize from cache.\n");
  4406. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4407. // Query from list
  4408. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4409. {
  4410. DEBUG_INFO("Authorize from list.\n");
  4411. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4412. }
  4413. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  4414. {
  4415. if(strcmp(idTagQuery.idTagstr,"") == 0)
  4416. {
  4417. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  4418. }
  4419. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  4420. {
  4421. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  4422. }
  4423. if(!GetOcppConnStatus())
  4424. {
  4425. DEBUG_INFO("off-line Local Authorization Fail.\n");
  4426. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4427. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4428. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  4429. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4430. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4431. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4432. authorizeRetryTimes = 0;
  4433. return result;
  4434. }
  4435. }
  4436. else
  4437. {
  4438. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4439. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4440. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4441. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4442. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4443. else
  4444. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4445. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4446. result = PASS;
  4447. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4448. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4449. authorizeRetryTimes = 0;
  4450. return result;
  4451. }
  4452. }
  4453. //initialize struct Authorize
  4454. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4455. //get data from shared memory
  4456. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4457. random_uuid(guid);
  4458. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4459. LWS_Send(message);
  4460. sprintf(tempdata, "Authorize,%d", gun_index);
  4461. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4462. {
  4463. result = PASS;
  4464. DEBUG_INFO("Authorize mapItem pass\n");
  4465. }
  4466. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4467. return result;
  4468. }
  4469. int sendBootNotificationRequest(void)
  4470. {
  4471. mtrace();
  4472. int result = FAIL;
  4473. char message[500]={0}, payload[700]={0};
  4474. char guid[37]={0};
  4475. char tempdata[65]={0};
  4476. // Fill BootNotification fields
  4477. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4478. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4479. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4480. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4481. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4482. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4483. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4484. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4485. ShmOCPP16Data->ChargeBoxId
  4486. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4487. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4488. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4489. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4490. ,ShmOCPP16Data->BootNotification.CpIccid
  4491. ,ShmOCPP16Data->BootNotification.CpImsi);
  4492. random_uuid(guid);
  4493. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4494. LWS_Send(message);
  4495. sprintf(tempdata, "BootNotification,0");
  4496. 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*/)
  4497. {
  4498. result = PASS;
  4499. }
  4500. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4501. strcpy(queuedata,message);
  4502. return result;
  4503. }
  4504. int sendDataTransferRequest(int gun_index)
  4505. {
  4506. mtrace();
  4507. char message[1000]={0};
  4508. char guid[37]={0};
  4509. char tempdata[65]={0};
  4510. int result = FAIL;
  4511. random_uuid(guid);
  4512. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4513. MESSAGE_TYPE_CALL,
  4514. guid,
  4515. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4516. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4517. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4518. LWS_Send(message);
  4519. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4520. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4521. {
  4522. result = PASS;
  4523. DEBUG_INFO("DataTransfer mapItem pass\n");
  4524. }
  4525. return result;
  4526. }
  4527. int sendDiagnosticsStatusNotificationRequest(char *status)
  4528. {
  4529. mtrace();
  4530. int result = FAIL;
  4531. char message[110]={0};
  4532. char guid[37]={0};
  4533. char tempdata[65]={0};
  4534. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4535. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4536. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4537. random_uuid(guid);
  4538. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4539. LWS_SendNow(message);
  4540. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4541. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4542. {
  4543. result = PASS;
  4544. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4545. }
  4546. //#ifdef SystemLogMessage
  4547. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4548. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4549. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4550. //#endif
  4551. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4552. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4553. //record status
  4554. if(strcmp(status,"Idle")==0)
  4555. {
  4556. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4557. }
  4558. else if(strcmp(status,"Uploaded")==0)
  4559. {
  4560. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4561. }
  4562. else if(strcmp(status,"UploadFailed")==0)
  4563. {
  4564. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4565. }
  4566. else if(strcmp(status,"Uploading")==0)
  4567. {
  4568. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4569. }
  4570. return result;
  4571. }
  4572. int sendFirmwareStatusNotificationRequest(char *status)
  4573. {
  4574. mtrace();
  4575. int result = FAIL;
  4576. char message[110]={0};
  4577. char guid[37]={0};
  4578. char tempdata[65]={0};
  4579. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4580. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4581. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4582. random_uuid(guid);
  4583. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4584. LWS_SendNow(message);
  4585. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4586. 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*/)
  4587. {
  4588. result = PASS;
  4589. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4590. }
  4591. //#ifdef SystemLogMessage
  4592. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4593. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4594. //#endif
  4595. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4596. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4597. //record status
  4598. if(strcmp(status,"Downloaded")==0)
  4599. {
  4600. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4601. }
  4602. else if(strcmp(status,"DownloadFailed")==0)
  4603. {
  4604. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4605. }
  4606. else if(strcmp(status,"Downloading")==0)
  4607. {
  4608. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4609. }
  4610. else if(strcmp(status,"Idle")==0)
  4611. {
  4612. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4613. }
  4614. else if(strcmp(status,"InstallationFailed")==0)
  4615. {
  4616. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4617. }
  4618. else if(strcmp(status,"Installing")==0)
  4619. {
  4620. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4621. }
  4622. else if(strcmp(status,"Installed")==0)
  4623. {
  4624. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4625. }
  4626. return result;
  4627. }
  4628. int sendHeartbeatRequest(int gun_index)
  4629. {
  4630. mtrace();
  4631. int result = FAIL;
  4632. char message[80]={0};
  4633. char guid[37]={0};
  4634. char tempdata[65]={0};
  4635. random_uuid(guid);
  4636. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4637. , MESSAGE_TYPE_CALL
  4638. , guid );
  4639. LWS_Send(message);
  4640. sprintf(tempdata, "Heartbeat,%d", 0);
  4641. 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*/)
  4642. {
  4643. result = PASS;
  4644. }
  4645. return result;
  4646. }
  4647. int sendStartTransactionRequest(int gun_index)
  4648. {
  4649. mtrace();
  4650. int result = FAIL;
  4651. char message[250]={0};
  4652. char guid[37]={0};
  4653. struct timeval tmnow;
  4654. struct tm *tm;
  4655. char buf[28];//, usec_buf[6];
  4656. char tempdata[65]={0};
  4657. int tempIndex = 0;
  4658. DEBUG_INFO("sendStartTransactionRequest...\n");
  4659. gettimeofday(&tmnow, NULL);
  4660. time_t t;
  4661. t = time(NULL);
  4662. /*UTC time and date*/
  4663. tm = gmtime(&t);
  4664. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4665. #if 0 // remove temporally
  4666. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4667. strcat(buf,".");
  4668. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4669. strcat(buf,usec_buf);
  4670. #endif
  4671. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4672. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4673. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4674. // clear StartTransaction Response
  4675. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4676. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4677. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4678. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4679. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  4680. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4681. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4682. {
  4683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4684. {
  4685. tempIndex = ((gun_index==2) ? 1: 0);
  4686. }
  4687. else
  4688. {
  4689. tempIndex = gun_index;
  4690. }
  4691. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4692. {
  4693. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4694. {
  4695. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4696. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4697. }
  4698. }
  4699. }
  4700. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4701. {
  4702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4703. {
  4704. tempIndex = ((gun_index==2) ? 1: 0);
  4705. }
  4706. else
  4707. {
  4708. tempIndex = gun_index;
  4709. }
  4710. for (int index = 0; index < CCS_QUANTITY; index++)
  4711. {
  4712. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4713. {
  4714. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4715. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4716. }
  4717. }
  4718. }
  4719. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4720. {
  4721. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4722. {
  4723. tempIndex = ((gun_index==2) ? 1: 0);
  4724. }
  4725. else
  4726. {
  4727. tempIndex = gun_index;
  4728. }
  4729. for (int index = 0; index < GB_QUANTITY; index++)
  4730. {
  4731. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4732. {
  4733. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4734. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4735. }
  4736. }
  4737. }
  4738. else if(gunType[gun_index] == GUN_TYPE_DO)
  4739. {
  4740. tempIndex = gun_index;
  4741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4742. {
  4743. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4744. {
  4745. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4746. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4747. }
  4748. }
  4749. }
  4750. else
  4751. {
  4752. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4753. {
  4754. tempIndex = 2;
  4755. }
  4756. else
  4757. {
  4758. tempIndex = gun_index;
  4759. }
  4760. for (int index = 0; index < AC_QUANTITY; index++)
  4761. {
  4762. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4763. {
  4764. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4765. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4766. }
  4767. }
  4768. }
  4769. random_uuid(guid);
  4770. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4771. {
  4772. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4773. , gun_index +1
  4774. , MESSAGE_TYPE_CALL
  4775. , guid
  4776. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4777. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4778. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4779. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4780. }
  4781. else
  4782. {
  4783. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4784. , gun_index +1
  4785. , MESSAGE_TYPE_CALL
  4786. , guid
  4787. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4788. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4789. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4790. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4791. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4792. }
  4793. #if 1
  4794. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4795. 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*/)
  4796. {
  4797. result = PASS;
  4798. }
  4799. #endif
  4800. strcpy(queuedata, message);
  4801. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4802. OCPP_insert_transaction_msg(YES, queuedata);
  4803. return result;
  4804. }
  4805. int sendStatusNotificationRequest(int gun_index)
  4806. {
  4807. mtrace();
  4808. int result = FAIL;
  4809. char message[600]={0};
  4810. char guid[37];
  4811. int currentStatus = 0;
  4812. struct timeval tmnow;
  4813. struct tm *tm;
  4814. char buf[28];//, usec_buf[6];
  4815. char tempdata[65]={0};
  4816. int tempIndex = 0;
  4817. uint8_t isStateChanged = TRUE;
  4818. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4819. gettimeofday(&tmnow, NULL);
  4820. time_t t;
  4821. t = time(NULL);
  4822. /*UTC time and date*/
  4823. tm = gmtime(&t);
  4824. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4825. #if 0 // remove temporally
  4826. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4827. strcat(buf,".");
  4828. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4829. strcat(buf,usec_buf);
  4830. #endif
  4831. //printf("%s",buf);
  4832. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4833. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4834. // it's option
  4835. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4836. /*
  4837. enum _SYSTEM_STATUS
  4838. {
  4839. S_BOOTING = 0,
  4840. S_IDLE, = 1
  4841. S_AUTHORIZING, =2
  4842. S_REASSIGN_CHECK, =3
  4843. S_REASSIGN, =4
  4844. S_PRECHARGE, =5
  4845. S_PREPARING_FOR_EV, =6
  4846. S_PREPARING_FOR_EVSE, =7
  4847. S_CHARGING, =8
  4848. S_TERMINATING, =9
  4849. S_COMPLETE, =10
  4850. S_ALARM, =11
  4851. S_FAULT =12
  4852. }
  4853. */
  4854. //check Transaction active
  4855. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4856. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4857. {
  4858. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4859. {
  4860. tempIndex = ((gun_index==2) ? 1: 0);
  4861. }
  4862. else
  4863. {
  4864. tempIndex = gun_index;
  4865. }
  4866. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4867. {
  4868. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4869. {
  4870. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4871. {
  4872. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4873. {
  4874. currentStatus = Preparing; //OCPP Status: Preparing
  4875. }
  4876. else
  4877. {
  4878. currentStatus = Available; //OCPP Status: Available
  4879. }
  4880. }
  4881. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4882. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4883. ) //S_PRECHARGE
  4884. {
  4885. currentStatus = Preparing; //OCPP Status: Preparing
  4886. }
  4887. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4888. {
  4889. currentStatus = Charging; //OCPP Status: Charging
  4890. }
  4891. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4892. {
  4893. currentStatus = Finishing; //OCPP Status: Finishing
  4894. }
  4895. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4896. {
  4897. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4898. }
  4899. 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
  4900. {
  4901. currentStatus = Unavailable; //OCPP Status: Unavailable
  4902. }
  4903. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4904. {
  4905. currentStatus = Faulted; //OCPP Status: Faulted
  4906. }
  4907. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4908. {
  4909. currentStatus = Reserved; //OCPP Status: Reserved
  4910. }
  4911. } //end of the same index
  4912. }//end of for CHAdeMO_QUANTITY
  4913. }
  4914. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4915. {
  4916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4917. {
  4918. tempIndex = ((gun_index==2) ? 1: 0);
  4919. }
  4920. else
  4921. {
  4922. tempIndex = gun_index;
  4923. }
  4924. for (int index = 0; index < CCS_QUANTITY; index++)
  4925. {
  4926. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4927. {
  4928. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4929. {
  4930. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4931. {
  4932. currentStatus = Preparing; //OCPP Status: Preparing
  4933. }
  4934. else
  4935. {
  4936. currentStatus = Available; //OCPP Status: Available
  4937. }
  4938. }
  4939. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4940. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4941. ) //S_PRECHARGE
  4942. {
  4943. currentStatus = Preparing; //OCPP Status: Preparing
  4944. }
  4945. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4946. {
  4947. currentStatus = Charging; //OCPP Status: Charging
  4948. }
  4949. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4950. {
  4951. currentStatus = Finishing; //OCPP Status: Finishing
  4952. }
  4953. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4954. {
  4955. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4956. }
  4957. 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
  4958. {
  4959. currentStatus = Unavailable; //OCPP Status : Unavailable
  4960. }
  4961. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4962. {
  4963. currentStatus = Faulted; //OCPP Status: Faulted
  4964. }
  4965. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4966. {
  4967. currentStatus = Reserved; //OCPP Status: Reserved
  4968. }
  4969. } //end of the same index
  4970. } // end of for CCS_QUANTITY
  4971. }
  4972. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4973. {
  4974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4975. {
  4976. tempIndex = ((gun_index==2) ? 1: 0);
  4977. }
  4978. else
  4979. {
  4980. tempIndex = gun_index;
  4981. }
  4982. for (int index = 0; index < GB_QUANTITY; index++)
  4983. {
  4984. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4985. {
  4986. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4987. {
  4988. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4989. {
  4990. currentStatus = Preparing; //OCPP Status: Preparing
  4991. }
  4992. else
  4993. {
  4994. currentStatus = Available; //OCPP Status: Available
  4995. }
  4996. }
  4997. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4998. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4999. ) //S_PRECHARGE
  5000. {
  5001. currentStatus = Preparing; //OCPP Status: Preparing
  5002. }
  5003. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5004. {
  5005. currentStatus = Charging; //OCPP Status: Charging
  5006. }
  5007. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5008. {
  5009. currentStatus = Finishing; //OCPP Status: Finishing
  5010. }
  5011. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5012. {
  5013. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5014. }
  5015. 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
  5016. {
  5017. currentStatus = Unavailable; //OCPP Status: Unavailable
  5018. }
  5019. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  5020. {
  5021. currentStatus = Faulted; //OCPP Status: Faulted
  5022. }
  5023. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5024. {
  5025. currentStatus = Reserved; //OCPP Status: Reserved
  5026. }
  5027. } //end of the same index
  5028. } // end of for GB_QUANTITY
  5029. }
  5030. else if(gunType[gun_index] == GUN_TYPE_DO)
  5031. {
  5032. tempIndex = gun_index;
  5033. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5034. {
  5035. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5036. {
  5037. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  5038. {
  5039. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  5040. {
  5041. currentStatus = Preparing; //OCPP Status: Preparing
  5042. }
  5043. else
  5044. {
  5045. currentStatus = Available; //OCPP Status: Available
  5046. }
  5047. }
  5048. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  5049. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  5050. ) //S_PRECHARGE
  5051. {
  5052. currentStatus = Preparing; //OCPP Status: Preparing
  5053. }
  5054. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  5055. {
  5056. currentStatus = Charging; //OCPP Status: Charging
  5057. }
  5058. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  5059. {
  5060. currentStatus = Finishing; //OCPP Status: Finishing
  5061. }
  5062. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5063. {
  5064. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5065. }
  5066. 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
  5067. {
  5068. currentStatus = Unavailable; //OCPP Status: Unavailable
  5069. }
  5070. 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
  5071. {
  5072. currentStatus = Faulted; //OCPP Status: Faulted
  5073. }
  5074. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5075. {
  5076. currentStatus = Reserved; //OCPP Status: Reserved
  5077. }
  5078. } //end of the same index
  5079. }
  5080. }
  5081. else
  5082. {
  5083. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5084. {
  5085. tempIndex = 2;
  5086. }
  5087. else
  5088. {
  5089. tempIndex = gun_index;
  5090. }
  5091. for (int index = 0; index < AC_QUANTITY; index++)
  5092. {
  5093. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5094. {
  5095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  5096. {
  5097. 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))
  5098. {
  5099. currentStatus = Preparing; //OCPP Status: Preparing
  5100. }
  5101. else
  5102. {
  5103. currentStatus = Available; //OCPP Status: Available
  5104. }
  5105. }
  5106. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  5107. {
  5108. currentStatus = Preparing; //OCPP Status: Preparing
  5109. }
  5110. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  5111. {
  5112. currentStatus = Charging; //OCPP Status: Charging
  5113. }
  5114. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  5115. {
  5116. currentStatus = Finishing; //OCPP Status: Finishing
  5117. }
  5118. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  5119. {
  5120. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  5121. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  5122. else
  5123. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  5124. }
  5125. 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
  5126. {
  5127. currentStatus = Unavailable; //OCPP Status: Unavailable
  5128. }
  5129. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  5130. {
  5131. currentStatus = Faulted; //OCPP Status: Faulted
  5132. }
  5133. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  5134. {
  5135. currentStatus = Reserved; //OCPP Status: Reserved
  5136. }
  5137. }//end of the same index
  5138. }//end of for AC_QUANTITY
  5139. }
  5140. //it's option
  5141. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  5142. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  5143. {
  5144. isStateChanged = FALSE;
  5145. }
  5146. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5147. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  5148. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5149. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  5150. random_uuid(guid);
  5151. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  5152. , MESSAGE_TYPE_CALL
  5153. , guid
  5154. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  5155. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  5156. , ShmOCPP16Data->StatusNotification[gun_index].Info
  5157. , ShmOCPP16Data->StatusNotification[gun_index].Status
  5158. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  5159. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  5160. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  5161. if((server_sign == TRUE) && isStateChanged)
  5162. {
  5163. LWS_Send(message);
  5164. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  5165. 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*/)
  5166. {
  5167. //DEBUG_ERROR("statusNotification mapitem pass");
  5168. result = PASS;
  5169. }
  5170. }
  5171. else
  5172. {
  5173. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  5174. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  5175. result = PASS;
  5176. }
  5177. return result;
  5178. }
  5179. int sendStopTransactionRequest(int gun_index)
  5180. {
  5181. mtrace();
  5182. int result = FAIL;
  5183. //char message[1500]={0};
  5184. char guid[37]={0};
  5185. char tempdata[65]={0};
  5186. int tempIndex = 0;
  5187. char TempStopTransaction[256];
  5188. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  5189. //int idx_sample=0;
  5190. DEBUG_INFO("sendStopTransactionRequest \n");
  5191. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5192. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  5193. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  5194. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5195. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5196. {
  5197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5198. {
  5199. tempIndex = ((gun_index==2) ? 1: 0);
  5200. }
  5201. else
  5202. {
  5203. tempIndex = gun_index;
  5204. }
  5205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5206. {
  5207. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5208. {
  5209. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  5210. }
  5211. }// END OF CHAdeMO_QUANTITY
  5212. }
  5213. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5214. {
  5215. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5216. {
  5217. tempIndex = ((gun_index==2) ? 1: 0);
  5218. }
  5219. else
  5220. {
  5221. tempIndex = gun_index;
  5222. }
  5223. for (int index = 0; index < CCS_QUANTITY; index++)
  5224. {
  5225. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5226. {
  5227. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  5228. }
  5229. }// END OF CCS_QUANTITY
  5230. }
  5231. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5232. {
  5233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5234. {
  5235. tempIndex = ((gun_index==2) ? 1: 0);
  5236. }
  5237. else
  5238. {
  5239. tempIndex = gun_index;
  5240. }
  5241. for (int index = 0; index < GB_QUANTITY; index++)
  5242. {
  5243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5244. {
  5245. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  5246. }
  5247. }// END OF GB_QUANTITY
  5248. }
  5249. else if(gunType[gun_index] == GUN_TYPE_DO)
  5250. {
  5251. tempIndex = gun_index;
  5252. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5253. {
  5254. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5255. {
  5256. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  5257. }
  5258. }// END OF GB_QUANTITY
  5259. }
  5260. else
  5261. {
  5262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5263. {
  5264. tempIndex = 2;
  5265. }
  5266. else
  5267. {
  5268. tempIndex = gun_index;
  5269. }
  5270. for (int index = 0; index < AC_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5273. {
  5274. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  5275. }
  5276. }// END OF AC_QUANTITY
  5277. }
  5278. //====================================== Stop Transaction Time =====================================================
  5279. struct timeval tmnow;
  5280. struct tm *tm;
  5281. char buf[28];//, usec_buf[6];
  5282. gettimeofday(&tmnow, NULL);
  5283. time_t t;
  5284. t = time(NULL);
  5285. /*UTC time and date*/
  5286. tm = gmtime(&t);
  5287. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  5289. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  5290. random_uuid(guid);
  5291. /***********************************transactionData******************************************************/
  5292. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  5293. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  5294. //=================================
  5295. // Transaction_Begin
  5296. //=================================
  5297. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5298. {
  5299. //============================================ Energy.Active.Import.Interval ================================
  5300. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  5301. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  5303. 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*/]);
  5304. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5305. 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))
  5306. {
  5307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  5308. }
  5309. else
  5310. {
  5311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  5312. }
  5313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  5314. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5315. }
  5316. //=================================
  5317. // Transaction_End
  5318. //=================================
  5319. // ================================= Current.Import L1 ===============================================
  5320. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5321. {
  5322. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  5323. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5324. {
  5325. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5326. {
  5327. tempIndex = ((gun_index==2) ? 1: 0);
  5328. }
  5329. else
  5330. {
  5331. tempIndex = gun_index;
  5332. }
  5333. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5334. {
  5335. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5336. {
  5337. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5338. }
  5339. }// End of for CHAdeMO_QUANTITY
  5340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5341. }
  5342. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5343. {
  5344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5345. {
  5346. tempIndex = ((gun_index==2) ? 1: 0);
  5347. }
  5348. else
  5349. {
  5350. tempIndex = gun_index;
  5351. }
  5352. for (int index = 0; index < CCS_QUANTITY; index++)
  5353. {
  5354. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5355. {
  5356. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5357. }
  5358. }// End of for CCS_QUANTITY
  5359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5360. }
  5361. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5362. {
  5363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5364. {
  5365. tempIndex = ((gun_index==2) ? 1: 0);
  5366. }
  5367. else
  5368. {
  5369. tempIndex = gun_index;
  5370. }
  5371. for (int index = 0; index < GB_QUANTITY; index++)
  5372. {
  5373. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5374. {
  5375. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5376. }
  5377. }// End of for GB_QUANTITY
  5378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5379. }
  5380. else if(gunType[gun_index] == GUN_TYPE_DO)
  5381. {
  5382. tempIndex = gun_index;
  5383. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5384. {
  5385. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5386. {
  5387. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  5388. }
  5389. }
  5390. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  5391. }
  5392. else
  5393. {
  5394. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5395. {
  5396. tempIndex = 2;
  5397. }
  5398. else
  5399. {
  5400. tempIndex = gun_index;
  5401. }
  5402. for (int index = 0; index < AC_QUANTITY; index++)
  5403. {
  5404. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5405. {
  5406. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  5407. }
  5408. }// End of for AC_QUANTITY
  5409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  5410. }
  5411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  5413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  5414. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  5415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5416. }
  5417. // ================================= Energy.Active.Import.Interval ==============================================
  5418. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  5419. {
  5420. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5421. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5422. {
  5423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5424. {
  5425. tempIndex = ((gun_index==2) ? 1: 0);
  5426. }
  5427. else
  5428. {
  5429. tempIndex = gun_index;
  5430. }
  5431. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5432. {
  5433. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5434. {
  5435. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5436. }
  5437. }// END OF CHAdeMO_QUANTITY
  5438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5439. }
  5440. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5441. {
  5442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5443. {
  5444. tempIndex = ((gun_index==2) ? 1: 0);
  5445. }
  5446. else
  5447. {
  5448. tempIndex = gun_index;
  5449. }
  5450. for (int index = 0; index < CCS_QUANTITY; index++)
  5451. {
  5452. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5453. {
  5454. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5455. }
  5456. }// END OF CCS_QUANTITY
  5457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5458. }
  5459. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5460. {
  5461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5462. {
  5463. tempIndex = ((gun_index==2) ? 1: 0);
  5464. }
  5465. else
  5466. {
  5467. tempIndex = gun_index;
  5468. }
  5469. for (int index = 0; index < GB_QUANTITY; index++)
  5470. {
  5471. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5472. {
  5473. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5474. }
  5475. }// END OF GB_QUANTITY
  5476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5477. }
  5478. else if(gunType[gun_index] == GUN_TYPE_DO)
  5479. {
  5480. tempIndex = gun_index;
  5481. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5482. {
  5483. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5484. {
  5485. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5486. }
  5487. }
  5488. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5489. }
  5490. else
  5491. {
  5492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5493. {
  5494. tempIndex = 2;
  5495. }
  5496. else
  5497. {
  5498. tempIndex = gun_index;
  5499. }
  5500. for (int index = 0; index < AC_QUANTITY; index++)
  5501. {
  5502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5503. {
  5504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5505. }
  5506. }// END OF AC_QUANTITY
  5507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5508. }
  5509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5512. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5514. }
  5515. //=================================== Power.Active.Import ==================================================
  5516. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5517. {
  5518. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5519. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5520. {
  5521. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5522. {
  5523. tempIndex = ((gun_index==2) ? 1: 0);
  5524. }
  5525. else
  5526. {
  5527. tempIndex = gun_index;
  5528. }
  5529. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5530. {
  5531. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5532. {
  5533. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5534. }
  5535. } // End for CHAdeMO_QUANTITY
  5536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5537. }
  5538. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5539. {
  5540. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5541. {
  5542. tempIndex = ((gun_index==2) ? 1: 0);
  5543. }
  5544. else
  5545. {
  5546. tempIndex = gun_index;
  5547. }
  5548. for (int index = 0; index < CCS_QUANTITY; index++)
  5549. {
  5550. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5551. {
  5552. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5553. }
  5554. } // END for CCS_QUANTITY
  5555. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5556. }
  5557. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5558. {
  5559. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5560. {
  5561. tempIndex = ((gun_index==2) ? 1: 0);
  5562. }
  5563. else
  5564. {
  5565. tempIndex = gun_index;
  5566. }
  5567. for (int index = 0; index < GB_QUANTITY; index++)
  5568. {
  5569. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5570. {
  5571. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5572. }
  5573. }// END for GB_QUANTITY
  5574. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5575. }
  5576. else if(gunType[gun_index] == GUN_TYPE_DO)
  5577. {
  5578. tempIndex = gun_index;
  5579. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5580. {
  5581. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5582. {
  5583. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5584. }
  5585. }
  5586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5587. }
  5588. else
  5589. {
  5590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5591. {
  5592. tempIndex = 2;
  5593. }
  5594. else
  5595. {
  5596. tempIndex = gun_index;
  5597. }
  5598. for (int index = 0; index < AC_QUANTITY; index++)
  5599. {
  5600. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5601. {
  5602. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5603. }
  5604. } // END for AC_QUANTITY
  5605. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5606. }
  5607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5612. }
  5613. //============================ Voltage L1 ====================================
  5614. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5615. {
  5616. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5617. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5618. {
  5619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5620. {
  5621. tempIndex = ((gun_index==2) ? 1: 0);
  5622. }
  5623. else
  5624. {
  5625. tempIndex = gun_index;
  5626. }
  5627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5628. {
  5629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5630. {
  5631. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5632. }
  5633. } // END OF FOR CHAdeMO_QUANTITY
  5634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5635. }
  5636. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5637. {
  5638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5639. {
  5640. tempIndex = ((gun_index==2) ? 1: 0);
  5641. }
  5642. else
  5643. {
  5644. tempIndex = gun_index;
  5645. }
  5646. for (int index = 0; index < CCS_QUANTITY; index++)
  5647. {
  5648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5649. {
  5650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5651. }
  5652. } // END OF FOR CCS_QUANTITY
  5653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5654. }
  5655. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5656. {
  5657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5658. {
  5659. tempIndex = ((gun_index==2) ? 1: 0);
  5660. }
  5661. else
  5662. {
  5663. tempIndex = gun_index;
  5664. }
  5665. for (int index = 0; index < GB_QUANTITY; index++)
  5666. {
  5667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5668. {
  5669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5670. }
  5671. } // END OF FOR GB_QUANTITY
  5672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5673. }
  5674. else if(gunType[gun_index] == GUN_TYPE_DO)
  5675. {
  5676. tempIndex = gun_index;
  5677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5678. {
  5679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5680. {
  5681. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5682. }
  5683. }
  5684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5685. }
  5686. else
  5687. {
  5688. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5689. {
  5690. tempIndex = 2;
  5691. }
  5692. else
  5693. {
  5694. tempIndex = gun_index;
  5695. }
  5696. for (int index = 0; index < AC_QUANTITY; index++)
  5697. {
  5698. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5699. {
  5700. 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
  5701. }
  5702. } // END OF FOR AC_QUANTITY
  5703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5704. }
  5705. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5707. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5709. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5710. }
  5711. //====================== End SoC ================================
  5712. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5713. {
  5714. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5715. 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))
  5716. {
  5717. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5718. {
  5719. tempIndex = ((gun_index==2) ? 1: 0);
  5720. }
  5721. else
  5722. {
  5723. tempIndex = gun_index;
  5724. }
  5725. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5726. {
  5727. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5728. {
  5729. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5730. {
  5731. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5732. }
  5733. }
  5734. }
  5735. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5736. {
  5737. for (int index = 0; index < CCS_QUANTITY; index++)
  5738. {
  5739. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5740. {
  5741. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5742. }
  5743. }
  5744. }
  5745. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5746. {
  5747. for (int index = 0; index < GB_QUANTITY; index++)
  5748. {
  5749. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5750. {
  5751. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5752. }
  5753. }
  5754. }
  5755. else if(gunType[gun_index] == GUN_TYPE_DO)
  5756. {
  5757. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5758. {
  5759. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5760. {
  5761. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5762. }
  5763. }
  5764. }
  5765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5766. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5769. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5771. } // END FOR DC CASE
  5772. }
  5773. // ================================= Current.Import L2 ===============================================
  5774. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5775. {
  5776. // AC 3 phse L2 current
  5777. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5778. {
  5779. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5780. {
  5781. tempIndex = 2;
  5782. }
  5783. else
  5784. {
  5785. tempIndex = gun_index;
  5786. }
  5787. for (int index = 0; index < AC_QUANTITY; index++)
  5788. {
  5789. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5790. {
  5791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5792. }
  5793. }// End of for AC_QUANTITY
  5794. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5795. }
  5796. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5801. }
  5802. // ================================= Current.Import L3 ===============================================
  5803. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5804. {
  5805. // AC 3 phse L3 current
  5806. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5807. {
  5808. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5809. {
  5810. tempIndex = 2;
  5811. }
  5812. else
  5813. {
  5814. tempIndex = gun_index;
  5815. }
  5816. for (int index = 0; index < AC_QUANTITY; index++)
  5817. {
  5818. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5819. {
  5820. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5821. }
  5822. }// End of for AC_QUANTITY
  5823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5824. }
  5825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5830. }
  5831. //============================ Voltage L2 ====================================
  5832. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5833. {
  5834. // AC 3 phse L2 voltage
  5835. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5836. {
  5837. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5838. {
  5839. tempIndex = 2;
  5840. }
  5841. else
  5842. {
  5843. tempIndex = gun_index;
  5844. }
  5845. for (int index = 0; index < AC_QUANTITY; index++)
  5846. {
  5847. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5848. {
  5849. 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
  5850. }
  5851. } // END OF FOR AC_QUANTITY
  5852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5853. }
  5854. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5857. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5859. }
  5860. //============================ Voltage L3 ====================================
  5861. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5862. {
  5863. // AC 3 phse L3 voltage
  5864. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5865. {
  5866. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5867. {
  5868. tempIndex = 2;
  5869. }
  5870. else
  5871. {
  5872. tempIndex = gun_index;
  5873. }
  5874. for (int index = 0; index < AC_QUANTITY; index++)
  5875. {
  5876. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5877. {
  5878. 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
  5879. }
  5880. } // END OF FOR AC_QUANTITY
  5881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5882. }
  5883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5886. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5887. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5888. }
  5889. //====================== Start SoC ================================
  5890. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5891. {
  5892. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5893. 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))
  5894. {
  5895. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5896. {
  5897. tempIndex = ((gun_index==2) ? 1: 0);
  5898. }
  5899. else
  5900. {
  5901. tempIndex = gun_index;
  5902. }
  5903. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5904. {
  5905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5906. {
  5907. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5908. {
  5909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5910. }
  5911. }
  5912. }
  5913. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5914. {
  5915. for (int index = 0; index < CCS_QUANTITY; index++)
  5916. {
  5917. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5918. {
  5919. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5920. }
  5921. }
  5922. }
  5923. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5924. {
  5925. for (int index = 0; index < GB_QUANTITY; index++)
  5926. {
  5927. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5928. {
  5929. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5930. }
  5931. }
  5932. }
  5933. else if(gunType[gun_index] == GUN_TYPE_DO)
  5934. {
  5935. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5936. {
  5937. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5938. {
  5939. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5940. }
  5941. }
  5942. }
  5943. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5944. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5945. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5946. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5949. } // END FOR DC CASE
  5950. }
  5951. //================================================ Message create ====================================================
  5952. json_object *StopTransaction = json_object_new_object();
  5953. json_object *transactionDatas = json_object_new_array();
  5954. json_object *sampledValues = json_object_new_array();
  5955. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5956. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5957. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5958. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5959. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5960. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5961. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5962. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5963. {
  5964. json_object *transactionData = json_object_new_object();
  5965. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5966. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5967. {
  5968. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5969. {
  5970. json_object *sampledValue = json_object_new_object();
  5971. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5972. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5973. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5974. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5975. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5976. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5977. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5978. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5979. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5980. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5981. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5982. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5983. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5984. json_object_array_add(sampledValues, sampledValue);
  5985. }
  5986. }
  5987. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5988. json_object_array_add(transactionDatas, transactionData);
  5989. }
  5990. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5991. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5992. ,MESSAGE_TYPE_CALL
  5993. ,guid
  5994. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5995. json_object_put(StopTransaction);
  5996. #if 1 // for TempStopTransaction
  5997. //Delete TempStopTransaction
  5998. if((access(TempStopTransaction,F_OK))!=-1)
  5999. {
  6000. remove(TempStopTransaction); // remove file "TempStopTransaction"
  6001. }
  6002. #endif
  6003. #if 1
  6004. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  6005. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  6006. {
  6007. result = PASS;
  6008. //DEBUG_INFO("StopTransaction mapitem pass\n");
  6009. }
  6010. #endif
  6011. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6012. OCPP_insert_transaction_msg(NO, queuedata);
  6013. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  6014. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  6015. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  6016. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  6017. {
  6018. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  6019. }
  6020. //for test
  6021. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  6022. return result;
  6023. }
  6024. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  6025. {
  6026. mtrace();
  6027. int result = FAIL;
  6028. char guid[37]={0};
  6029. char tempdata[65]={0};
  6030. int tempIndex = 0;
  6031. DEBUG_INFO("sendMeterValuesRequest ...\n");
  6032. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6033. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  6034. //set value
  6035. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  6036. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (cpinitateMsg.bits[gun_index].isOnCharging?
  6037. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  6038. -1);
  6039. random_uuid(guid);
  6040. //UTC Date time
  6041. struct timeval tmnow;
  6042. struct tm *tm;
  6043. char buf[28];//, usec_buf[6];
  6044. gettimeofday(&tmnow, NULL);
  6045. time_t t;
  6046. t = time(NULL);
  6047. /*UTC time and date*/
  6048. tm = gmtime(&t);
  6049. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  6051. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6052. //********************************(1)Current.Import L1************************************************/
  6053. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6054. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6055. (dataType == ReadingContext_Trigger))
  6056. {
  6057. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6058. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6059. {
  6060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6061. {
  6062. tempIndex = ((gun_index==2) ? 1: 0);
  6063. }
  6064. else
  6065. {
  6066. tempIndex = gun_index;
  6067. }
  6068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6069. {
  6070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6071. {
  6072. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  6073. }
  6074. }
  6075. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6076. }
  6077. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6078. {
  6079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6080. {
  6081. tempIndex = ((gun_index==2) ? 1: 0);
  6082. }
  6083. else
  6084. {
  6085. tempIndex = gun_index;
  6086. }
  6087. for (int index = 0; index < CCS_QUANTITY; index++)
  6088. {
  6089. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6090. {
  6091. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  6092. }
  6093. }
  6094. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6095. }
  6096. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6097. {
  6098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6099. {
  6100. tempIndex = ((gun_index==2) ? 1: 0);
  6101. }
  6102. else
  6103. {
  6104. tempIndex = gun_index;
  6105. }
  6106. for (int index = 0; index < GB_QUANTITY; index++)
  6107. {
  6108. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6109. {
  6110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  6111. }
  6112. }
  6113. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6114. }
  6115. else if(gunType[gun_index] == GUN_TYPE_DO)
  6116. {
  6117. tempIndex = gun_index;
  6118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6119. {
  6120. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6121. {
  6122. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  6123. }
  6124. }
  6125. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  6126. }
  6127. else
  6128. {
  6129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6130. {
  6131. tempIndex = 2;
  6132. }
  6133. else
  6134. {
  6135. tempIndex = gun_index;
  6136. }
  6137. for (int index = 0; index < AC_QUANTITY; index++)
  6138. {
  6139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6140. {
  6141. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  6142. }
  6143. }
  6144. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  6145. }
  6146. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  6147. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  6148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  6149. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  6150. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6151. }
  6152. //********************************(2)Energy.Active.Import.Register ************************************************/
  6153. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6154. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  6155. (dataType == ReadingContext_Trigger))
  6156. {
  6157. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6159. {
  6160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6161. {
  6162. tempIndex = ((gun_index==2) ? 1: 0);
  6163. }
  6164. else
  6165. {
  6166. tempIndex = gun_index;
  6167. }
  6168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6169. {
  6170. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6171. {
  6172. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  6173. }
  6174. }
  6175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6176. }
  6177. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6178. {
  6179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6180. {
  6181. tempIndex = ((gun_index==2) ? 1: 0);
  6182. }
  6183. else
  6184. {
  6185. tempIndex = gun_index;
  6186. }
  6187. for (int index = 0; index < CCS_QUANTITY; index++)
  6188. {
  6189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6190. {
  6191. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  6192. }
  6193. }
  6194. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6195. }
  6196. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6197. {
  6198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6199. {
  6200. tempIndex = ((gun_index==2) ? 1: 0);
  6201. }
  6202. else
  6203. {
  6204. tempIndex = gun_index;
  6205. }
  6206. for (int index = 0; index < GB_QUANTITY; index++)
  6207. {
  6208. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6209. {
  6210. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  6211. }
  6212. }
  6213. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6214. }
  6215. else if(gunType[gun_index] == GUN_TYPE_DO)
  6216. {
  6217. tempIndex = gun_index;
  6218. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6219. {
  6220. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6221. {
  6222. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  6223. }
  6224. }
  6225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  6226. }
  6227. else
  6228. {
  6229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6230. {
  6231. tempIndex = 2;
  6232. }
  6233. else
  6234. {
  6235. tempIndex = gun_index;
  6236. }
  6237. for (int index = 0; index < AC_QUANTITY; index++)
  6238. {
  6239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6240. {
  6241. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  6242. }
  6243. }
  6244. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  6245. }
  6246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  6247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  6248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  6249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  6250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6251. }
  6252. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6253. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6254. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  6255. (dataType == ReadingContext_Trigger))
  6256. {
  6257. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6258. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6259. {
  6260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6261. {
  6262. tempIndex = ((gun_index==2) ? 1: 0);
  6263. }
  6264. else
  6265. {
  6266. tempIndex = gun_index;
  6267. }
  6268. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6269. {
  6270. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6271. {
  6272. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  6273. }
  6274. } // END OF FOR CHAdeMO_QUANTITY
  6275. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6276. }
  6277. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6278. {
  6279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6280. {
  6281. tempIndex = ((gun_index==2) ? 1: 0);
  6282. }
  6283. else
  6284. {
  6285. tempIndex = gun_index;
  6286. }
  6287. for (int index = 0; index < CCS_QUANTITY; index++)
  6288. {
  6289. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6290. {
  6291. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  6292. }
  6293. } // END OF CCS_QUANTITY
  6294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6295. }
  6296. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6297. {
  6298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6299. {
  6300. tempIndex = ((gun_index==2) ? 1: 0);
  6301. }
  6302. else
  6303. {
  6304. tempIndex = gun_index;
  6305. }
  6306. for (int index = 0; index < GB_QUANTITY; index++)
  6307. {
  6308. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6309. {
  6310. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  6311. }
  6312. } // END OF GB_QUANTITY
  6313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6314. }
  6315. else if(gunType[gun_index] == GUN_TYPE_DO)
  6316. {
  6317. tempIndex = gun_index;
  6318. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6319. {
  6320. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6321. {
  6322. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  6323. }
  6324. }
  6325. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  6326. }
  6327. else
  6328. {
  6329. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6330. {
  6331. tempIndex = 2;
  6332. }
  6333. else
  6334. {
  6335. tempIndex = gun_index;
  6336. }
  6337. for (int index = 0; index < AC_QUANTITY; index++)
  6338. {
  6339. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6340. {
  6341. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  6342. }
  6343. }
  6344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  6345. }
  6346. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  6347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  6348. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  6349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  6350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  6351. }
  6352. //********************************(4)Power.Active.Import************************************************/
  6353. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6354. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  6355. (dataType == ReadingContext_Trigger))
  6356. {
  6357. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6358. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6359. {
  6360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6361. {
  6362. tempIndex = ((gun_index==2) ? 1: 0);
  6363. }
  6364. else
  6365. {
  6366. tempIndex = gun_index;
  6367. }
  6368. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6369. {
  6370. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6371. {
  6372. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  6373. }
  6374. } // END OF FOR
  6375. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6376. }
  6377. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6378. {
  6379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6380. {
  6381. tempIndex = ((gun_index==2) ? 1: 0);
  6382. }
  6383. else
  6384. {
  6385. tempIndex = gun_index;
  6386. }
  6387. for (int index = 0; index < CCS_QUANTITY; index++)
  6388. {
  6389. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6390. {
  6391. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  6392. }
  6393. }
  6394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6395. }
  6396. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6397. {
  6398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6399. {
  6400. tempIndex = ((gun_index==2) ? 1: 0);
  6401. }
  6402. else
  6403. {
  6404. tempIndex = gun_index;
  6405. }
  6406. for (int index = 0; index < GB_QUANTITY; index++)
  6407. {
  6408. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6409. {
  6410. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6411. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  6412. }
  6413. }
  6414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6415. }
  6416. else if(gunType[gun_index] == GUN_TYPE_DO)
  6417. {
  6418. tempIndex = gun_index;
  6419. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6420. {
  6421. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6422. {
  6423. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6424. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  6425. }
  6426. }
  6427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  6428. }
  6429. else
  6430. {
  6431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6432. {
  6433. tempIndex = 2;
  6434. }
  6435. else
  6436. {
  6437. tempIndex = gun_index;
  6438. }
  6439. for (int index = 0; index < AC_QUANTITY; index++)
  6440. {
  6441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6442. {
  6443. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6444. }
  6445. }
  6446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6447. }
  6448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6452. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6453. }
  6454. //***********************************************(5)VOLTAGE L1******************************************************/
  6455. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6456. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6457. (dataType == ReadingContext_Trigger))
  6458. {
  6459. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6460. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6461. {
  6462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6463. {
  6464. tempIndex = ((gun_index==2) ? 1: 0);
  6465. }
  6466. else
  6467. {
  6468. tempIndex = gun_index;
  6469. }
  6470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6471. {
  6472. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6473. {
  6474. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6475. }
  6476. }
  6477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6478. }
  6479. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6480. {
  6481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6482. {
  6483. tempIndex = ((gun_index==2) ? 1: 0);
  6484. }
  6485. else
  6486. {
  6487. tempIndex = gun_index;
  6488. }
  6489. for (int index = 0; index < CCS_QUANTITY; index++)
  6490. {
  6491. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6492. {
  6493. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6494. }
  6495. }
  6496. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6497. }
  6498. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6499. {
  6500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6501. {
  6502. tempIndex = ((gun_index==2) ? 1: 0);
  6503. }
  6504. else
  6505. {
  6506. tempIndex = gun_index;
  6507. }
  6508. for (int index = 0; index < GB_QUANTITY; index++)
  6509. {
  6510. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6511. {
  6512. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6513. }
  6514. }
  6515. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6516. }
  6517. else if(gunType[gun_index] == GUN_TYPE_DO)
  6518. {
  6519. tempIndex = gun_index;
  6520. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6521. {
  6522. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6523. {
  6524. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6525. }
  6526. }
  6527. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6528. }
  6529. else
  6530. {
  6531. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6532. {
  6533. tempIndex = 2;
  6534. }
  6535. else
  6536. {
  6537. tempIndex = gun_index;
  6538. }
  6539. for (int index = 0; index < AC_QUANTITY; index++)
  6540. {
  6541. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6542. {
  6543. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6544. }
  6545. }
  6546. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6547. }
  6548. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6549. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6550. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6551. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6552. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6553. }
  6554. //***********************************************(6)SOC******************************************************/
  6555. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6556. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6557. (dataType == ReadingContext_Trigger))
  6558. {
  6559. 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))
  6560. {
  6561. //idx_sample=5;
  6562. //sampledValue = NULL;
  6563. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6564. {
  6565. tempIndex = ((gun_index==2) ? 1: 0);
  6566. }
  6567. else
  6568. {
  6569. tempIndex = gun_index;
  6570. }
  6571. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6572. {
  6573. //tempIndex = ((gun_index==2) ? 1: 0);
  6574. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6575. {
  6576. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6577. {
  6578. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6579. }
  6580. }
  6581. }
  6582. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6583. {
  6584. //tempIndex = ((gun_index==2) ? 1: 0);
  6585. for (int index = 0; index < CCS_QUANTITY; index++)
  6586. {
  6587. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6588. {
  6589. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6590. }
  6591. }
  6592. }
  6593. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6594. {
  6595. //tempIndex = ((gun_index==2) ? 1: 0);
  6596. for (int index = 0; index < GB_QUANTITY; index++)
  6597. {
  6598. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6599. {
  6600. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6601. }
  6602. }
  6603. }
  6604. else if(gunType[gun_index] == GUN_TYPE_DO)
  6605. {
  6606. //tempIndex = ((gun_index==2) ? 1: 0);
  6607. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6608. {
  6609. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6610. {
  6611. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6612. }
  6613. }
  6614. }
  6615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6619. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6620. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6621. }
  6622. }
  6623. //********************************(7)Current.Import L2************************************************/
  6624. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6625. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6626. (dataType == ReadingContext_Trigger))
  6627. {
  6628. // Only for AC 3 phase
  6629. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6630. {
  6631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6632. {
  6633. tempIndex = 2;
  6634. }
  6635. else
  6636. {
  6637. tempIndex = gun_index;
  6638. }
  6639. for (int index = 0; index < AC_QUANTITY; index++)
  6640. {
  6641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6642. {
  6643. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6644. }
  6645. }
  6646. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6647. }
  6648. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6649. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6650. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6651. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6652. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6653. }
  6654. //********************************(8)Current.Import L3************************************************/
  6655. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6656. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6657. (dataType == ReadingContext_Trigger))
  6658. {
  6659. // Only for AC 3 phase
  6660. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6661. {
  6662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6663. {
  6664. tempIndex = 2;
  6665. }
  6666. else
  6667. {
  6668. tempIndex = gun_index;
  6669. }
  6670. for (int index = 0; index < AC_QUANTITY; index++)
  6671. {
  6672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6673. {
  6674. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6675. }
  6676. }
  6677. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6678. }
  6679. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6680. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6681. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6682. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6684. }
  6685. //***********************************************(9)VOLTAGE L2******************************************************/
  6686. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6687. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6688. (dataType == ReadingContext_Trigger))
  6689. {
  6690. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6691. {
  6692. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6693. {
  6694. tempIndex = 2;
  6695. }
  6696. else
  6697. {
  6698. tempIndex = gun_index;
  6699. }
  6700. for (int index = 0; index < AC_QUANTITY; index++)
  6701. {
  6702. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6703. {
  6704. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6705. }
  6706. }
  6707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6708. }
  6709. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6710. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6711. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6712. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6713. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6714. }
  6715. //***********************************************(10)VOLTAGE L3******************************************************/
  6716. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6717. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6718. (dataType == ReadingContext_Trigger))
  6719. {
  6720. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6721. {
  6722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6723. {
  6724. tempIndex = 2;
  6725. }
  6726. else
  6727. {
  6728. tempIndex = gun_index;
  6729. }
  6730. for (int index = 0; index < AC_QUANTITY; index++)
  6731. {
  6732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6733. {
  6734. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6735. }
  6736. }
  6737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6738. }
  6739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6740. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6741. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6742. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6743. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6744. }
  6745. //***********************************************(11)Current.Offered******************************************************/
  6746. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6747. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6748. (dataType == ReadingContext_Trigger))
  6749. {
  6750. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6751. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6752. {
  6753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6754. {
  6755. tempIndex = ((gun_index==2) ? 1: 0);
  6756. }
  6757. else
  6758. {
  6759. tempIndex = gun_index;
  6760. }
  6761. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6762. {
  6763. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6764. {
  6765. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].CurrentOffered/10));
  6766. }
  6767. } // END OF FOR CHAdeMO_QUANTITY
  6768. }
  6769. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6770. {
  6771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6772. {
  6773. tempIndex = ((gun_index==2) ? 1: 0);
  6774. }
  6775. else
  6776. {
  6777. tempIndex = gun_index;
  6778. }
  6779. for (int index = 0; index < CCS_QUANTITY; index++)
  6780. {
  6781. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6782. {
  6783. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].CurrentOffered/10));
  6784. }
  6785. } // END OF CCS_QUANTITY
  6786. }
  6787. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6788. {
  6789. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6790. {
  6791. tempIndex = ((gun_index==2) ? 1: 0);
  6792. }
  6793. else
  6794. {
  6795. tempIndex = gun_index;
  6796. }
  6797. for (int index = 0; index < GB_QUANTITY; index++)
  6798. {
  6799. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6800. {
  6801. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].CurrentOffered/10));
  6802. }
  6803. } // END OF GB_QUANTITY
  6804. }
  6805. else if(gunType[gun_index] == GUN_TYPE_DO)
  6806. {
  6807. tempIndex = gun_index;
  6808. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6809. {
  6810. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6811. {
  6812. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.CurrentOffered/10));
  6813. }
  6814. }
  6815. }
  6816. else
  6817. {
  6818. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6819. {
  6820. tempIndex = 2;
  6821. }
  6822. else
  6823. {
  6824. tempIndex = gun_index;
  6825. }
  6826. for (int index = 0; index < AC_QUANTITY; index++)
  6827. {
  6828. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6829. {
  6830. uint16_t currentOffer;
  6831. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6832. {
  6833. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6834. }
  6835. else
  6836. {
  6837. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6838. }
  6839. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6840. }
  6841. }
  6842. }
  6843. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6844. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6847. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6848. }
  6849. //***********************************************(12)Power.Offered******************************************************/
  6850. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6851. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6852. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6853. {
  6854. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6855. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6856. {
  6857. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6858. {
  6859. tempIndex = ((gun_index==2) ? 1: 0);
  6860. }
  6861. else
  6862. {
  6863. tempIndex = gun_index;
  6864. }
  6865. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6866. {
  6867. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6868. {
  6869. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerOffered*100));
  6870. }
  6871. } // END OF FOR CHAdeMO_QUANTITY
  6872. }
  6873. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6874. {
  6875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6876. {
  6877. tempIndex = ((gun_index==2) ? 1: 0);
  6878. }
  6879. else
  6880. {
  6881. tempIndex = gun_index;
  6882. }
  6883. for (int index = 0; index < CCS_QUANTITY; index++)
  6884. {
  6885. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6886. {
  6887. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerOffered*100));
  6888. }
  6889. } // END OF CCS_QUANTITY
  6890. }
  6891. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6892. {
  6893. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6894. {
  6895. tempIndex = ((gun_index==2) ? 1: 0);
  6896. }
  6897. else
  6898. {
  6899. tempIndex = gun_index;
  6900. }
  6901. for (int index = 0; index < GB_QUANTITY; index++)
  6902. {
  6903. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6904. {
  6905. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerOffered*100));
  6906. }
  6907. } // END OF GB_QUANTITY
  6908. }
  6909. else if(gunType[gun_index] == GUN_TYPE_DO)
  6910. {
  6911. tempIndex = gun_index;
  6912. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6913. {
  6914. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6915. {
  6916. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerOffered*100));
  6917. }
  6918. }
  6919. }
  6920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6923. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6925. }
  6926. // Message create ====================================================================================================
  6927. if(TRUE)
  6928. {
  6929. json_object *MeterValueReq = json_object_new_object();
  6930. json_object *MeterValues = json_object_new_array();
  6931. json_object *sampledValues = json_object_new_array();
  6932. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6933. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6934. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6935. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6936. {
  6937. json_object *MeterValue = json_object_new_object();
  6938. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6939. {
  6940. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6941. {
  6942. json_object *sampledValue = json_object_new_object();
  6943. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6944. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6945. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6946. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6947. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6948. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6949. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6950. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6951. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6952. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6953. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6954. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6955. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6956. json_object_array_add(sampledValues, sampledValue);
  6957. }
  6958. }
  6959. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6960. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6961. json_object_array_add(MeterValues, MeterValue);
  6962. }
  6963. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6964. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6965. ,gun_index + 1
  6966. ,MESSAGE_TYPE_CALL
  6967. ,guid
  6968. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6969. json_object_put(MeterValueReq);
  6970. }
  6971. // Put request guid to hash map
  6972. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6973. 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*/)
  6974. {
  6975. result = PASS;
  6976. //DEBUG_INFO("MeterValues mapitem pass\n");
  6977. }
  6978. if((dataType != ReadingContext_Trigger) &&
  6979. (dataType != ReadingContext_Sample_Clock) &&
  6980. ((ShmOCPP16Data->MeterValues[gun_index].TransactionId > 0) || (strstr((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6981. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6982. else
  6983. {
  6984. if(FirstHeartBeat)
  6985. LWS_Send(queuedata +2);
  6986. }
  6987. return result;
  6988. }
  6989. int sendLogStatusNotificationRequest(char *status)
  6990. {
  6991. mtrace();
  6992. int result = PASS;
  6993. char message[4096]={0};
  6994. char guid[37]={0};
  6995. char tempdata[128]={0};
  6996. json_object *LogStatusNotification = json_object_new_object();
  6997. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6998. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6999. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  7000. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  7001. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  7002. random_uuid(guid);
  7003. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  7004. json_object_put(LogStatusNotification);
  7005. LWS_Send(message);
  7006. sprintf(tempdata, "LogStatusNotification,%d", 0);
  7007. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7008. {
  7009. result = PASS;
  7010. }
  7011. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  7012. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  7013. return result;
  7014. }
  7015. int sendSecurityEventNotificationRequest()
  7016. {
  7017. mtrace();
  7018. int result = PASS;
  7019. char message[4096]={0};
  7020. char guid[37]={0};
  7021. char tempdata[128]={0};
  7022. json_object *SecurityEventNotification = json_object_new_object();
  7023. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7024. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  7025. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  7026. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  7027. random_uuid(guid);
  7028. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7029. json_object_put(SecurityEventNotification);
  7030. LWS_Send(message);
  7031. sprintf(tempdata, "SecurityEventNotification,0");
  7032. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7033. {
  7034. result = PASS;
  7035. }
  7036. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  7037. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  7038. return result;
  7039. }
  7040. int sendSignCertificateRequest()
  7041. {
  7042. mtrace();
  7043. int result = PASS;
  7044. char message[4096]={0};
  7045. char guid[37]={0};
  7046. char tempdata[128]={0};
  7047. json_object *SignCertificate = json_object_new_object();
  7048. DEBUG_INFO("sendSignCertificateRequest...\n");
  7049. // Read csr file content
  7050. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  7051. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  7052. char *line = NULL;
  7053. size_t len = 0;
  7054. while(getline(&line, &len, fp) != -1)
  7055. {
  7056. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7057. {
  7058. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  7059. }
  7060. }
  7061. fclose(fp);
  7062. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  7063. random_uuid(guid);
  7064. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7065. json_object_put(SignCertificate);
  7066. LWS_Send(message);
  7067. sprintf(tempdata, "SignCertificate,0");
  7068. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7069. {
  7070. result = PASS;
  7071. }
  7072. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  7073. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  7074. return result;
  7075. }
  7076. int sendSignedFirmwareStatusNotificationRequest(char *status)
  7077. {
  7078. mtrace();
  7079. int result = PASS;
  7080. char message[110]={0};
  7081. char guid[37]={0};
  7082. char tempdata[65]={0};
  7083. json_object *FirmwareStatusNotification = json_object_new_object();
  7084. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  7085. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  7086. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  7087. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  7088. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  7089. random_uuid(guid);
  7090. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7091. json_object_put(FirmwareStatusNotification);
  7092. LWS_Send(message);
  7093. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  7094. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7095. {
  7096. result = PASS;
  7097. }
  7098. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  7099. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  7100. return result;
  7101. }
  7102. //==========================================
  7103. // send confirm routine
  7104. //==========================================
  7105. int sendCancelReservationConfirmation(char *uuid,char *payload)
  7106. {
  7107. mtrace();
  7108. int result = FAIL;
  7109. char message[100]={0};
  7110. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  7111. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7112. LWS_Send(message);
  7113. result = TRUE;
  7114. return result;
  7115. }
  7116. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  7117. {
  7118. mtrace();
  7119. int result = FAIL;
  7120. char message[100]={0};
  7121. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  7122. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7123. LWS_Send(message);
  7124. result = TRUE;
  7125. return result;
  7126. }
  7127. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  7128. {
  7129. mtrace();
  7130. int result = FAIL;
  7131. char message[100]={0};
  7132. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  7133. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  7134. LWS_Send(message);
  7135. result = TRUE;
  7136. return result;
  7137. }
  7138. int sendClearCacheConfirmation(char *uuid,char *payload)
  7139. {
  7140. mtrace();
  7141. int result = FAIL;
  7142. char message[500]={0};
  7143. DEBUG_INFO("sendClearCacheConfirmation...\n");
  7144. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7145. LWS_Send(message);
  7146. return result;
  7147. }
  7148. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  7149. {
  7150. mtrace();
  7151. int result = FAIL;
  7152. char message[500]={0};
  7153. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  7154. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7155. LWS_Send(message);
  7156. return result;
  7157. }
  7158. int sendDataTransferConfirmation(char *uuid,char *payload)
  7159. {
  7160. mtrace();
  7161. char statusStr[20]={0};
  7162. char dataStr[10]={0};
  7163. char sstr[20]={0};
  7164. int c = 0;
  7165. char *loc;
  7166. int result = FAIL;
  7167. DEBUG_INFO("sendDataTransferConfirmation...\n");
  7168. /**********************status**************************/
  7169. loc = strstr(payload, "status");
  7170. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7171. c = 0;
  7172. while (loc[3+strlen("status")+c] != '\"')
  7173. {
  7174. sstr[c] = loc[3+strlen("status")+c];
  7175. c++;
  7176. }
  7177. sstr[c] = '\0';
  7178. strcpy(statusStr, sstr);
  7179. /**********************data**************************/
  7180. loc = strstr(payload, "data");
  7181. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7182. c = 0;
  7183. while (loc[3+strlen("data")+c] != '\"')
  7184. {
  7185. sstr[c] = loc[3+strlen("data")+c];
  7186. c++;
  7187. }
  7188. sstr[c] = '\0';
  7189. strcpy(dataStr, sstr);
  7190. return result;
  7191. }
  7192. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  7193. {
  7194. mtrace();
  7195. int result = FAIL;
  7196. char message[1000]={0};
  7197. int CompositeScheduleIndex = 0;
  7198. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  7199. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  7200. if(nPeriod == 0)
  7201. {
  7202. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  7203. {
  7204. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  7205. ,MESSAGE_TYPE_CALLRESULT
  7206. ,uuid
  7207. ,payload
  7208. ,connectorIdInt);
  7209. }
  7210. else
  7211. {
  7212. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  7213. ,MESSAGE_TYPE_CALLRESULT
  7214. ,uuid
  7215. ,payload
  7216. ,connectorIdInt
  7217. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7218. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7219. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7220. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  7221. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  7222. }
  7223. }
  7224. else
  7225. {
  7226. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  7227. ,MESSAGE_TYPE_CALLRESULT
  7228. ,uuid
  7229. ,payload
  7230. ,connectorIdInt
  7231. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7232. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  7233. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  7234. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  7235. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  7236. {
  7237. if (idx_sample == 0)
  7238. {
  7239. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7240. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7241. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7242. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7243. }
  7244. else
  7245. {
  7246. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  7247. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  7248. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  7249. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  7250. }
  7251. }
  7252. sprintf(message + strlen(message), "]}}]");
  7253. }
  7254. LWS_Send(message);
  7255. result = TRUE;
  7256. return result;
  7257. }
  7258. int sendGetConfigurationConfirmation(char *uuid)
  7259. {
  7260. mtrace();
  7261. int result = FAIL;
  7262. int MaxKeySupported = 0;
  7263. int sentConfigurationNumber= 0;
  7264. int sentunConfigurationNumber= 0;
  7265. char message[1024*10]={0};
  7266. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  7267. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  7268. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  7269. ,MESSAGE_TYPE_CALLRESULT
  7270. ,uuid );
  7271. //configuration key
  7272. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  7273. {
  7274. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  7275. {
  7276. if (sentConfigurationNumber == 0)
  7277. {
  7278. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7279. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7280. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7281. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7282. }
  7283. else
  7284. {
  7285. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  7286. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  7287. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  7288. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  7289. }
  7290. sentConfigurationNumber = sentConfigurationNumber + 1;
  7291. }
  7292. }
  7293. sprintf(message + strlen(message), "]");
  7294. if(UnknownKeynum != 0)
  7295. {
  7296. sprintf(message + strlen(message), ",\"unknownKey\":[");
  7297. //unkown key
  7298. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  7299. {
  7300. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  7301. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  7302. if(sentunConfigurationNumber == 0)
  7303. {
  7304. sprintf(message + strlen(message), "\"%s\""
  7305. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7306. }
  7307. else
  7308. {
  7309. sprintf(message + strlen(message), ",\"%s\""
  7310. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  7311. }
  7312. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  7313. }
  7314. sprintf(message + strlen(message), "]");
  7315. }
  7316. sprintf(message + strlen(message), "}]");
  7317. LWS_Send(message);
  7318. return result;
  7319. }
  7320. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  7321. {
  7322. mtrace();
  7323. int result = FAIL;
  7324. char message[400]={0};
  7325. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  7326. if(strcmp(payload,"")==0)
  7327. {
  7328. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7329. }
  7330. else
  7331. {
  7332. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7333. }
  7334. LWS_Send(message);
  7335. result = TRUE;
  7336. return result;
  7337. }
  7338. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  7339. {
  7340. mtrace();
  7341. int result = FAIL;
  7342. char message[80]={0};
  7343. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  7344. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  7345. LWS_Send(message);
  7346. result = TRUE;
  7347. return result;
  7348. }
  7349. int sendRemoteStartConfirmation(char *uuid,char *payload)
  7350. {
  7351. mtrace();
  7352. int result = FAIL;
  7353. char message[80]={0};
  7354. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  7355. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7356. LWS_Send(message);
  7357. result = TRUE;
  7358. return result;
  7359. }
  7360. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  7361. {
  7362. mtrace();
  7363. int result = FAIL;
  7364. char message[80]={0};
  7365. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  7366. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7367. LWS_Send(message);
  7368. result = TRUE;
  7369. return result;
  7370. }
  7371. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  7372. {
  7373. mtrace();
  7374. int result = FAIL;
  7375. char message[80]={0};
  7376. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  7377. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  7378. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7379. LWS_Send(message);
  7380. result = TRUE;
  7381. return result;
  7382. }
  7383. int sendResetConfirmation(char *uuid,char *payload)
  7384. {
  7385. mtrace();
  7386. int result = FAIL;
  7387. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  7388. char message[80]={0};
  7389. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  7390. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7391. LWS_Send(message);
  7392. result = TRUE;
  7393. return result;
  7394. }
  7395. int sendSendLocalListConfirmation(char *uuid,char *payload)
  7396. {
  7397. mtrace();
  7398. int result = FAIL;
  7399. char message[500]={0};
  7400. // [ 3, "1571284266109", { "status": "Accepted" } ]
  7401. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  7402. LWS_Send(message);
  7403. result = TRUE;
  7404. return result;
  7405. }
  7406. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  7407. {
  7408. mtrace();
  7409. int result = FAIL;
  7410. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  7411. char message[80]={0};
  7412. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  7413. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7414. LWS_Send(message);
  7415. result = TRUE;
  7416. return result;
  7417. }
  7418. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  7419. {
  7420. mtrace();
  7421. int result = FAIL;
  7422. char message[80]={0};
  7423. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  7424. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7425. LWS_Send(message);
  7426. result = TRUE;
  7427. return result;
  7428. }
  7429. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7430. {
  7431. mtrace();
  7432. int result = FAIL;
  7433. char message[80]={0};
  7434. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7435. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7436. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7437. LWS_Send(message);
  7438. result = TRUE;
  7439. return result;
  7440. }
  7441. int sendUpdateFirmwareConfirmation(char *uuid)
  7442. {
  7443. mtrace();
  7444. int result = FAIL;
  7445. char message[60]={0};
  7446. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7447. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7448. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7449. LWS_Send(message);
  7450. result = TRUE;
  7451. return result;
  7452. }
  7453. int sendCertificateSignedConfirmation(char *uuid)
  7454. {
  7455. mtrace();
  7456. int result = PASS;
  7457. char message[4096]={0};
  7458. json_object *CertificateSigned = json_object_new_object();
  7459. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7460. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7461. sprintf(message,"[%d,\"%s\",%s]"
  7462. ,MESSAGE_TYPE_CALLRESULT
  7463. ,uuid
  7464. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7465. json_object_put(CertificateSigned);
  7466. LWS_Send(message);
  7467. return result;
  7468. }
  7469. int sendDeleteCertificateConfirmation(char *uuid)
  7470. {
  7471. mtrace();
  7472. int result = PASS;
  7473. char message[4096]={0};
  7474. json_object *DeleteCertificate = json_object_new_object();
  7475. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7476. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7477. sprintf(message,"[%d,\"%s\",%s]"
  7478. ,MESSAGE_TYPE_CALLRESULT
  7479. ,uuid
  7480. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7481. json_object_put(DeleteCertificate);
  7482. LWS_Send(message);
  7483. return result;
  7484. }
  7485. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7486. {
  7487. mtrace();
  7488. int result = PASS;
  7489. char message[4096]={0};
  7490. json_object *ExtendedTriggerMessage = json_object_new_object();
  7491. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7492. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7493. sprintf(message,"[%d,\"%s\",%s]"
  7494. ,MESSAGE_TYPE_CALLRESULT
  7495. ,uuid
  7496. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7497. json_object_put(ExtendedTriggerMessage);
  7498. LWS_Send(message);
  7499. return result;
  7500. }
  7501. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7502. {
  7503. mtrace();
  7504. int result = PASS;
  7505. char message[4096]={0};
  7506. json_object *GetInstalledCertificateIds = json_object_new_object();
  7507. json_object *certificateHashDataDatas = json_object_new_array();
  7508. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7509. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7510. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7511. {
  7512. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7513. {
  7514. json_object *certificateHashData = json_object_new_object();
  7515. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7516. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7517. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7518. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7519. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7520. }
  7521. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7522. }
  7523. else
  7524. {
  7525. json_object_put(certificateHashDataDatas);
  7526. }
  7527. sprintf(message,"[%d,\"%s\",%s]"
  7528. ,MESSAGE_TYPE_CALLRESULT
  7529. ,uuid
  7530. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7531. json_object_put(GetInstalledCertificateIds);
  7532. LWS_Send(message);
  7533. return result;
  7534. }
  7535. int sendGetLogConfirmation(char *uuid)
  7536. {
  7537. mtrace();
  7538. int result = PASS;
  7539. char message[4096]={0};
  7540. json_object *GetLog = json_object_new_object();
  7541. DEBUG_INFO("sendGetLogConfirmation...\n");
  7542. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7543. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7544. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7545. sprintf(message,"[%d,\"%s\",%s]"
  7546. ,MESSAGE_TYPE_CALLRESULT
  7547. ,uuid
  7548. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7549. json_object_put(GetLog);
  7550. LWS_Send(message);
  7551. return result;
  7552. }
  7553. int sendInstallCertificateConfirmation(char *uuid)
  7554. {
  7555. mtrace();
  7556. int result = PASS;
  7557. char message[4096]={0};
  7558. json_object *InstallCertificate = json_object_new_object();
  7559. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7560. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7561. sprintf(message,"[%d,\"%s\",%s]"
  7562. ,MESSAGE_TYPE_CALLRESULT
  7563. ,uuid
  7564. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7565. json_object_put(InstallCertificate);
  7566. LWS_Send(message);
  7567. return result;
  7568. }
  7569. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7570. {
  7571. mtrace();
  7572. int result = PASS;
  7573. char message[4096]={0};
  7574. json_object *SignedUpdateFirmware = json_object_new_object();
  7575. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7576. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7577. sprintf(message,"[%d,\"%s\",%s]"
  7578. ,MESSAGE_TYPE_CALLRESULT
  7579. ,uuid
  7580. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7581. json_object_put(SignedUpdateFirmware);
  7582. LWS_Send(message);
  7583. return result;
  7584. }
  7585. int sendUnknownConfirmation(char *uuid)
  7586. {
  7587. mtrace();
  7588. int result = PASS;
  7589. char message[256]={0};
  7590. DEBUG_INFO("sendUnknownConfirmation...\n");
  7591. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7592. LWS_Send(message);
  7593. return result;
  7594. }
  7595. //==========================================
  7596. // Handle server request routine Start
  7597. //==========================================
  7598. int handleCancelReservationRequest(char *uuid, char *payload)
  7599. {
  7600. mtrace();
  7601. int result = FAIL;
  7602. int gunNO = 0;
  7603. int reservationIdInt = -1;
  7604. char comfirmstr[20];
  7605. DEBUG_INFO("handleCancelReservationRequest...\n");
  7606. json_object *CancelReservation;
  7607. CancelReservation = json_tokener_parse(payload);
  7608. if(!is_error(CancelReservation))
  7609. {
  7610. // Required data
  7611. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7612. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7613. }
  7614. json_object_put(CancelReservation);
  7615. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7616. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7617. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7618. if(reservationIdInt != -1)
  7619. {
  7620. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7621. //check Transaction active
  7622. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7623. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7624. {
  7625. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7626. {
  7627. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7628. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7629. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7630. {
  7631. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7632. }
  7633. else
  7634. {
  7635. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7636. }
  7637. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7638. goto end;
  7639. }
  7640. }
  7641. for (int index = 0; index < CCS_QUANTITY; index++)
  7642. {
  7643. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7644. {
  7645. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7646. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7647. if(gunType[2] == GUN_TYPE_CCS)
  7648. {
  7649. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7650. }
  7651. else
  7652. {
  7653. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7654. }
  7655. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7656. goto end;
  7657. }
  7658. }
  7659. for (int index = 0; index < GB_QUANTITY; index++)
  7660. {
  7661. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7662. {
  7663. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7664. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7665. if(gunType[2] == GUN_TYPE_GBT)
  7666. {
  7667. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7668. }
  7669. else
  7670. {
  7671. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7672. }
  7673. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7674. goto end;
  7675. }
  7676. }
  7677. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7678. {
  7679. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7680. {
  7681. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7682. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7683. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7684. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7685. goto end;
  7686. }
  7687. }
  7688. for (int index = 0; index < AC_QUANTITY; index++)
  7689. {
  7690. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7691. {
  7692. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7693. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7694. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7695. {
  7696. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7697. }
  7698. else
  7699. {
  7700. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7701. }
  7702. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7703. goto end;
  7704. }
  7705. }
  7706. }
  7707. //The reservationId does NOT match the reservationId
  7708. sendCancelReservationConfirmation(uuid, comfirmstr);
  7709. end:
  7710. // Fill in ocpp packet uuid
  7711. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7712. return result;
  7713. }
  7714. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7715. {
  7716. mtrace();
  7717. int result = FAIL;
  7718. int gunIndex = -1;
  7719. char typeStr[16]={0};
  7720. char comfirmstr[20];
  7721. int specificId = FALSE;
  7722. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7723. json_object *ChangeAvailability;
  7724. ChangeAvailability = json_tokener_parse(payload);
  7725. if(!is_error(ChangeAvailability))
  7726. {
  7727. // Required data
  7728. if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
  7729. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7730. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7731. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7732. }
  7733. json_object_put(ChangeAvailability);
  7734. if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
  7735. {
  7736. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7737. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7738. }
  7739. else if(gunIndex == 0)
  7740. {
  7741. for(int i=0; i < gunTotalNumber; i++)
  7742. {
  7743. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7744. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7745. }
  7746. }
  7747. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7749. if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
  7750. {
  7751. specificId = TRUE;
  7752. }
  7753. if(specificId == FALSE)
  7754. goto end;
  7755. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7756. {
  7757. //----------------------gunIndex is 0 ------------------------------------------------//
  7758. if(gunIndex == 0)
  7759. {
  7760. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7761. {
  7762. for(int i=0; i < gunTotalNumber; i++)
  7763. {
  7764. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7765. {
  7766. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7767. {
  7768. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7769. {
  7770. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7771. goto end;
  7772. }
  7773. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7774. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7775. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7776. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7777. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7778. {
  7779. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7780. goto end;
  7781. }
  7782. }
  7783. }//END FOR CHAdeMO_QUANTITY
  7784. for (int index = 0; index < CCS_QUANTITY; index++)
  7785. {
  7786. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7787. {
  7788. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7789. {
  7790. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7791. goto end;
  7792. }
  7793. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7794. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7795. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7796. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7797. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7798. {
  7799. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7800. goto end;
  7801. }
  7802. }
  7803. }//END FOR CCS_QUANTITY
  7804. for (int index = 0; index < GB_QUANTITY; index++)
  7805. {
  7806. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7807. {
  7808. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7809. {
  7810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7811. goto end;
  7812. }
  7813. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7814. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7815. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7816. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7817. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7818. {
  7819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7820. goto end;
  7821. }
  7822. }
  7823. }// END FOR GB_QUANTITY
  7824. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7825. {
  7826. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7827. {
  7828. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7829. {
  7830. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7831. goto end;
  7832. }
  7833. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7834. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7835. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7836. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7837. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7838. {
  7839. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7840. goto end;
  7841. }
  7842. }
  7843. }// END FOR GENERAL_GUN_QUANTITY
  7844. for (int index = 0; index < AC_QUANTITY; index++)
  7845. {
  7846. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7847. {
  7848. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7849. {
  7850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7851. goto end;
  7852. }
  7853. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7854. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7855. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7856. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7857. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7858. {
  7859. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7860. goto end;
  7861. }
  7862. }
  7863. }//END FOR AC_QUANTITY
  7864. }// END FOR gunTotalNumber
  7865. }
  7866. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7867. {
  7868. for(int i=0; i < gunTotalNumber; i++)
  7869. {
  7870. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7871. {
  7872. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7873. goto end;
  7874. }
  7875. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7876. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7877. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7878. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7879. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7880. {
  7881. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7882. goto end;
  7883. }
  7884. }
  7885. }
  7886. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7887. goto end;
  7888. }
  7889. //----------------------gunIndex is not 0 ------------------------------------------------//
  7890. //check Transaction active
  7891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7892. {
  7893. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7894. {
  7895. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7896. {
  7897. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7898. goto end;
  7899. }
  7900. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7901. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7902. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7903. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7904. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7905. {
  7906. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7907. goto end;
  7908. }
  7909. else
  7910. {
  7911. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7912. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7913. goto end;
  7914. }
  7915. }
  7916. }//END FOR CHAdeMO_QUANTITY
  7917. for (int index = 0; index < CCS_QUANTITY; index++)
  7918. {
  7919. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7920. {
  7921. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7922. {
  7923. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7924. goto end;
  7925. }
  7926. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7927. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7928. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7929. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7930. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7931. {
  7932. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7933. goto end;
  7934. }
  7935. else
  7936. {
  7937. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7938. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7939. goto end;
  7940. }
  7941. }
  7942. }//END FOR CCS_QUANTITY
  7943. for (int index = 0; index < GB_QUANTITY; index++)
  7944. {
  7945. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7946. {
  7947. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7948. {
  7949. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7950. goto end;
  7951. }
  7952. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7953. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7954. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7955. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7956. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7957. {
  7958. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7959. goto end;
  7960. }
  7961. else
  7962. {
  7963. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7964. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7965. goto end;
  7966. }
  7967. }
  7968. }// END FOR GB_QUANTITY
  7969. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7970. {
  7971. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7972. {
  7973. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7974. {
  7975. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7976. goto end;
  7977. }
  7978. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7979. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7980. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7981. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7982. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7983. {
  7984. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7985. goto end;
  7986. }
  7987. else
  7988. {
  7989. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7990. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7991. goto end;
  7992. }
  7993. }
  7994. }// END FOR GENERAL_GUN_QUANTITY
  7995. for (int index = 0; index < AC_QUANTITY; index++)
  7996. {
  7997. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7998. {
  7999. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  8000. {
  8001. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8002. goto end;
  8003. }
  8004. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  8005. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  8006. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  8007. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  8008. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  8009. {
  8010. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  8011. goto end;
  8012. }
  8013. else
  8014. {
  8015. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  8016. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8017. goto end;
  8018. }
  8019. }
  8020. }//END FOR AC_QUANTITY
  8021. }//END FOR AvailabilityTypeStr[Inoperative]
  8022. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  8023. {
  8024. //----------------------gunIndex is 0 ------------------------------------------------//
  8025. if(gunIndex == 0)
  8026. {
  8027. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8028. {
  8029. for(int i=0; i < gunTotalNumber; i++)
  8030. {
  8031. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8032. {
  8033. 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
  8034. {
  8035. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8036. goto end;
  8037. }
  8038. }//END FOR CHAdeMO_QUANTITY
  8039. for (int index = 0; index < CCS_QUANTITY; index++)
  8040. {
  8041. 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
  8042. {
  8043. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8044. goto end;
  8045. }
  8046. }//END FOR CCS_QUANTITY
  8047. for (int index = 0; index < GB_QUANTITY; index++)
  8048. {
  8049. 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
  8050. {
  8051. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8052. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8053. goto end;
  8054. }
  8055. }// END FOR GB_QUANTITY
  8056. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8057. {
  8058. 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
  8059. {
  8060. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8061. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8062. goto end;
  8063. }
  8064. }// END FOR GENERAL_GUN_QUANTITY
  8065. for (int index = 0; index < AC_QUANTITY; index++)
  8066. {
  8067. 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
  8068. {
  8069. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8070. goto end;
  8071. }
  8072. }//END FOR CHAdeMO_QUANTITY
  8073. }// END FOR gunTotalNumber
  8074. }
  8075. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  8076. {
  8077. for(int i=0; i < gunTotalNumber; i++)
  8078. {
  8079. for (int index = 0; index < AC_QUANTITY; index++)
  8080. {
  8081. 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
  8082. {
  8083. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  8084. goto end;
  8085. }
  8086. }//END FOR CHAdeMO_QUANTITY
  8087. } // END FOR gunTotalNumber
  8088. }
  8089. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8090. goto end;
  8091. }
  8092. //----------------------gunIndex is not 0 ------------------------------------------------//
  8093. //check Transaction active
  8094. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8095. {
  8096. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8097. {
  8098. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8099. goto end;
  8100. }
  8101. }//END FOR CHAdeMO_QUANTITY
  8102. for (int index = 0; index < CCS_QUANTITY; index++)
  8103. {
  8104. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8105. {
  8106. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8107. goto end;
  8108. }
  8109. }//END FOR CCS_QUANTITY
  8110. for (int index = 0; index < GB_QUANTITY; index++)
  8111. {
  8112. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8113. {
  8114. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8115. goto end;
  8116. }
  8117. }// END FOR GB_QUANTITY
  8118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8119. {
  8120. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8121. {
  8122. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8123. goto end;
  8124. }
  8125. }// END FOR GENERAL_GUN_QUANTITY
  8126. for (int index = 0; index < AC_QUANTITY; index++)
  8127. {
  8128. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  8129. {
  8130. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  8131. goto end;
  8132. }
  8133. }//END FOR AC_QUANTITY
  8134. }//END FOR AvailabilityTypeStr[Operative]
  8135. end:
  8136. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8137. {
  8138. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  8139. }
  8140. else
  8141. {
  8142. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  8143. }
  8144. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  8145. {
  8146. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8147. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  8148. }
  8149. else if(gunIndex == 0)
  8150. {
  8151. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  8152. {
  8153. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  8154. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  8155. }
  8156. }
  8157. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  8158. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8159. return result;
  8160. }
  8161. int handleChangeConfigurationRequest(char *uuid, char *payload)
  8162. {
  8163. mtrace();
  8164. int result = FAIL;
  8165. char keystr[40]={0};
  8166. char valuestr[256]={0};
  8167. char comfirmstr[20]={0};
  8168. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  8169. json_object *ChangeConfiguration;
  8170. ChangeConfiguration = json_tokener_parse(payload);
  8171. if(!is_error(ChangeConfiguration))
  8172. {
  8173. // Required data
  8174. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  8175. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  8176. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  8177. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  8178. }
  8179. json_object_put(ChangeConfiguration);
  8180. if((uuid==NULL) || (payload ==NULL) )
  8181. {
  8182. DEBUG_ERROR("Payload is null\n");
  8183. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8184. }
  8185. else
  8186. {
  8187. int status = setKeyValue(keystr, valuestr);
  8188. switch(status)
  8189. {
  8190. case ConfigurationStatus_Accepted:
  8191. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  8192. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  8193. StoreConfigurationTable();
  8194. break;
  8195. case RebootRequired:
  8196. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  8197. StoreConfigurationTable();
  8198. break;
  8199. case NotSupported:
  8200. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  8201. break;
  8202. case ConfigurationStatus_Rejected:
  8203. default:
  8204. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  8205. break;
  8206. }
  8207. }
  8208. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  8209. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  8210. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  8211. {
  8212. ChageWebSocketPingInterval(atoi(valuestr));
  8213. }
  8214. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8215. {
  8216. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8217. SetOcppConnStatus(FALSE);
  8218. }
  8219. if(((strcmp(keystr,"FreeVend")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  8220. {
  8221. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8222. }
  8223. return result;
  8224. }
  8225. int handleClearCacheRequest(char *uuid, char *payload)
  8226. {
  8227. mtrace();
  8228. int result = FAIL;
  8229. char comfirmstr[20];
  8230. char rmFileCmd[100]={0};
  8231. struct stat stats;
  8232. DEBUG_INFO("handleClearCacheRequest...\n");
  8233. stat("/Storage/OCPP", &stats);
  8234. // Check for directory existence
  8235. if (S_ISDIR(stats.st_mode) == 1)
  8236. {}
  8237. else
  8238. {
  8239. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  8240. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  8241. system(rmFileCmd);
  8242. }
  8243. if(OCPP_cleanLocalCache())
  8244. {
  8245. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  8246. }
  8247. else
  8248. {
  8249. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  8250. }
  8251. sendClearCacheConfirmation(uuid, comfirmstr);
  8252. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8253. return result;
  8254. }
  8255. int handleClearChargingProfileRequest(char *uuid, char *payload)
  8256. {
  8257. mtrace();
  8258. int result = FAIL;
  8259. int resultRename;
  8260. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  8261. char chargingProfilePurposeStr[26]={0};
  8262. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  8263. char tempchargingProfilePurposeStr[26]={0};
  8264. char str[100]={0};
  8265. char fname[200]={0};
  8266. char comfirmstr[20]={0};
  8267. char word[1600]={0};
  8268. int clearflag = FALSE;
  8269. int chargingProfileIdIsNULL = FALSE;
  8270. int connectorIsNULL = FALSE;
  8271. int chargingProfilePurposeIsNULL = FALSE;
  8272. int stackLevelIsNULL = FALSE;
  8273. //int GotoEnd = FALSE;
  8274. FILE *fptr1, *fptr2;
  8275. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  8276. int n_chargingProfile=0;
  8277. int isEmptyFile = FALSE;
  8278. char sLineWord[1600]={0};
  8279. char chargingProfiles[10][100]={0};
  8280. int ChargeProfileCount = 0;
  8281. int ch;
  8282. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  8283. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  8284. json_object *ClearChargingProfile;
  8285. ClearChargingProfile = json_tokener_parse(payload);
  8286. if(!is_error(ClearChargingProfile))
  8287. {
  8288. // Optional data
  8289. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  8290. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  8291. else
  8292. chargingProfileIdIsNULL = TRUE;
  8293. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  8294. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  8295. else
  8296. connectorIsNULL = TRUE;
  8297. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  8298. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  8299. else
  8300. chargingProfilePurposeIsNULL = TRUE;
  8301. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  8302. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  8303. else
  8304. stackLevelIsNULL = TRUE;
  8305. }
  8306. json_object_put(ClearChargingProfile);
  8307. if(connectorIsNULL == FALSE)
  8308. {
  8309. switch(connectorIdInt)
  8310. {
  8311. case 0:
  8312. if(chargingProfilePurposeIsNULL == TRUE)
  8313. {
  8314. int l = 0;
  8315. strcpy(fname, ChargePointMaxProfile_JSON);
  8316. if((access(fname,F_OK))!=-1)
  8317. {
  8318. strcpy(chargingProfiles[l], fname);
  8319. l = l + 1;
  8320. }
  8321. strcpy(fname, TxDefaultProfile_0_JSON);
  8322. if((access(fname,F_OK))!=-1)
  8323. {
  8324. strcpy(chargingProfiles[l], fname);
  8325. l = l + 1;
  8326. }
  8327. ChargeProfileCount = l;
  8328. }
  8329. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  8330. {
  8331. strcpy(fname, ChargePointMaxProfile_JSON);
  8332. if((access(fname,F_OK))!=-1)
  8333. {
  8334. strcpy(chargingProfiles[0], fname);
  8335. ChargeProfileCount = 1;
  8336. }
  8337. }
  8338. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8339. {
  8340. strcpy(fname, TxDefaultProfile_0_JSON);
  8341. if((access(fname,F_OK))!=-1)
  8342. {
  8343. strcpy(chargingProfiles[0], fname);
  8344. ChargeProfileCount = 1;
  8345. }
  8346. }
  8347. break;
  8348. default:
  8349. if(chargingProfilePurposeIsNULL == TRUE)
  8350. {
  8351. int m = 0;
  8352. memset(fname, 0, ARRAY_SIZE(fname));
  8353. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8354. if((access(fname,F_OK))!=-1)
  8355. {
  8356. strcpy(chargingProfiles[m], fname);
  8357. m = m + 1;
  8358. }
  8359. memset(fname, 0, ARRAY_SIZE(fname));
  8360. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8361. if((access(fname,F_OK))!=-1)
  8362. {
  8363. strcpy(chargingProfiles[m], fname);
  8364. m = m + 1;
  8365. }
  8366. ChargeProfileCount = m;
  8367. }
  8368. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  8369. {
  8370. //strcpy(fname, TxDefaultProfile_1_JSON);
  8371. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8372. if((access(fname,F_OK))!=-1)
  8373. {
  8374. strcpy(chargingProfiles[0], fname);
  8375. ChargeProfileCount = 1;
  8376. }
  8377. }
  8378. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  8379. {
  8380. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8381. if((access(fname,F_OK))!=-1)
  8382. {
  8383. strcpy(chargingProfiles[0], fname);
  8384. ChargeProfileCount = 1;
  8385. }
  8386. //strcpy(fname, TxProfile_1_JSON);
  8387. }
  8388. //strcpy(fname, ChargePointMaxProfile_JSON );
  8389. break;
  8390. }
  8391. }
  8392. else // Check all Charging Profiles
  8393. {
  8394. int i = 0;
  8395. char fnametemp[200]={0};
  8396. ChargeProfileCount = 0;
  8397. //Check ChargePointMaxProfile.json exit
  8398. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8399. {
  8400. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  8401. i = i + 1;
  8402. }
  8403. //Check TxDefaultProfile_0.json exit
  8404. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8405. {
  8406. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  8407. i = i + 1;
  8408. }
  8409. //Check TxDefaultProfile_%d.json
  8410. for(int j=1; j <= gunTotalNumber; j++)
  8411. {
  8412. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8413. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8414. if((access(fnametemp,F_OK))!=-1)
  8415. {
  8416. strcpy(chargingProfiles[i], fnametemp);
  8417. i = i + 1;
  8418. }
  8419. }
  8420. //Check TxProfile_%d.json
  8421. for(int j=1; j <= gunTotalNumber; j++)
  8422. {
  8423. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8424. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8425. if((access(fnametemp,F_OK))!=-1)
  8426. {
  8427. strcpy(chargingProfiles[i], fnametemp);
  8428. i = i + 1;
  8429. }
  8430. }
  8431. ChargeProfileCount = i;
  8432. }// End connectorIsNULL is TRUE
  8433. if(ChargeProfileCount == 0)
  8434. {
  8435. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8436. goto end;
  8437. }
  8438. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8439. {
  8440. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8441. goto end;
  8442. }
  8443. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8444. {
  8445. memset(str, 0, ARRAY_SIZE(str));
  8446. // clear temp file
  8447. sprintf(str,"rm -f %s",temp);
  8448. system(str);
  8449. for(int k=0; k < ChargeProfileCount; k++)
  8450. {
  8451. memset(str, 0, ARRAY_SIZE(str));
  8452. //clear file in C
  8453. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8454. system(str);
  8455. }
  8456. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8457. goto end;
  8458. }
  8459. else if(connectorIsNULL == TRUE)
  8460. {
  8461. for(int k=0; k < ChargeProfileCount; k++)
  8462. {
  8463. fptr1 = fopen(chargingProfiles[k], "r");
  8464. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8465. //Check Charging Profile Count
  8466. while(fscanf(fptr1, "%s", word) != EOF)
  8467. {
  8468. //DEBUG_INFO("word=%s\n",word);
  8469. if(strstr(word, "chargingProfileId")!= NULL)
  8470. {
  8471. //DEBUG_INFO("test chargingProfileId \n");
  8472. n_chargingProfile = n_chargingProfile + 1;
  8473. //DEBUG_INFO("chargingProfileId Found\n");
  8474. }
  8475. }
  8476. rewind(fptr1);
  8477. //search Charging Profile Element
  8478. //int i= 0;
  8479. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8480. {
  8481. json_object *tmpProfilee;
  8482. tmpProfilee = json_tokener_parse(sLineWord);
  8483. if(!is_error(tmpProfilee))
  8484. {
  8485. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8486. {
  8487. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8488. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8489. }
  8490. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8491. {
  8492. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8493. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8494. }
  8495. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8496. {
  8497. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8498. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8499. }
  8500. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8501. {
  8502. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8503. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8504. }
  8505. }
  8506. json_object_put(tmpProfilee);
  8507. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8508. {
  8509. //------- not write to fptr2-------//
  8510. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8511. //clearflag = TRUE;
  8512. }
  8513. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8514. {
  8515. //------- not write to fptr2-------//
  8516. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8517. }
  8518. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8519. {
  8520. //------- not write to fptr2-------//
  8521. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8522. }
  8523. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8524. {
  8525. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8526. }
  8527. else
  8528. {
  8529. fprintf(fptr2, sLineWord);//writing data into file
  8530. }
  8531. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8532. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8533. if(clearflag == TRUE)
  8534. {
  8535. fclose(fptr1);
  8536. fclose(fptr2);
  8537. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8538. system(str);
  8539. // clear temp file
  8540. sprintf(str,"rm -f %s",temp);
  8541. system(str);
  8542. }
  8543. else
  8544. {
  8545. fclose(fptr1);
  8546. fclose(fptr2);
  8547. memset(str, 0, ARRAY_SIZE(str));
  8548. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8549. system(str);
  8550. resultRename = rename(temp, chargingProfiles[k]);
  8551. if(resultRename == 0)
  8552. {
  8553. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8554. }
  8555. else
  8556. {
  8557. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8558. }
  8559. if(comfirmstr[0]== 0)
  8560. {
  8561. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8562. }
  8563. //Check chargingProfile is empty file
  8564. /*------ Read the file ----------------*/
  8565. fptr1=fopen(chargingProfiles[k],"r");
  8566. ch=fgetc(fptr1);
  8567. rewind(fptr1);
  8568. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8569. if(ch!=EOF)
  8570. {
  8571. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8572. {
  8573. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8574. if(sLineWord[0]=='\0')
  8575. {
  8576. isEmptyFile = TRUE;
  8577. break;
  8578. }
  8579. else
  8580. {
  8581. isEmptyFile = FALSE;
  8582. break;
  8583. }
  8584. }
  8585. }
  8586. else
  8587. isEmptyFile = TRUE;
  8588. fclose(fptr1);
  8589. if(isEmptyFile == TRUE)
  8590. {
  8591. memset(str, 0, ARRAY_SIZE(str));
  8592. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8593. system(str);
  8594. }
  8595. }
  8596. }// End of while(int k=0; k < ChargePointCount; k++)
  8597. }
  8598. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8599. {
  8600. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8601. for(int k=0; k < ChargeProfileCount; k++)
  8602. {
  8603. fptr1 = fopen(chargingProfiles[k], "r");
  8604. fptr2 = fopen(temp, "w+");
  8605. //Check Charging Profile Count
  8606. while(fscanf(fptr1, "%s", word) != EOF)
  8607. {
  8608. //DEBUG_INFO("word=%s\n",word);
  8609. if(strstr(word, "chargingProfileId")!= NULL)
  8610. {
  8611. n_chargingProfile = n_chargingProfile + 1;
  8612. }
  8613. }
  8614. rewind(fptr1);
  8615. //search Charging Profile Element
  8616. //int i= 0;
  8617. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8618. {
  8619. json_object *tmpProfilee;
  8620. tmpProfilee = json_tokener_parse(sLineWord);
  8621. if(!is_error(tmpProfilee))
  8622. {
  8623. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8624. {
  8625. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8626. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8627. }
  8628. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8629. {
  8630. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8631. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8632. }
  8633. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8634. {
  8635. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8636. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8637. }
  8638. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8639. {
  8640. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8641. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8642. }
  8643. }
  8644. json_object_put(tmpProfilee);
  8645. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8646. {
  8647. //------- not write to fptr2-------//
  8648. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8649. //clearflag = TRUE;
  8650. }
  8651. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8652. {
  8653. //------- not write to fptr2-------//
  8654. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8655. }
  8656. else if(stackLevelIsNULL == TRUE)
  8657. {
  8658. //Clear Whole File
  8659. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8660. clearflag = TRUE;
  8661. break;
  8662. }
  8663. else
  8664. {
  8665. fprintf(fptr2, sLineWord);//writing data into file
  8666. }
  8667. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8668. }
  8669. if(clearflag == TRUE)
  8670. {
  8671. fclose(fptr1);
  8672. fclose(fptr2);
  8673. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8674. system(str);
  8675. // clear temp file
  8676. sprintf(str,"rm -f %s",temp);
  8677. system(str);
  8678. }
  8679. else
  8680. {
  8681. fclose(fptr1);
  8682. fclose(fptr2);
  8683. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8684. system(str);
  8685. resultRename = rename(temp, chargingProfiles[k]);
  8686. if(resultRename == 0)
  8687. {
  8688. DEBUG_INFO("File ChargingProfile renamed successfully");
  8689. }
  8690. else
  8691. {
  8692. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8693. }
  8694. if(comfirmstr[0]== 0)
  8695. {
  8696. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8697. }
  8698. //Check chargingProfile is empty file
  8699. /*------ Read the file ----------------*/
  8700. fptr1=fopen(chargingProfiles[k],"r");
  8701. ch=fgetc(fptr1);
  8702. rewind(fptr1);
  8703. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8704. if(ch!=EOF)
  8705. {
  8706. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8707. {
  8708. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8709. if(sLineWord[0]=='\0')
  8710. {
  8711. isEmptyFile = TRUE;
  8712. break;
  8713. }
  8714. else
  8715. {
  8716. isEmptyFile = FALSE;
  8717. break;
  8718. }
  8719. }
  8720. }
  8721. else
  8722. isEmptyFile = TRUE;
  8723. fclose(fptr1);
  8724. if(isEmptyFile == TRUE)
  8725. {
  8726. memset(str, 0, ARRAY_SIZE(str));
  8727. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8728. system(str);
  8729. }
  8730. /*------- End of reading ---------------*/
  8731. }
  8732. } // while(int k=0; k < ChargeProfileCount; k++)
  8733. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8734. end:
  8735. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8736. {
  8737. if(connectorIdInt == 0)
  8738. {
  8739. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8740. {
  8741. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8742. }
  8743. }
  8744. else
  8745. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8746. }
  8747. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8748. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8749. return result;
  8750. }
  8751. void createFirmwareVersionByDataTransfer(void)
  8752. {
  8753. json_object *FirmwareDataTransfer = json_object_new_object();
  8754. // AC & DC model
  8755. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8756. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8757. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8758. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8759. // DC model
  8760. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8761. {
  8762. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8763. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8764. (gunType[3] != GUN_TYPE_UNKNOWN))
  8765. {
  8766. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8767. }
  8768. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8769. {
  8770. // DS DM DW
  8771. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8772. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8773. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8774. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8775. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8776. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8777. }
  8778. else
  8779. {
  8780. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8781. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8782. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8783. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8784. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8785. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8786. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8787. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8788. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8789. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8790. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8791. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8792. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8793. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8794. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8795. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8796. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8797. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8798. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8799. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8800. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8801. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8802. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8803. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8804. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8805. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8806. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8807. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8808. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8809. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8810. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8811. }
  8812. }
  8813. // 4G model
  8814. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8815. {
  8816. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8817. }
  8818. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8819. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8820. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8821. json_object_put(FirmwareDataTransfer);
  8822. }
  8823. int handleDataTransferRequest(char *uuid, char *payload)
  8824. {
  8825. mtrace();
  8826. json_object *response = json_object_new_object();
  8827. int result = FAIL;
  8828. char tempvendorId[255]={0};
  8829. char tempmessageId[50]={0};
  8830. char tempdata[512]={0};
  8831. char message[2048]={0};
  8832. DEBUG_INFO("handleDataTransferRequest...\n");
  8833. if((uuid != NULL) && (payload != NULL))
  8834. {
  8835. json_object *DataTransfer;
  8836. DataTransfer = json_tokener_parse(payload);
  8837. if(!is_error(DataTransfer))
  8838. {
  8839. // Required data
  8840. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8841. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8842. // Optional data
  8843. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8844. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8845. if(json_object_object_get(DataTransfer, "data") != NULL)
  8846. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8847. result = PASS;
  8848. }
  8849. json_object_put(DataTransfer);
  8850. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8851. {
  8852. // Send all moudle firmware version on EVSE
  8853. createFirmwareVersionByDataTransfer();
  8854. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8855. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8856. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8857. json_object_put(response);
  8858. }
  8859. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8860. {
  8861. system("/usr/bin/run_tmate_restart.sh &");
  8862. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8863. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8864. json_object_put(response);
  8865. }
  8866. else if(strstr(tempmessageId, "ID_ChargingPreference") != NULL)
  8867. {
  8868. json_object *data;
  8869. data = json_tokener_parse(tempdata);
  8870. if(!is_error(data))
  8871. {
  8872. if((json_object_object_get(data, "ConnectorId") != NULL) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) > 0) && (json_object_get_int(json_object_object_get(data, "ConnectorId")) <= gunTotalNumber))
  8873. {
  8874. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  8875. memset(&ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  8876. if(json_object_object_get(data, "SOC") != NULL)
  8877. {
  8878. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  8879. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  8880. }
  8881. if(json_object_object_get(data, "Energy") != NULL)
  8882. {
  8883. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  8884. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  8885. }
  8886. if(json_object_object_get(data, "Duration") != NULL)
  8887. {
  8888. ShmOCPP16Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  8889. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  8890. }
  8891. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8892. }
  8893. else
  8894. {
  8895. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8896. json_object_object_add(response, "data", json_object_new_string("Connector id must > 0."));
  8897. }
  8898. }
  8899. else
  8900. {
  8901. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8902. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8903. }
  8904. json_object_put(data);
  8905. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8906. json_object_put(response);
  8907. }
  8908. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8909. {
  8910. json_object *data;
  8911. data = json_tokener_parse(tempdata);
  8912. if(!is_error(data))
  8913. {
  8914. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8915. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8916. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8917. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8918. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8919. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8920. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8921. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8922. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8923. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8924. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8925. }
  8926. else
  8927. {
  8928. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8929. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8930. }
  8931. json_object_put(data);
  8932. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8933. json_object_put(response);
  8934. }
  8935. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8936. {
  8937. json_object *data;
  8938. data = json_tokener_parse(tempdata);
  8939. if(!is_error(data))
  8940. {
  8941. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8942. if(json_object_object_get(data, "idToken") != NULL)
  8943. {
  8944. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8945. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8946. }
  8947. if(json_object_object_get(data, "price") != NULL)
  8948. {
  8949. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8950. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8951. }
  8952. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8953. }
  8954. else
  8955. {
  8956. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8957. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8958. }
  8959. json_object_put(data);
  8960. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8961. json_object_put(response);
  8962. }
  8963. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8964. {
  8965. json_object *data;
  8966. data = json_tokener_parse(tempdata);
  8967. if(!is_error(data))
  8968. {
  8969. if(json_object_object_get(data, "txId") != NULL)
  8970. {
  8971. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8972. for(int idx = 0;idx<gunTotalNumber;idx++)
  8973. {
  8974. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8975. {
  8976. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8977. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8978. if(json_object_object_get(data, "description") != NULL)
  8979. {
  8980. // California pricing V1.0
  8981. DEBUG_INFO("California pricing V1.0\n");
  8982. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8983. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8984. }
  8985. else
  8986. {
  8987. // California pricing V1.1
  8988. DEBUG_INFO("California pricing V1.1\n");
  8989. if(json_object_object_get(data, "timestamp") != NULL)
  8990. {
  8991. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8992. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8993. }
  8994. if(json_object_object_get(data, "meterValue") != NULL)
  8995. {
  8996. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8997. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8998. }
  8999. if(json_object_object_get(data, "cost") != NULL)
  9000. {
  9001. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  9002. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  9003. }
  9004. if(json_object_object_get(data, "state") != NULL)
  9005. {
  9006. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  9007. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  9008. }
  9009. if(json_object_object_get(data, "chargingPrice") != NULL)
  9010. {
  9011. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  9012. {
  9013. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  9014. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  9015. }
  9016. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  9017. {
  9018. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  9019. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  9020. }
  9021. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  9022. {
  9023. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  9024. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  9025. }
  9026. }
  9027. if(json_object_object_get(data, "idlePrice") != NULL)
  9028. {
  9029. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  9030. {
  9031. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  9032. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  9033. }
  9034. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  9035. {
  9036. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  9037. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  9038. }
  9039. }
  9040. if(json_object_object_get(data, "nextPeriod") != NULL)
  9041. {
  9042. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  9043. {
  9044. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9045. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  9046. }
  9047. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  9048. {
  9049. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  9050. {
  9051. 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")));
  9052. 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"));
  9053. }
  9054. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  9055. {
  9056. 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")));
  9057. 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"));
  9058. }
  9059. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  9060. {
  9061. 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")));
  9062. 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"));
  9063. }
  9064. }
  9065. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  9066. {
  9067. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  9068. {
  9069. 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")));
  9070. 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"));
  9071. }
  9072. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  9073. {
  9074. 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")));
  9075. 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"));
  9076. }
  9077. }
  9078. }
  9079. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  9080. {
  9081. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  9082. {
  9083. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9084. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  9085. }
  9086. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  9087. {
  9088. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  9089. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  9090. }
  9091. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  9092. {
  9093. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  9094. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  9095. }
  9096. }
  9097. }
  9098. }
  9099. }
  9100. }
  9101. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9102. }
  9103. else
  9104. {
  9105. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9106. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9107. }
  9108. json_object_put(data);
  9109. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9110. json_object_put(response);
  9111. }
  9112. else if(strstr(tempmessageId, "FinalCost") != NULL)
  9113. {
  9114. json_object *data;
  9115. data = json_tokener_parse(tempdata);
  9116. if(!is_error(data))
  9117. {
  9118. if(json_object_object_get(data, "txId") != NULL)
  9119. {
  9120. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  9121. for(int idx = 0;idx<gunTotalNumber;idx++)
  9122. {
  9123. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  9124. {
  9125. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  9126. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  9127. if(json_object_object_get(data, "description") != NULL)
  9128. {
  9129. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  9130. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  9131. }
  9132. }
  9133. }
  9134. }
  9135. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9136. }
  9137. else
  9138. {
  9139. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9140. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9141. }
  9142. json_object_put(data);
  9143. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9144. json_object_put(response);
  9145. }
  9146. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  9147. {
  9148. json_object *data;
  9149. data = json_tokener_parse(tempdata);
  9150. if(!is_error(data))
  9151. {
  9152. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9153. if(json_object_object_get(data, "Content_Type") != NULL)
  9154. {
  9155. 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))
  9156. {
  9157. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  9158. if(json_object_object_get(data, "Customization_Conent") != NULL)
  9159. {
  9160. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  9161. }
  9162. }
  9163. else
  9164. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9165. }
  9166. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9167. }
  9168. else
  9169. {
  9170. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9171. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9172. }
  9173. json_object_put(data);
  9174. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9175. json_object_put(response);
  9176. }
  9177. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  9178. {
  9179. json_object *data;
  9180. data = json_tokener_parse(tempdata);
  9181. if(!is_error(data))
  9182. {
  9183. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9184. if(json_object_object_get(data, "Page_Index") != NULL)
  9185. {
  9186. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  9187. }
  9188. if(json_object_object_get(data, "Duration") != NULL)
  9189. {
  9190. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  9191. }
  9192. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  9193. }
  9194. else
  9195. {
  9196. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9197. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9198. }
  9199. json_object_put(data);
  9200. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9201. json_object_put(response);
  9202. }
  9203. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  9204. {
  9205. json_object *data;
  9206. data = json_tokener_parse(tempdata);
  9207. if(!is_error(data))
  9208. {
  9209. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  9210. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  9211. {
  9212. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  9213. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  9214. else
  9215. {
  9216. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9217. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9218. }
  9219. }
  9220. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  9221. {
  9222. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  9223. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  9224. else
  9225. {
  9226. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9227. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9228. }
  9229. }
  9230. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  9231. {
  9232. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  9233. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  9234. else
  9235. {
  9236. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9237. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9238. }
  9239. }
  9240. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  9241. {
  9242. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  9243. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  9244. else
  9245. {
  9246. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9247. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9248. }
  9249. }
  9250. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  9251. {
  9252. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  9253. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  9254. else
  9255. {
  9256. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9257. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9258. }
  9259. }
  9260. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  9261. {
  9262. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  9263. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  9264. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  9265. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  9266. else
  9267. {
  9268. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9269. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9270. }
  9271. }
  9272. if(json_object_object_get(data, "isAuthentication") != NULL)
  9273. {
  9274. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  9275. {
  9276. case 0:
  9277. case 1:
  9278. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  9279. break;
  9280. default:
  9281. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9282. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9283. break;
  9284. }
  9285. }
  9286. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  9287. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  9288. }
  9289. else
  9290. {
  9291. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  9292. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  9293. }
  9294. json_object_put(data);
  9295. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  9296. json_object_put(response);
  9297. }
  9298. else
  9299. {
  9300. // Can not find valid message id
  9301. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  9302. }
  9303. }
  9304. else
  9305. {
  9306. // Payload is null
  9307. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  9308. }
  9309. LWS_Send(message);
  9310. return result;
  9311. }
  9312. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  9313. {
  9314. mtrace();
  9315. int result = FAIL;
  9316. int connectorIdInt, durationInt;
  9317. char chargingRateUnitStr[4]={0};
  9318. char comfirmstr[20];
  9319. int confirmPeriods = 0;
  9320. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  9321. json_object *GetCompositeSchedule;
  9322. GetCompositeSchedule = json_tokener_parse(payload);
  9323. if(!is_error(GetCompositeSchedule))
  9324. {
  9325. // Required data
  9326. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  9327. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  9328. else
  9329. connectorIdInt = -1;
  9330. if(json_object_object_get(GetCompositeSchedule, "duration"))
  9331. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  9332. else
  9333. durationInt = 86400;
  9334. // Optional data
  9335. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  9336. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  9337. }
  9338. json_object_put(GetCompositeSchedule);
  9339. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  9340. if((connectorIdInt == 0) ||
  9341. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  9342. {
  9343. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  9344. struct StructChargingProfile tmpProfile[1];
  9345. if(strstr(chargingRateUnitStr, "W") != NULL)
  9346. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  9347. else
  9348. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  9349. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9350. {
  9351. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9352. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9353. }
  9354. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  9355. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  9356. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  9357. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  9358. {
  9359. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  9360. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  9361. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  9362. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  9363. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  9364. {
  9365. confirmPeriods = idx;
  9366. break;
  9367. }
  9368. }
  9369. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  9370. {
  9371. confirmPeriods += 1;
  9372. }
  9373. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  9374. }
  9375. else
  9376. {
  9377. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  9378. }
  9379. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  9380. return result;
  9381. }
  9382. int handleGetConfigurationRequest(char *uuid, char *payload)
  9383. {
  9384. mtrace();
  9385. int result = FAIL;
  9386. int MaxKeySupported = 0;
  9387. int n_keys = 0;
  9388. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  9389. DEBUG_INFO("handleGetConfigurationRequest...\n");
  9390. json_object *GetConfiguration;
  9391. GetConfiguration = json_tokener_parse(payload);
  9392. if(!is_error(GetConfiguration))
  9393. {
  9394. // Optional data
  9395. if(json_object_object_get(GetConfiguration, "key") != NULL)
  9396. {
  9397. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  9398. {
  9399. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  9400. n_keys = idx + 1;
  9401. }
  9402. }
  9403. }
  9404. json_object_put(GetConfiguration);
  9405. UnknownKeynum = 0;
  9406. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  9407. MaxKeySupported = GetConfigurationMaxKeysNUM;
  9408. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  9409. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  9410. if(n_keys != 0)
  9411. {
  9412. for(int i=0;i<n_keys;i++)
  9413. {
  9414. getKeyValue(requestKey[i]);
  9415. }
  9416. }
  9417. else
  9418. {
  9419. DEBUG_INFO("There is no key in Message, get all configuration\n");
  9420. getKeyValue("");
  9421. }
  9422. processUnkownKey();
  9423. sendGetConfigurationConfirmation(uuid);
  9424. return result;
  9425. }
  9426. static char fnamePlusPath[100]={0};
  9427. static char fnamePWithNoPath[60]={0};
  9428. void checkUploadLog(void)
  9429. {
  9430. FILE *fp;
  9431. /* Open the command for reading. */
  9432. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  9433. if (fp == NULL) {
  9434. DEBUG_WARN("Failed to run command\n" );
  9435. exit(1);
  9436. }
  9437. int ftppathlen = 0;
  9438. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  9439. int i = 0;
  9440. /* Read the output a line at a time - output it. */
  9441. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  9442. if(i==0)
  9443. {
  9444. ftppathlen = strlen(fnamePlusPath);
  9445. DEBUG_INFO("%s\n", fnamePlusPath);
  9446. fnamePlusPath[ftppathlen]='\0';
  9447. break;
  9448. }
  9449. i= i+1;
  9450. }
  9451. /* close */
  9452. pclose(fp);
  9453. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  9454. {
  9455. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  9456. {
  9457. fnamePlusPath[k]='\0';
  9458. }
  9459. }
  9460. i=1;
  9461. //char fname[60]={0};
  9462. while(i < ftppathlen)
  9463. {
  9464. int len=ftppathlen-i;
  9465. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  9466. {
  9467. DEBUG_INFO("compare '/' all right\n");
  9468. break;
  9469. }
  9470. i=i+1;
  9471. }
  9472. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  9473. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  9474. fnamePWithNoPath[i+1] = '\0';
  9475. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  9476. {
  9477. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  9478. {
  9479. fnamePWithNoPath[j]='\0';
  9480. }
  9481. }
  9482. FILE* fp1 = fopen(fnamePlusPath, "r");
  9483. if (fp1)
  9484. {
  9485. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  9486. // file exists
  9487. fclose(fp1);
  9488. }
  9489. else
  9490. {
  9491. // file doesn't exist
  9492. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9493. }
  9494. }
  9495. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9496. {
  9497. mtrace();
  9498. int result = FAIL;
  9499. time_t CurrentTime;
  9500. struct tm *tm;
  9501. pthread_t th_Status;
  9502. CurrentTime = time(NULL);
  9503. tm = localtime(&CurrentTime);
  9504. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9505. 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);
  9506. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9507. if(!interLock.isGetDiagnosticGoing)
  9508. {
  9509. interLock.isGetDiagnosticGoing = 1;
  9510. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9511. sleep(1);
  9512. }
  9513. else
  9514. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  9515. return result;
  9516. }
  9517. void* GetDiagnosticsProcess(void* data)
  9518. {
  9519. pthread_detach(pthread_self());
  9520. mtrace();
  9521. int retriesInt=0, retryIntervalInt=0;
  9522. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9523. 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};
  9524. int port=0;
  9525. int isSuccess = FALSE;
  9526. char cmdBuf[2048];
  9527. struct tm *tmNow;
  9528. time_t CurrentTime;
  9529. struct tm tmStart;
  9530. struct tm tmStop;
  9531. CurrentTime = time(NULL);
  9532. tmNow=localtime(&CurrentTime);
  9533. uint16_t targetYear, targetMonth;
  9534. json_object *GetDiagnostics;
  9535. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9536. GetDiagnostics = json_tokener_parse(data);
  9537. if(!is_error(GetDiagnostics))
  9538. {
  9539. // Required data
  9540. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9541. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9542. // Optional data
  9543. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9544. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9545. else
  9546. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9547. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9548. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9549. else
  9550. retryIntervalInt = 30;
  9551. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9552. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9553. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9554. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9555. }
  9556. json_object_put(GetDiagnostics);
  9557. // Pack log to compress file
  9558. 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) &&
  9559. (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))
  9560. {
  9561. // Pack system log
  9562. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9563. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9564. targetYear = tmStart.tm_year;
  9565. targetMonth = tmStart.tm_mon;
  9566. do
  9567. {
  9568. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9569. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  9570. if(targetMonth+1>=13)
  9571. {
  9572. targetYear += 1;
  9573. targetMonth = 1;
  9574. }
  9575. else
  9576. {
  9577. targetMonth += 1;
  9578. }
  9579. }while((targetYear < (tmNow->tm_year+1900)) ||
  9580. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9581. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9582. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9583. system(cmdBuf);
  9584. // Pack charging & event log
  9585. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9586. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9587. targetYear = tmStart.tm_year;
  9588. targetMonth = tmStart.tm_mon;
  9589. do
  9590. {
  9591. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9592. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  9593. if(targetMonth+1>=13)
  9594. {
  9595. targetYear += 1;
  9596. targetMonth = 1;
  9597. }
  9598. else
  9599. {
  9600. targetMonth += 1;
  9601. }
  9602. }while((targetYear < (tmNow->tm_year+1900)) ||
  9603. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9604. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9605. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9606. system(cmdBuf);
  9607. // Combine log file
  9608. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9609. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9610. }
  9611. else
  9612. {
  9613. system("exec /root/logPackTools 'log' 6");
  9614. }
  9615. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9616. system(cmdBuf);
  9617. checkUploadLog();
  9618. //****************location*******************/
  9619. if(strcmp(locationstr,"")==0)
  9620. {
  9621. DEBUG_INFO("location is <Empty>!\n");
  9622. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9623. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9624. goto end;
  9625. }
  9626. memset(protocol, 0, ARRAY_SIZE(protocol));
  9627. memset(user, 0, ARRAY_SIZE(user) );
  9628. memset(password, 0, ARRAY_SIZE(password));
  9629. memset(host, 0, ARRAY_SIZE(host));
  9630. memset(path, 0, ARRAY_SIZE(path));
  9631. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9632. memset(host1, 0, ARRAY_SIZE(host1));
  9633. memset(path1, 0, ARRAY_SIZE(path1));
  9634. /*location: ftp://user:password@host:port/path*/
  9635. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9636. if((access(fnamePlusPath,F_OK))!=-1)
  9637. {
  9638. DEBUG_INFO("fnamePlusPath exist.\n");
  9639. }
  9640. else
  9641. {
  9642. DEBUG_INFO("fnamePlusPath not exist!\n");
  9643. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9644. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9645. goto end;
  9646. }
  9647. if(strchr(locationstr,'@')==NULL)
  9648. {
  9649. sscanf(locationstr,
  9650. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9651. protocol, host, &port, path);
  9652. strcpy(user,"anonymous");
  9653. strcpy(password,"");
  9654. }
  9655. else
  9656. {
  9657. //DEBUG_INFO("pch=%s\n", pch);
  9658. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9659. protocol, user, password, host, &port, path);
  9660. }
  9661. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9662. {
  9663. DEBUG_INFO("protocol is not ftp/http ! \n");
  9664. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9665. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9666. goto end;
  9667. }
  9668. if(strncmp(locationstr,"http", 4) == 0)
  9669. {
  9670. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9671. sprintf(ftppath,"/%s", path);
  9672. do
  9673. {
  9674. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9675. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9676. sleep(3);
  9677. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9678. if(!isSuccess)
  9679. {
  9680. DEBUG_INFO("Diagnostics fail.\n");
  9681. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9682. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9683. sleep(retryIntervalInt);
  9684. }
  9685. else
  9686. {
  9687. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9688. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9689. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9690. }
  9691. retriesInt--;
  9692. }while((isSuccess == 0)&&(retriesInt >= 0));
  9693. }
  9694. else
  9695. {
  9696. sscanf(host,"%[^/]%s",host1, path1);
  9697. if(strlen(path) > 0)
  9698. sprintf(ftppath,"/%s", path);
  9699. else
  9700. sprintf(ftppath,"/%s", path1);
  9701. int ftppathlen=strlen(ftppath);
  9702. int i=1;
  9703. char filenametemp[50];
  9704. while(i < ftppathlen)
  9705. {
  9706. int len=ftppathlen-i;
  9707. if(ftppath[len]== 47) // '/' ascll code: 47
  9708. {
  9709. DEBUG_INFO("find '/' all right\n");
  9710. break;
  9711. }
  9712. i=i+1;
  9713. }
  9714. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9715. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9716. filenametemp[i+1] = 0;
  9717. if(port == 0)
  9718. port = 21;
  9719. do
  9720. {
  9721. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9722. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9723. sleep(3);
  9724. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9725. if(!isSuccess)
  9726. {
  9727. DEBUG_INFO("Diagnostics fail.\n");
  9728. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9729. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9730. sleep(retryIntervalInt);
  9731. }
  9732. else
  9733. {
  9734. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9735. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9736. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9737. }
  9738. retriesInt--;
  9739. }while((!isSuccess)&&(retriesInt >= 0));
  9740. }
  9741. end:
  9742. system("rm -f /mnt/*");
  9743. sleep(5);
  9744. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9745. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9746. interLock.isGetDiagnosticGoing = 0;
  9747. pthread_exit(NULL);
  9748. }
  9749. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9750. {
  9751. mtrace();
  9752. int result = FAIL;
  9753. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9754. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9755. {
  9756. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9757. locallistVersion = -1;
  9758. }
  9759. else
  9760. {
  9761. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9762. OCPP_getListVerion();
  9763. }
  9764. //from db.OCPP_getListVerion
  9765. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9766. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9767. sendGetLocalListVersionConfirmation(uuid,"");
  9768. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9769. return result;
  9770. }
  9771. int handleRemoteStartRequestOrg(char *uuid, char *payload)
  9772. {
  9773. mtrace();
  9774. int result = FAIL;
  9775. int connectorIdInt=-1;
  9776. int tempIndex = 0;
  9777. int connectorIdIsNULL, chargingProfileIsNULL;
  9778. char comfirmstr[20]={0};
  9779. char cmdBuf[512];
  9780. json_object *RemoteStartTransaction;
  9781. FILE *fp;
  9782. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9783. if(server_pending == TRUE)
  9784. {
  9785. return 0;
  9786. }
  9787. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9788. RemoteStartTransaction = json_tokener_parse(payload);
  9789. if(!is_error(RemoteStartTransaction))
  9790. {
  9791. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9792. {
  9793. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9794. }
  9795. else
  9796. {
  9797. connectorIdIsNULL = TRUE;
  9798. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9799. {
  9800. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9801. {
  9802. connectorIdIsNULL = FALSE;
  9803. connectorIdInt = (gun_index+1);
  9804. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9805. break;
  9806. }
  9807. }
  9808. }
  9809. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9810. {
  9811. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9812. // Required data
  9813. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9814. // Optional data
  9815. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9816. {
  9817. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9818. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9819. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9820. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9821. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9822. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9823. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9824. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9825. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9826. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9827. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9828. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9829. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9830. {
  9831. 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")));
  9832. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9833. 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"));
  9834. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9835. 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"));
  9836. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9837. 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")));
  9838. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9839. {
  9840. 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++)
  9841. {
  9842. 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"));
  9843. 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"));
  9844. 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)
  9845. 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"));
  9846. }
  9847. }
  9848. }
  9849. }
  9850. else
  9851. {
  9852. chargingProfileIsNULL = TRUE;
  9853. }
  9854. }
  9855. }
  9856. else
  9857. {
  9858. connectorIdIsNULL = TRUE;
  9859. }
  9860. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9861. {
  9862. DEBUG_WARN("Connector id is NULL\n.");
  9863. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9864. goto end;
  9865. }
  9866. /*
  9867. enum _SYSTEM_STATUS
  9868. {
  9869. S_BOOTING = 0,
  9870. S_IDLE, = 1
  9871. S_AUTHORIZING, = 2
  9872. S_REASSIGN_CHECK, = 3
  9873. S_REASSIGN, = 4
  9874. S_PRECHARGE, = 5
  9875. S_PREPARING_FOR_EV, = 6
  9876. S_PREPARING_FOR_EVSE, = 7
  9877. S_CHARGING, = 8
  9878. S_TERMINATING, = 9
  9879. S_COMPLETE, = 10
  9880. S_ALARM, = 11
  9881. S_FAULT = 12
  9882. }
  9883. */
  9884. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9885. {
  9886. //check Transaction active
  9887. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9888. {
  9889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9890. {
  9891. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9892. }
  9893. else
  9894. {
  9895. tempIndex = connectorIdInt -1;
  9896. }
  9897. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9898. {
  9899. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9900. {
  9901. 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))
  9902. {
  9903. //Reserved
  9904. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9905. }
  9906. 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))
  9907. {
  9908. //Reserved
  9909. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9910. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9911. goto end;
  9912. }
  9913. else
  9914. {
  9915. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9916. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9917. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9918. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9919. {
  9920. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9921. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9922. goto end;
  9923. }
  9924. }//END FOR ELSE
  9925. }
  9926. }// END FOR CHAdeMO_QUANTITY
  9927. }
  9928. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9929. {
  9930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9931. {
  9932. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9933. }
  9934. else
  9935. {
  9936. tempIndex = connectorIdInt -1;
  9937. }
  9938. for (int index = 0; index < CCS_QUANTITY; index++)
  9939. {
  9940. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9941. {
  9942. 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))
  9943. {
  9944. //Reserved
  9945. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9946. }
  9947. 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))
  9948. {
  9949. //Reserved
  9950. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9951. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9952. goto end;
  9953. }
  9954. else
  9955. {
  9956. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9957. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9958. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9959. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9960. {
  9961. DEBUG_WARN("CCS connector not allow start\n.");
  9962. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9963. goto end;
  9964. }
  9965. }// END FOR ELSE
  9966. }
  9967. }// END FOR CCS_QUANTITY
  9968. }
  9969. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9970. {
  9971. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9972. {
  9973. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9974. }
  9975. else
  9976. {
  9977. tempIndex = connectorIdInt -1;
  9978. }
  9979. for (int index = 0; index < GB_QUANTITY; index++)
  9980. {
  9981. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9982. {
  9983. 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))
  9984. {
  9985. //Reserved
  9986. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9987. }
  9988. 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))
  9989. {
  9990. //Reserved
  9991. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9992. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9993. goto end;
  9994. }
  9995. else
  9996. {
  9997. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9998. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9999. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10000. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10001. {
  10002. DEBUG_WARN("GB connector not allow start\n.");
  10003. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10004. goto end;
  10005. }
  10006. }// END FOR ELSE
  10007. }
  10008. } // END FOR GB_QUANTITY
  10009. }
  10010. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10011. {
  10012. tempIndex = connectorIdInt -1;
  10013. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10014. {
  10015. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10016. {
  10017. 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))
  10018. {
  10019. //Reserved
  10020. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10021. }
  10022. 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))
  10023. {
  10024. //Reserved
  10025. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10026. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10027. goto end;
  10028. }
  10029. else
  10030. {
  10031. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10032. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10033. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10034. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10035. {
  10036. DEBUG_WARN("GB connector not allow start\n.");
  10037. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10038. goto end;
  10039. }
  10040. }// END FOR ELSE
  10041. }
  10042. } // END FOR GB_QUANTITY
  10043. }
  10044. else
  10045. {
  10046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10047. {
  10048. tempIndex = 2;
  10049. }
  10050. else
  10051. {
  10052. tempIndex = connectorIdInt -1;
  10053. }
  10054. for (int index = 0; index < AC_QUANTITY; index++)
  10055. {
  10056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10057. {
  10058. 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))
  10059. {
  10060. //Reserved
  10061. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  10062. }
  10063. 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))
  10064. {
  10065. //Reserved
  10066. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  10067. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10068. goto end;
  10069. }
  10070. else
  10071. {
  10072. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10073. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10074. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10075. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10076. {
  10077. DEBUG_WARN("AC connector not allow start\n.");
  10078. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10079. goto end;
  10080. }
  10081. }//END FOR ELSE
  10082. }
  10083. }// END FOR AC_QUANTITY
  10084. }
  10085. if(chargingProfileIsNULL == FALSE)
  10086. {
  10087. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10088. {
  10089. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10090. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10091. //memset idTag
  10092. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10093. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10094. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10095. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10096. // Save profile to file
  10097. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10098. system(cmdBuf);
  10099. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10100. fp = fopen(cmdBuf, "w");
  10101. 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));
  10102. fclose(fp);
  10103. }
  10104. else
  10105. {
  10106. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  10107. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10108. }
  10109. }
  10110. else
  10111. {
  10112. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10113. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10114. //memset idTag
  10115. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10116. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10117. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10118. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10119. }
  10120. }
  10121. else
  10122. {
  10123. DEBUG_WARN("Connector id over\n.");
  10124. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10125. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10126. }
  10127. end:
  10128. json_object_put(RemoteStartTransaction);
  10129. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  10130. {
  10131. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  10132. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  10133. }
  10134. //OCPP send RemoteStartConfirmation by first.
  10135. sendRemoteStartConfirmation(uuid, comfirmstr);
  10136. return result;
  10137. }
  10138. int handleRemoteStartRequest(char *uuid, char *payload)
  10139. {
  10140. mtrace();
  10141. int result = PASS;
  10142. int connectorIdInt=-1;
  10143. int tempIndex = 0;
  10144. char comfirmstr[20]={0};
  10145. char cmdBuf[512];
  10146. json_object *RemoteStartTransaction;
  10147. FILE *fp;
  10148. DEBUG_INFO("handleRemoteStartRequest ...\n");
  10149. if(server_pending == TRUE)
  10150. {
  10151. result = FAIL;
  10152. }
  10153. RemoteStartTransaction = json_tokener_parse(payload);
  10154. if(!is_error(RemoteStartTransaction))
  10155. {
  10156. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  10157. {
  10158. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  10159. }
  10160. else
  10161. {
  10162. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10163. {
  10164. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  10165. {
  10166. connectorIdInt = (gun_index+1);
  10167. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  10168. break;
  10169. }
  10170. }
  10171. }
  10172. if(connectorIdInt == 0)
  10173. {
  10174. DEBUG_WARN("Connector id shall not equal 0.\n");
  10175. result = FAIL;
  10176. }
  10177. else if(connectorIdInt == -1)
  10178. {
  10179. DEBUG_INFO("Connector id does not specific.\n");
  10180. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10181. {
  10182. memset(&ShmOCPP16Data->RemoteStartTransaction[gun_index], 0x00, sizeof(struct StructRemoteStartTransaction));
  10183. // Required data
  10184. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10185. // Optional data
  10186. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10187. {
  10188. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10189. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10190. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10191. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10192. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10193. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10194. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10195. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10196. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10197. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10198. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10199. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10200. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10201. {
  10202. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  10203. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10204. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  10205. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10206. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  10207. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10208. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  10209. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10210. {
  10211. 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++)
  10212. {
  10213. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10214. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10215. 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)
  10216. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10217. }
  10218. }
  10219. }
  10220. }
  10221. else
  10222. {
  10223. ShmOCPP16Data->RemoteStartTransaction[gun_index].ChargingProfile.ChargingProfileId = -1;
  10224. }
  10225. }
  10226. }
  10227. else if(((0 < connectorIdInt) && (connectorIdInt <= gunTotalNumber)))
  10228. {
  10229. DEBUG_INFO("Connector id: %d\n", connectorIdInt);
  10230. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  10231. // Required data
  10232. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  10233. // Optional data
  10234. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  10235. {
  10236. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  10237. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  10238. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  10239. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  10240. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  10241. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  10242. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  10243. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  10244. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  10245. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  10246. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  10247. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  10248. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  10249. {
  10250. 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")));
  10251. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  10252. 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"));
  10253. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  10254. 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"));
  10255. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  10256. 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")));
  10257. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10258. {
  10259. 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++)
  10260. {
  10261. 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"));
  10262. 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"));
  10263. 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)
  10264. 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"));
  10265. }
  10266. }
  10267. }
  10268. }
  10269. else
  10270. {
  10271. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = -1;
  10272. }
  10273. }
  10274. else
  10275. {
  10276. DEBUG_WARN("Connector id is over maximun value.\n");
  10277. result = FAIL;
  10278. }
  10279. }
  10280. if(result == PASS)
  10281. {
  10282. if(connectorIdInt > 0)
  10283. {
  10284. //check Transaction active
  10285. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10286. {
  10287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10288. {
  10289. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10290. }
  10291. else
  10292. {
  10293. tempIndex = connectorIdInt -1;
  10294. }
  10295. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10296. {
  10297. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10298. {
  10299. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10300. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10301. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10302. {
  10303. //Reserved
  10304. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  10305. }
  10306. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1) &&
  10307. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0) &&
  10308. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10309. {
  10310. //Reserved
  10311. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  10312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10313. goto end;
  10314. }
  10315. else
  10316. {
  10317. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10318. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  10319. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  10320. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  10321. {
  10322. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n");
  10323. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10324. goto end;
  10325. }
  10326. }//END FOR ELSE
  10327. }
  10328. }// END FOR CHAdeMO_QUANTITY
  10329. }
  10330. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10331. {
  10332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10333. {
  10334. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10335. }
  10336. else
  10337. {
  10338. tempIndex = connectorIdInt -1;
  10339. }
  10340. for (int index = 0; index < CCS_QUANTITY; index++)
  10341. {
  10342. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10343. {
  10344. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10345. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10346. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10347. {
  10348. //Reserved
  10349. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  10350. }
  10351. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1) &&
  10352. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0) &&
  10353. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10354. {
  10355. //Reserved
  10356. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  10357. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10358. goto end;
  10359. }
  10360. else
  10361. {
  10362. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10363. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10364. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10365. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10366. {
  10367. DEBUG_WARN("CCS connector not allow start cause busy.\n");
  10368. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10369. goto end;
  10370. }
  10371. }// END FOR ELSE
  10372. }
  10373. }// END FOR CCS_QUANTITY
  10374. }
  10375. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10376. {
  10377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10378. {
  10379. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  10380. }
  10381. else
  10382. {
  10383. tempIndex = connectorIdInt -1;
  10384. }
  10385. for (int index = 0; index < GB_QUANTITY; index++)
  10386. {
  10387. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  10388. {
  10389. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10390. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10391. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10392. {
  10393. //Reserved
  10394. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  10395. }
  10396. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1) &&
  10397. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0) &&
  10398. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10399. {
  10400. //Reserved
  10401. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  10402. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10403. goto end;
  10404. }
  10405. else
  10406. {
  10407. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10408. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10409. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10410. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10411. {
  10412. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  10413. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10414. goto end;
  10415. }
  10416. }// END FOR ELSE
  10417. }
  10418. } // END FOR GB_QUANTITY
  10419. }
  10420. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10421. {
  10422. tempIndex = connectorIdInt -1;
  10423. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10424. {
  10425. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  10426. {
  10427. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10428. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10429. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10430. {
  10431. //Reserved
  10432. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  10433. }
  10434. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1) &&
  10435. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0) &&
  10436. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10437. {
  10438. //Reserved
  10439. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  10440. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10441. goto end;
  10442. }
  10443. else
  10444. {
  10445. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10446. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10447. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10448. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10449. {
  10450. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  10451. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10452. goto end;
  10453. }
  10454. }// END FOR ELSE
  10455. }
  10456. } // END FOR GB_QUANTITY
  10457. }
  10458. else
  10459. {
  10460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10461. {
  10462. tempIndex = 2;
  10463. }
  10464. else
  10465. {
  10466. tempIndex = connectorIdInt -1;
  10467. }
  10468. for (int index = 0; index < AC_QUANTITY; index++)
  10469. {
  10470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  10471. {
  10472. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10473. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10474. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  10475. {
  10476. //Reserved
  10477. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  10478. }
  10479. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1) &&
  10480. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0) &&
  10481. (strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  10482. {
  10483. //Reserved
  10484. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  10485. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10486. goto end;
  10487. }
  10488. else
  10489. {
  10490. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10491. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  10492. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  10493. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  10494. {
  10495. DEBUG_WARN("AC connector not allow start cause busy.\n");
  10496. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10497. goto end;
  10498. }
  10499. }//END FOR ELSE
  10500. }
  10501. }// END FOR AC_QUANTITY
  10502. }
  10503. if(ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId > -1)
  10504. {
  10505. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10506. {
  10507. // Save profile to file
  10508. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10509. system(cmdBuf);
  10510. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10511. fp = fopen(cmdBuf, "w");
  10512. 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));
  10513. fclose(fp);
  10514. }
  10515. else
  10516. {
  10517. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10518. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10519. goto end;
  10520. }
  10521. }
  10522. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  10523. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10524. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  10525. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10526. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  10527. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  10528. }
  10529. else
  10530. {
  10531. uint8_t isHasIdleConnector = FALSE;
  10532. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  10533. {
  10534. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  10535. {
  10536. isHasIdleConnector = TRUE;
  10537. break;
  10538. }
  10539. }
  10540. if(isHasIdleConnector == TRUE)
  10541. {
  10542. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10543. if(ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfileId > -1)
  10544. {
  10545. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[0].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10546. {
  10547. // Save profile to file
  10548. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp.json");
  10549. system(cmdBuf);
  10550. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_Tmp.json");
  10551. fp = fopen(cmdBuf, "w");
  10552. fprintf(fp, "{\"connectorId\":0,\"csChargingProfiles\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  10553. fclose(fp);
  10554. refreshStartTimer(&clientTime.RemoteStartWait);
  10555. ShmOCPP16Data->MsMsg.bits.isRemoteStartWaitReq = 1;
  10556. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10557. }
  10558. else
  10559. {
  10560. DEBUG_WARN("Profile purpose not TxProfile.\n");
  10561. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10562. }
  10563. }
  10564. }
  10565. else
  10566. {
  10567. DEBUG_INFO("There is not any connector is idle.\n");
  10568. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10569. }
  10570. }
  10571. }
  10572. else
  10573. {
  10574. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10575. }
  10576. end:
  10577. json_object_put(RemoteStartTransaction);
  10578. sendRemoteStartConfirmation(uuid, comfirmstr);
  10579. return result;
  10580. }
  10581. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  10582. {
  10583. mtrace();
  10584. int result = FAIL;
  10585. int match = FALSE;
  10586. int GunNO = 0;
  10587. int tempIndex = 0;
  10588. int transactionIdInt=0;
  10589. int transactionIdIsNULL= TRUE;
  10590. char comfirmstr[20];
  10591. json_object *RemoteStopTransaction;
  10592. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  10593. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  10594. if(server_pending == TRUE)
  10595. {
  10596. return 0;
  10597. }
  10598. RemoteStopTransaction = json_tokener_parse(payload);
  10599. if(!is_error(RemoteStopTransaction))
  10600. {
  10601. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  10602. {
  10603. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  10604. transactionIdIsNULL = FALSE;
  10605. }
  10606. }
  10607. json_object_put(RemoteStopTransaction);
  10608. if(transactionIdIsNULL == FALSE)
  10609. {
  10610. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  10611. {
  10612. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  10613. {
  10614. //check Transaction active
  10615. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  10616. {
  10617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10618. {
  10619. tempIndex = ((gun_index==2) ? 1: 0);
  10620. }
  10621. else
  10622. {
  10623. tempIndex = gun_index;
  10624. }
  10625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10626. {
  10627. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10628. {
  10629. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10630. {
  10631. match = TRUE;
  10632. GunNO = gun_index;
  10633. }
  10634. }
  10635. }// END FOR CHAdeMO_QUANTITY
  10636. }
  10637. else if(gunType[gun_index] == GUN_TYPE_CCS)
  10638. {
  10639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10640. {
  10641. tempIndex = ((gun_index==2) ? 1: 0);
  10642. }
  10643. else
  10644. {
  10645. tempIndex = gun_index;
  10646. }
  10647. for (int index = 0; index < CCS_QUANTITY; index++)
  10648. {
  10649. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10650. {
  10651. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10652. {
  10653. match = TRUE;
  10654. GunNO = gun_index;
  10655. }
  10656. }
  10657. }// END FOR CCS_QUANTITY
  10658. }
  10659. else if(gunType[gun_index] == GUN_TYPE_GBT)
  10660. {
  10661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10662. {
  10663. tempIndex = ((gun_index==2) ? 1: 0);
  10664. }
  10665. else
  10666. {
  10667. tempIndex = gun_index;
  10668. }
  10669. for (int index = 0; index < GB_QUANTITY; index++)
  10670. {
  10671. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10672. {
  10673. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10674. {
  10675. match = TRUE;
  10676. GunNO = gun_index;
  10677. }
  10678. }
  10679. }// END FOR GB_QUANTITY
  10680. }
  10681. else if(gunType[gun_index] == GUN_TYPE_DO)
  10682. {
  10683. tempIndex = gun_index;
  10684. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10685. {
  10686. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10687. {
  10688. 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
  10689. {
  10690. match = TRUE;
  10691. GunNO = gun_index;
  10692. }
  10693. }
  10694. }// END FOR GB_QUANTITY
  10695. }
  10696. else
  10697. {
  10698. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10699. {
  10700. tempIndex = 2;
  10701. }
  10702. else
  10703. {
  10704. tempIndex = gun_index;
  10705. }
  10706. for (int index = 0; index < AC_QUANTITY; index++)
  10707. {
  10708. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10709. {
  10710. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  10711. {
  10712. match = TRUE;
  10713. GunNO = gun_index;
  10714. }
  10715. }
  10716. }// END FOR CHAdeMO_QUANTITY
  10717. } // END FOR AC ELSE
  10718. }// CHECK IF ResponseTransactionId == transactionIdInt
  10719. }//END FOR
  10720. if( match == TRUE)
  10721. {
  10722. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  10723. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  10724. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  10725. }
  10726. else
  10727. {
  10728. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10729. }
  10730. }
  10731. else
  10732. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  10733. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  10734. return result;
  10735. }
  10736. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  10737. {
  10738. mtrace();
  10739. int result = FAIL;
  10740. int connectorIdInt=0, reservationIdInt=0;
  10741. int tempIndex = 0;
  10742. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  10743. char comfirmstr[20]={0};
  10744. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  10745. int c = 0;
  10746. char *loc;
  10747. //char *ptr;
  10748. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  10749. strcpy(sstrtemp, stringtrimspace(payload));
  10750. //***(1)connectorId ****/
  10751. c=0;
  10752. loc = strstr(sstrtemp, "connectorId");
  10753. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10754. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  10755. {
  10756. sstr[c] = loc[strlen("connectorId")+2+c];
  10757. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10758. c++;
  10759. }
  10760. sstr[c] = '\0';
  10761. connectorIdInt = atoi(sstr);
  10762. //***(2)expiryDate ****/
  10763. loc = strstr(sstrtemp, "expiryDate");
  10764. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10765. c = 0;
  10766. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  10767. {
  10768. sstr[c] = loc[3+strlen("expiryDate")+c];
  10769. c++;
  10770. }
  10771. sstr[c] = '\0';
  10772. strcpy(expiryDatestr, sstr);
  10773. //***(3)idTag ****/
  10774. loc = strstr(sstrtemp, "idTag");
  10775. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10776. c = 0;
  10777. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  10778. {
  10779. sstr[c] = loc[3+strlen("idTag")+c];
  10780. c++;
  10781. }
  10782. sstr[c] = '\0';
  10783. strcpy(idTagstr, sstr);
  10784. //***(4)parentIdTag ****/
  10785. loc = strstr(sstrtemp, "parentIdTag");
  10786. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10787. c = 0;
  10788. if(loc == NULL)
  10789. {
  10790. strcpy(parentIdTagstr, "");
  10791. }
  10792. else
  10793. {
  10794. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  10795. {
  10796. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10797. c++;
  10798. }
  10799. sstr[c] = '\0';
  10800. strcpy(parentIdTagstr, sstr);
  10801. }
  10802. //***(5)reservationId ****/
  10803. c=0;
  10804. loc = strstr(sstrtemp, "reservationId");
  10805. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10806. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  10807. {
  10808. sstr[c] = loc[strlen("reservationId")+2+c];
  10809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10810. c++;
  10811. }
  10812. sstr[c] = '\0';
  10813. reservationIdInt = atoi(sstr);
  10814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10815. /*
  10816. enum SYSTEM_STATUS
  10817. {
  10818. SYS_MODE_BOOTING = 0,
  10819. SYS_MODE_IDLE = 1,
  10820. SYS_MODE_AUTHORIZING = 2,
  10821. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  10822. SYS_MODE_REASSIGN = 4,
  10823. SYS_MODE_PREPARING = 5,
  10824. SYS_MODE_PREPARE_FOR_EV = 6,
  10825. SYS_MODE_PREPARE_FOR_EVSE = 7,
  10826. SYS_MODE_CHARGING = 8,
  10827. SYS_MODE_TERMINATING = 9,
  10828. SYS_MODE_COMPLETE = 10,
  10829. SYS_MODE_ALARM = 11,
  10830. SYS_MODE_FAULT = 12,
  10831. SYS_MODE_RESERVATION = 13,
  10832. SYS_MODE_BOOKING = 14,
  10833. SYS_MODE_MAINTAIN = 15,
  10834. SYS_MODE_DEBUG = 16,
  10835. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  10836. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  10837. SYS_MODE_UPDATE = 19
  10838. };
  10839. */
  10840. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  10841. {
  10842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10843. goto end;
  10844. }
  10845. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  10846. {
  10847. //check Transaction active
  10848. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10849. {
  10850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10851. {
  10852. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10853. }
  10854. else
  10855. {
  10856. tempIndex = connectorIdInt -1;
  10857. }
  10858. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10859. {
  10860. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10861. {
  10862. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10863. {
  10864. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10865. {
  10866. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10867. {
  10868. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10869. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10870. }
  10871. 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'))
  10872. {
  10873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10874. }
  10875. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10876. {
  10877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10878. }
  10879. else
  10880. {
  10881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10882. }
  10883. }
  10884. 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
  10885. {
  10886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10887. }
  10888. }
  10889. else
  10890. {
  10891. //replace reservation
  10892. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10893. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10894. }
  10895. }
  10896. } // END FOR CHAdeMO_QUANTITY
  10897. }
  10898. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10899. {
  10900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10901. {
  10902. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10903. }
  10904. else
  10905. {
  10906. tempIndex = connectorIdInt -1;
  10907. }
  10908. for (int index = 0; index < CCS_QUANTITY; index++)
  10909. {
  10910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10911. {
  10912. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10913. {
  10914. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10915. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  10916. {
  10917. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10918. {
  10919. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10921. }
  10922. 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'))
  10923. {
  10924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10925. }
  10926. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  10927. {
  10928. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10929. }
  10930. else
  10931. {
  10932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10933. }
  10934. }
  10935. 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
  10936. {
  10937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10938. }
  10939. }
  10940. else
  10941. {
  10942. //replace reservation
  10943. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10944. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10945. }
  10946. }
  10947. } // END FOR CCS_QUANTITY
  10948. }
  10949. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10950. {
  10951. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10952. {
  10953. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10954. }
  10955. else
  10956. {
  10957. tempIndex = connectorIdInt -1;
  10958. }
  10959. for (int index = 0; index < GB_QUANTITY; index++)
  10960. {
  10961. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10962. {
  10963. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10964. {
  10965. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10966. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10967. {
  10968. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10969. {
  10970. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10971. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10972. }
  10973. 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'))
  10974. {
  10975. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10976. }
  10977. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10978. {
  10979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10980. }
  10981. else
  10982. {
  10983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10984. }
  10985. }
  10986. 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
  10987. {
  10988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10989. }
  10990. }
  10991. else
  10992. {
  10993. //replace reservation
  10994. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10995. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10996. }
  10997. }
  10998. }// END FOR GB_QUANTITY
  10999. }
  11000. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11001. {
  11002. tempIndex = connectorIdInt -1;
  11003. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11004. {
  11005. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11006. {
  11007. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11008. {
  11009. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11010. 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
  11011. {
  11012. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11013. {
  11014. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11015. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11016. }
  11017. 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'))
  11018. {
  11019. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11020. }
  11021. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11022. {
  11023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11024. }
  11025. else
  11026. {
  11027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11028. }
  11029. }
  11030. 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
  11031. {
  11032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11033. }
  11034. }
  11035. else
  11036. {
  11037. //replace reservation
  11038. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11039. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11040. }
  11041. }
  11042. }// END FOR GB_QUANTITY
  11043. }
  11044. else
  11045. {
  11046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11047. {
  11048. tempIndex = 2;
  11049. }
  11050. else
  11051. {
  11052. tempIndex = (connectorIdInt -1);
  11053. }
  11054. for (int index = 0; index < AC_QUANTITY; index++)
  11055. {
  11056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11057. {
  11058. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11059. {
  11060. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11061. {
  11062. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11063. {
  11064. 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))
  11065. {
  11066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11067. }
  11068. else
  11069. {
  11070. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11071. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11072. }
  11073. }
  11074. 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'))
  11075. {
  11076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11077. }
  11078. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11079. {
  11080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11081. }
  11082. else
  11083. {
  11084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11085. }
  11086. }
  11087. 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
  11088. {
  11089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11090. }
  11091. }
  11092. else
  11093. {
  11094. //replace reservation
  11095. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  11096. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11097. }
  11098. }
  11099. } // END FOR AC_QUANTITY
  11100. }
  11101. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11102. }
  11103. else if(connectorIdInt == 0)
  11104. {
  11105. //check Transaction active
  11106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11107. {
  11108. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11109. {
  11110. 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'))
  11111. {
  11112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11113. goto end;
  11114. }
  11115. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11116. {
  11117. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11118. goto end;
  11119. }
  11120. 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
  11121. {
  11122. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11123. goto end;
  11124. }
  11125. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11126. {
  11127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11128. goto end;
  11129. }
  11130. }
  11131. }// END FOR CHAdeMO_QUANTITY
  11132. for (int index = 0; index < CCS_QUANTITY; index++)
  11133. {
  11134. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11135. {
  11136. 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'))
  11137. {
  11138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11139. goto end;
  11140. }
  11141. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  11142. {
  11143. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11144. goto end;
  11145. }
  11146. 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
  11147. {
  11148. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11149. goto end;
  11150. }
  11151. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11152. {
  11153. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11154. goto end;
  11155. }
  11156. }
  11157. } // END FOR CCS_QUANTITY
  11158. for (int index = 0; index < GB_QUANTITY; index++)
  11159. {
  11160. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11161. {
  11162. 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'))
  11163. {
  11164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11165. goto end;
  11166. }
  11167. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11168. {
  11169. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11170. goto end;
  11171. }
  11172. 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
  11173. {
  11174. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11175. goto end;
  11176. }
  11177. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11178. {
  11179. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11180. goto end;
  11181. }
  11182. }
  11183. } // END FOR GB_QUANTITY
  11184. for (int index = 0; index < AC_QUANTITY; index++)
  11185. {
  11186. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  11187. {
  11188. 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'))
  11189. {
  11190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  11191. goto end;
  11192. }
  11193. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  11194. {
  11195. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11196. goto end;
  11197. }
  11198. 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
  11199. {
  11200. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  11201. goto end;
  11202. }
  11203. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11204. {
  11205. 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))
  11206. {
  11207. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  11208. goto end;
  11209. }
  11210. }
  11211. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  11212. {
  11213. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11214. goto end;
  11215. }
  11216. }
  11217. }// END FOR AC_QUANTITY
  11218. //The connectorId is 0
  11219. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  11220. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  11221. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  11222. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  11223. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  11224. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  11225. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  11226. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  11227. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  11228. result = TRUE;
  11229. return result;
  11230. }
  11231. else
  11232. {
  11233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  11234. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  11235. }
  11236. if(strcmp(comfirmstr,"Accepted") == 0)
  11237. {
  11238. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  11239. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  11240. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  11241. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  11242. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  11243. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  11244. result = TRUE;
  11245. return result;
  11246. }
  11247. end:
  11248. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  11249. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  11250. return result;
  11251. }
  11252. int handleResetRequest(char *uuid, char *payload)
  11253. {
  11254. mtrace();
  11255. int result = FAIL;
  11256. char sstr[10]={0},sstrtemp[30]={ 0 };
  11257. char typestr[10]={0};
  11258. char comfirmstr[20]={0};
  11259. int c = 0;
  11260. char *loc;
  11261. DEBUG_INFO("handleResetRequest...\n");
  11262. strcpy(sstrtemp, stringtrimspace(payload));
  11263. loc = strstr(sstrtemp, "type");
  11264. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11265. c = 0;
  11266. while (loc[3+strlen("type")+c] != '\"')
  11267. {
  11268. sstr[c] = loc[3+strlen("type")+c];
  11269. c++;
  11270. }
  11271. sstr[c] = '\0';
  11272. strcpy(typestr,sstr);
  11273. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  11274. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  11275. {
  11276. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  11277. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  11278. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  11279. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11280. }
  11281. else
  11282. {
  11283. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  11284. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  11285. result = PASS;
  11286. }
  11287. sendResetConfirmation(uuid, comfirmstr);
  11288. return result;
  11289. }
  11290. int handleSendLocalListRequest(char *uuid, char *payload)
  11291. {
  11292. mtrace();
  11293. int result = FAIL;
  11294. char comfirmstr[20];
  11295. int checkState_Faulted = FALSE;
  11296. json_object *SendLocalList;
  11297. DEBUG_INFO("handleSendLocalListRequest...\n");
  11298. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  11299. {
  11300. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11301. goto end;
  11302. }
  11303. //check Charge Point state
  11304. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11305. {
  11306. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11307. {
  11308. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11309. }
  11310. }
  11311. for (int index = 0; index < CCS_QUANTITY; index++)
  11312. {
  11313. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11314. {
  11315. checkState_Faulted = TRUE; //OCPP Status
  11316. }
  11317. }
  11318. for (int index = 0; index < GB_QUANTITY; index++)
  11319. {
  11320. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11321. {
  11322. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11323. }
  11324. }
  11325. //check Charge Point state
  11326. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11327. {
  11328. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11329. {
  11330. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11331. }
  11332. }
  11333. //check Charge Point state
  11334. for (int index = 0; index < AC_QUANTITY; index++)
  11335. {
  11336. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  11337. {
  11338. checkState_Faulted = TRUE; //OCPP Status: Faulted
  11339. }
  11340. }
  11341. if(checkState_Faulted == TRUE)
  11342. {
  11343. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11344. goto end;
  11345. }
  11346. // Parsing payload
  11347. SendLocalList = json_tokener_parse(payload);
  11348. if(!is_error(SendLocalList))
  11349. {
  11350. // Required data
  11351. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  11352. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  11353. // Optional data
  11354. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  11355. {
  11356. //Check UpdateType
  11357. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11358. {
  11359. //Local list full update
  11360. DEBUG_INFO("Local list full update.\n");
  11361. OCPP_getListVerion();
  11362. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11363. {
  11364. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  11365. goto end;
  11366. }
  11367. OCPP_cleanLocalList();
  11368. }
  11369. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11370. {
  11371. //Local list different update
  11372. DEBUG_INFO("Local list different update.\n");
  11373. OCPP_getListVerion();
  11374. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  11375. {
  11376. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  11377. goto end;
  11378. }
  11379. }
  11380. else
  11381. {
  11382. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  11383. goto end;
  11384. }
  11385. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  11386. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  11387. {
  11388. 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")));
  11389. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  11390. {
  11391. 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")));
  11392. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  11393. 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")));
  11394. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  11395. 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")));
  11396. }
  11397. // Add to db
  11398. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11399. {
  11400. //Local list full update
  11401. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  11402. idx,
  11403. ShmOCPP16Data->SendLocalList.ListVersion,
  11404. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11405. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11406. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11407. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11408. // update list
  11409. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11410. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11411. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11412. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11413. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11414. }
  11415. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11416. {
  11417. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  11418. idx,
  11419. ShmOCPP16Data->SendLocalList.ListVersion,
  11420. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11421. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11422. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11423. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11424. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  11425. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTag,
  11426. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  11427. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  11428. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  11429. }
  11430. }
  11431. }
  11432. else
  11433. {
  11434. //Check UpdateType
  11435. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  11436. {
  11437. //Local list full update
  11438. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  11439. OCPP_cleanLocalList();
  11440. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11441. goto end;
  11442. }
  11443. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  11444. {
  11445. //Local list different update
  11446. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  11447. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11448. goto end;
  11449. }
  11450. }
  11451. result = PASS;
  11452. }
  11453. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  11454. end:
  11455. json_object_put(SendLocalList);
  11456. sendSendLocalListConfirmation(uuid, comfirmstr);
  11457. return result;
  11458. }
  11459. int handleSetChargingProfileRequest(char *uuid, char *payload)
  11460. {
  11461. mtrace();
  11462. int result = FAIL;
  11463. struct StructSetChargingProfile SetProfileReq = {0};
  11464. int tempchargingProfileIdInt;
  11465. int chargingSchedulePeriodCount = 0;
  11466. char comfirmstr[20]={0};
  11467. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  11468. char rmFileCmd[128]={0};
  11469. int profileQuantity = 0;
  11470. json_object *SetChargingProfile;
  11471. DEBUG_INFO("handleSetChargingProfileRequest\n");
  11472. SetChargingProfile = json_tokener_parse(payload);
  11473. if(!is_error(SetChargingProfile))
  11474. {
  11475. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  11476. {
  11477. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  11478. }
  11479. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  11480. {
  11481. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11482. {
  11483. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11484. }
  11485. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11486. {
  11487. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  11488. }
  11489. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11490. {
  11491. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11492. }
  11493. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  11494. {
  11495. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  11496. }
  11497. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  11498. {
  11499. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  11500. }
  11501. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  11502. {
  11503. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  11504. }
  11505. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  11506. {
  11507. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  11508. }
  11509. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  11510. {
  11511. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  11512. }
  11513. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  11514. {
  11515. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  11516. {
  11517. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  11518. }
  11519. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  11520. {
  11521. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  11522. }
  11523. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  11524. {
  11525. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  11526. }
  11527. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  11528. {
  11529. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  11530. }
  11531. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  11532. {
  11533. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  11534. if(chargingSchedulePeriodCount <= 10)
  11535. {
  11536. 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++)
  11537. {
  11538. 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)
  11539. {
  11540. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  11541. }
  11542. 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)
  11543. {
  11544. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  11545. }
  11546. 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)
  11547. {
  11548. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  11549. }
  11550. }
  11551. }
  11552. }
  11553. }
  11554. }
  11555. }
  11556. // Profile periods quantity check
  11557. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  11558. {
  11559. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11560. DEBUG_WARN("Profile period is over limit %s. \n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11561. goto end;
  11562. }
  11563. // Check invalid limit
  11564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  11565. {
  11566. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11567. {
  11568. if(((0 < SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit) && (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit < (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='A'?6:6*220*(SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases)))) ||
  11569. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  11570. {
  11571. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11572. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11573. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11574. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11575. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11576. goto end;
  11577. }
  11578. }
  11579. }
  11580. else
  11581. {
  11582. for(uint8_t idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  11583. {
  11584. if((SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit > (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit[0]=='W'?modelnameInfo.ratedPower:modelnameInfo.ParsingInfo[0].Current)))
  11585. {
  11586. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11587. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  11588. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit,
  11589. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit,
  11590. (SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases==0?3:SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases));
  11591. goto end;
  11592. }
  11593. }
  11594. }
  11595. // Profile purpose info check
  11596. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11597. {
  11598. FILE *fp;
  11599. char dataLine[4096]={0};
  11600. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  11601. if(SetProfileReq.ConnectorId != 0)
  11602. {
  11603. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11604. DEBUG_WARN("Profile connector id is not 0.\n");
  11605. goto end;
  11606. }
  11607. fp = fopen(ChargePointMaxProfile_JSON, "r");
  11608. if (!fp)
  11609. {
  11610. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  11611. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  11612. }
  11613. else
  11614. {
  11615. while(fscanf(fp, "%s", dataLine) != EOF)
  11616. {
  11617. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11618. {
  11619. profileQuantity += 1;
  11620. }
  11621. }
  11622. }
  11623. fclose(fp);
  11624. }
  11625. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11626. {
  11627. FILE *fp;
  11628. char dataLine[4096]={0};
  11629. char filename[128]={0};
  11630. int tmpProfileQuantity;
  11631. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  11632. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11633. {
  11634. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11635. DEBUG_WARN("Profile connector id is over max gun number.\n");
  11636. goto end;
  11637. }
  11638. if(SetProfileReq.ConnectorId == 0)
  11639. {
  11640. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  11641. {
  11642. tmpProfileQuantity = 0;
  11643. memset(filename, 0, ARRAY_SIZE(filename));
  11644. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11645. fp = fopen(filename, "r");
  11646. if (!fp)
  11647. {
  11648. DEBUG_INFO("%s does not create.\n", filename);
  11649. fp = fopen(filename, "w+");
  11650. }
  11651. else
  11652. {
  11653. while(fscanf(fp, "%s", dataLine) != EOF)
  11654. {
  11655. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11656. {
  11657. tmpProfileQuantity += 1;
  11658. }
  11659. }
  11660. }
  11661. fclose(fp);
  11662. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  11663. }
  11664. }
  11665. else
  11666. {
  11667. memset(filename, 0, ARRAY_SIZE(filename));
  11668. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11669. fp = fopen(filename, "r");
  11670. if (!fp)
  11671. {
  11672. DEBUG_INFO("%s does not create.\n", filename);
  11673. fp = fopen(filename, "w+");
  11674. }
  11675. else
  11676. {
  11677. while(fscanf(fp, "%s", dataLine) != EOF)
  11678. {
  11679. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11680. {
  11681. profileQuantity += 1;
  11682. }
  11683. }
  11684. }
  11685. fclose(fp);
  11686. }
  11687. }
  11688. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  11689. {
  11690. int isMatchTransactiodId= FALSE;
  11691. FILE *fp;
  11692. char dataLine[4096]={0};
  11693. char filename[128]={0};
  11694. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  11695. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  11696. if(SetProfileReq.ConnectorId == 0)
  11697. {
  11698. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11699. DEBUG_WARN("Profile connector id is 0.\n");
  11700. goto end;
  11701. }
  11702. int tempIndex = 0;
  11703. //check Transaction active
  11704. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  11705. {
  11706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11707. {
  11708. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11709. }
  11710. else
  11711. {
  11712. tempIndex = SetProfileReq.ConnectorId -1;
  11713. }
  11714. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11715. {
  11716. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11717. {
  11718. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11719. {
  11720. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11721. {
  11722. isMatchTransactiodId = TRUE;
  11723. break;
  11724. }
  11725. }
  11726. }
  11727. }
  11728. }
  11729. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  11730. {
  11731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11732. {
  11733. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11734. }
  11735. else
  11736. {
  11737. tempIndex = SetProfileReq.ConnectorId -1;
  11738. }
  11739. for (int index = 0; index < CCS_QUANTITY; index++)
  11740. {
  11741. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11742. {
  11743. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) ||
  11744. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11745. {
  11746. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11747. {
  11748. isMatchTransactiodId = TRUE;
  11749. break;
  11750. }
  11751. }
  11752. }
  11753. }
  11754. }
  11755. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  11756. {
  11757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11758. {
  11759. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  11760. }
  11761. else
  11762. {
  11763. tempIndex = SetProfileReq.ConnectorId -1;
  11764. }
  11765. for (int index = 0; index < GB_QUANTITY; index++)
  11766. {
  11767. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11768. {
  11769. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  11770. {
  11771. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11772. {
  11773. isMatchTransactiodId = TRUE;
  11774. break;
  11775. }
  11776. }
  11777. }
  11778. }
  11779. }
  11780. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  11781. {
  11782. tempIndex = SetProfileReq.ConnectorId -1;
  11783. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11784. {
  11785. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11786. {
  11787. if(((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) ||
  11788. ((SYS_MODE_CCS_PRECHARGE_STEP0 <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1))) // S_CHARGING
  11789. {
  11790. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11791. {
  11792. isMatchTransactiodId = TRUE;
  11793. break;
  11794. }
  11795. }
  11796. }
  11797. }
  11798. }
  11799. else
  11800. {
  11801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11802. {
  11803. tempIndex = 2;
  11804. }
  11805. else
  11806. {
  11807. tempIndex = (SetProfileReq.ConnectorId -1);
  11808. }
  11809. for (int index = 0; index < AC_QUANTITY; index++)
  11810. {
  11811. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11812. {
  11813. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  11814. {
  11815. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16Data->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  11816. {
  11817. isMatchTransactiodId = TRUE;
  11818. break;
  11819. }
  11820. }
  11821. }
  11822. }
  11823. }
  11824. //check Transaction active
  11825. if(isMatchTransactiodId == FALSE)
  11826. {
  11827. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11828. DEBUG_WARN("Tx profile transaction id is not match.\n");
  11829. goto end;
  11830. }
  11831. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  11832. {
  11833. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11834. DEBUG_WARN("Connector id is over max gun number.\n");
  11835. goto end;
  11836. }
  11837. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11838. fp = fopen(filename, "r");
  11839. if (!fp)
  11840. {
  11841. DEBUG_INFO("%s does not create.\n", filename);
  11842. fp = fopen(filename, "w+");
  11843. }
  11844. else
  11845. {
  11846. //Check Charging Profile Count
  11847. while(fscanf(fp, "%s", dataLine) != EOF)
  11848. {
  11849. //DEBUG_INFO("word=%s\n",word);
  11850. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11851. {
  11852. profileQuantity += 1;
  11853. }
  11854. }
  11855. }
  11856. fclose(fp);
  11857. }
  11858. // Check ChargeProfileMaxStackLevel
  11859. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  11860. if(profileQuantity >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11861. {
  11862. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11863. DEBUG_WARN("Purpose profile quantify is over stack limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11864. goto end;
  11865. }
  11866. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11867. {
  11868. FILE *fp;
  11869. char dataLine[4096]={0};
  11870. char fnametemp[128]={0};
  11871. int tmpProfileQuantity;
  11872. //Check ChargePointMaxProfile.json exit
  11873. profileQuantity = 0;
  11874. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11875. {
  11876. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11877. //Check Charging Profile Count
  11878. tmpProfileQuantity = 0;
  11879. while(fscanf(fp, "%s", dataLine) != EOF)
  11880. {
  11881. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11882. {
  11883. profileQuantity += 1;
  11884. tmpProfileQuantity += 1;
  11885. }
  11886. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11887. }
  11888. fclose(fp);
  11889. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  11890. }
  11891. //Check TxDefaultProfile_%d.json
  11892. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11893. {
  11894. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11895. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11896. if((access(fnametemp,F_OK))!=-1)
  11897. {
  11898. fp = fopen(fnametemp, "r");
  11899. //Check Charging Profile Count
  11900. tmpProfileQuantity = 0;
  11901. while(fscanf(fp, "%s", dataLine) != EOF)
  11902. {
  11903. //DEBUG_INFO("word=%s\n",word);
  11904. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11905. {
  11906. profileQuantity += 1;
  11907. tmpProfileQuantity += 1;
  11908. }
  11909. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11910. }
  11911. fclose(fp);
  11912. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11913. }
  11914. }
  11915. //Check TxProfile_%d.json
  11916. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  11917. {
  11918. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11919. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  11920. if((access(fnametemp,F_OK))!=-1)
  11921. {
  11922. fp = fopen(fnametemp, "r");
  11923. //Check Charging Profile Count
  11924. tmpProfileQuantity = 0;
  11925. while(fscanf(fp, "%s", dataLine) != EOF)
  11926. {
  11927. if(strstr(dataLine, "chargingProfileId")!= NULL)
  11928. {
  11929. profileQuantity += 1;
  11930. tmpProfileQuantity += 1;
  11931. }
  11932. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  11933. }
  11934. fclose(fp);
  11935. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  11936. }
  11937. }
  11938. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  11939. if(profileQuantity > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11940. {
  11941. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11942. DEBUG_WARN("Total profile quantify is over installed limit %s.\n", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11943. goto end;
  11944. }
  11945. }
  11946. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11947. //**********************************Write to File********************************************************/
  11948. {
  11949. FILE *infile;
  11950. FILE *outfile;
  11951. char dataLine[4096]={0};
  11952. char filename[128]={0};
  11953. int chkChar=0;
  11954. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  11955. {
  11956. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  11957. {
  11958. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  11959. }
  11960. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  11961. {
  11962. if(SetProfileReq.ConnectorId==0)
  11963. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  11964. else
  11965. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  11966. }
  11967. else
  11968. {
  11969. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  11970. }
  11971. infile = fopen (filename, "r");
  11972. outfile = fopen (tempfile, "w");
  11973. chkChar = fgetc(infile);
  11974. rewind(infile);
  11975. if(chkChar == EOF)
  11976. {
  11977. // Profile is empty
  11978. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  11979. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  11980. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11981. fclose(infile);
  11982. fclose(outfile);
  11983. sprintf(rmFileCmd,"rm -f %s",filename);
  11984. system(rmFileCmd);
  11985. rename(tempfile, filename);
  11986. }
  11987. else
  11988. {
  11989. // Profile is not empty
  11990. int ChargingProfileAdded = FALSE;
  11991. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  11992. {
  11993. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  11994. json_object *tmpChargingProfile;
  11995. tmpChargingProfile = json_tokener_parse(dataLine);
  11996. if(!is_error(SetChargingProfile))
  11997. {
  11998. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11999. {
  12000. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12001. {
  12002. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12003. }
  12004. }
  12005. }
  12006. json_object_put(tmpChargingProfile);
  12007. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  12008. {
  12009. if(ChargingProfileAdded == FALSE)
  12010. {
  12011. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12012. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12013. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12014. ChargingProfileAdded = TRUE;
  12015. }
  12016. }
  12017. else
  12018. {
  12019. fprintf(outfile,"%s\n",dataLine);
  12020. if(ChargingProfileAdded == FALSE)
  12021. {
  12022. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  12023. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  12024. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  12025. ChargingProfileAdded = TRUE;
  12026. }
  12027. }
  12028. } // end of while loop
  12029. fclose(infile);
  12030. fclose(outfile);
  12031. sprintf(rmFileCmd,"rm -f %s",filename);
  12032. system(rmFileCmd);
  12033. rename(tempfile, filename);
  12034. }
  12035. }
  12036. sleep(1);
  12037. result = TRUE;
  12038. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  12039. }
  12040. end:
  12041. json_object_put(SetChargingProfile);
  12042. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  12043. {
  12044. if(SetProfileReq.ConnectorId == 0)
  12045. {
  12046. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12047. {
  12048. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  12049. }
  12050. }
  12051. else
  12052. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16Data->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  12053. }
  12054. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  12055. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12056. return result;
  12057. }
  12058. int handleTriggerMessageRequest(char *uuid, char *payload)
  12059. {
  12060. mtrace();
  12061. int result = FAIL;
  12062. int connectorIdIsNULL = FALSE;
  12063. int connectorIdInt =0;
  12064. char sstr[40]={0},sstrtemp[100]={ 0 };
  12065. char requestedMessagestr[40]={0};
  12066. char comfirmstr[20]={0};
  12067. int c = 0;
  12068. char *loc;
  12069. DEBUG_INFO("handleTriggerMessageRequest\n");
  12070. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  12071. strcpy(sstrtemp, stringtrimspace(payload));
  12072. c = 0;
  12073. loc = strstr(sstrtemp, "requestedMessage");
  12074. while (loc[3+strlen("requestedMessage")+c] != '\"')
  12075. {
  12076. sstr[c] = loc[3+strlen("requestedMessage")+c];
  12077. c++;
  12078. }
  12079. sstr[c] = '\0';
  12080. strcpy(requestedMessagestr, sstr);
  12081. c = 0;
  12082. loc = strstr(sstrtemp, "connectorId");
  12083. if(loc == NULL)
  12084. {
  12085. connectorIdIsNULL = TRUE;
  12086. }
  12087. else
  12088. {
  12089. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12090. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  12091. {
  12092. sstr[c] = loc[strlen("connectorId")+2+c];
  12093. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12094. c++;
  12095. }
  12096. sstr[c] = '\0';
  12097. connectorIdInt = atoi(sstr);
  12098. }
  12099. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  12100. {
  12101. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  12102. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  12103. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12104. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  12105. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  12106. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  12107. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  12108. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  12109. {
  12110. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12111. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12112. return TRUE;
  12113. }
  12114. else
  12115. {
  12116. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12117. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12118. }
  12119. }
  12120. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  12121. {
  12122. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  12123. sendTriggerMessageConfirmation(uuid,comfirmstr);
  12124. return TRUE;
  12125. }
  12126. //==========================
  12127. // Trigger message
  12128. //==========================
  12129. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12130. {
  12131. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12132. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12133. {
  12134. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12135. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12136. }
  12137. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12138. }
  12139. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  12140. {
  12141. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  12142. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  12143. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  12144. }
  12145. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  12146. {
  12147. //sendBootNotificationRequest();
  12148. server_sign = FALSE;
  12149. }
  12150. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  12151. {
  12152. refreshStartTimer(&clientTime.Heartbeat);
  12153. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12154. }
  12155. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  12156. {
  12157. if(connectorIdIsNULL == FALSE)
  12158. {
  12159. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  12160. {
  12161. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  12162. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  12163. }
  12164. }
  12165. else
  12166. {
  12167. for(int idx=0;idx< gunTotalNumber;idx++)
  12168. {
  12169. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12170. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12171. }
  12172. }
  12173. }
  12174. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  12175. {
  12176. if(connectorIdIsNULL == FALSE)
  12177. {
  12178. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  12179. {
  12180. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  12181. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  12182. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  12183. }
  12184. }
  12185. else
  12186. {
  12187. for(int idx=0;idx< gunTotalNumber;idx++)
  12188. {
  12189. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  12190. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  12191. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  12192. }
  12193. }
  12194. }
  12195. return result;
  12196. }
  12197. int handleUnlockConnectorRequest(char *uuid, char *payload)
  12198. {
  12199. mtrace();
  12200. int result = FAIL;
  12201. int connectorIdInt =0;
  12202. char comfirmstr[20]={0};
  12203. int tempIndex = 0;
  12204. json_object *UnlockConnector;
  12205. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  12206. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  12207. UnlockConnector = json_tokener_parse(payload);
  12208. if(!is_error(UnlockConnector))
  12209. {
  12210. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  12211. {
  12212. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  12213. }
  12214. }
  12215. json_object_put(UnlockConnector);
  12216. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  12217. if(gunTotalNumber == 0)
  12218. {
  12219. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12220. goto end;
  12221. }
  12222. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  12223. {
  12224. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12225. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  12226. goto end;
  12227. }
  12228. else
  12229. {
  12230. //check Transaction active
  12231. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  12232. {
  12233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12234. {
  12235. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12236. }
  12237. else
  12238. {
  12239. tempIndex = connectorIdInt -1;
  12240. }
  12241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12242. {
  12243. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  12244. {
  12245. //stop Transaction
  12246. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12247. }
  12248. }
  12249. }
  12250. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  12251. {
  12252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12253. {
  12254. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12255. }
  12256. else
  12257. {
  12258. tempIndex = connectorIdInt -1;
  12259. }
  12260. for (int index = 0; index < CCS_QUANTITY; index++)
  12261. {
  12262. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  12263. {
  12264. //stop Transaction
  12265. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12266. }
  12267. }
  12268. }
  12269. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  12270. {
  12271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12272. {
  12273. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12274. }
  12275. else
  12276. {
  12277. tempIndex = connectorIdInt -1;
  12278. }
  12279. for (int index = 0; index < GB_QUANTITY; index++)
  12280. {
  12281. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  12282. {
  12283. //stop Transaction
  12284. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12285. }
  12286. }
  12287. }
  12288. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  12289. {
  12290. tempIndex = connectorIdInt -1;
  12291. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12292. {
  12293. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  12294. {
  12295. //stop Transaction
  12296. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12297. }
  12298. }
  12299. }
  12300. else
  12301. {
  12302. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12303. {
  12304. tempIndex = 2;
  12305. }
  12306. else
  12307. {
  12308. tempIndex = connectorIdInt-1;
  12309. }
  12310. for (int index = 0; index < AC_QUANTITY; index++)
  12311. {
  12312. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  12313. {
  12314. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  12315. }
  12316. }
  12317. }
  12318. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  12319. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  12320. result = TRUE;
  12321. return result;
  12322. }
  12323. end:
  12324. //json_object_put(obj); --- remove temporally
  12325. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  12326. return result;
  12327. }
  12328. static char UpdateFirmwarepayloadData[300]={0};
  12329. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  12330. {
  12331. mtrace();
  12332. int result = FAIL;
  12333. pthread_t t;
  12334. sendUpdateFirmwareConfirmation(uuid);
  12335. memset(UpdateFirmwarepayloadData, 0, 300);
  12336. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  12337. if(!interLock.isUpdateFirmwareGoing)
  12338. {
  12339. interLock.isUpdateFirmwareGoing = 1;
  12340. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  12341. sleep(1);
  12342. }
  12343. else
  12344. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  12345. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  12346. return result;
  12347. }
  12348. void *UpdateFirmwareProcess(void *data)
  12349. {
  12350. pthread_detach(pthread_self());
  12351. mtrace();
  12352. int retriesInt =0, retryIntervalInt=0;
  12353. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  12354. int port=0;
  12355. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  12356. int isSuccess = 0;
  12357. char ftpbuf[1024];
  12358. char temp[1024];
  12359. char * pch;
  12360. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  12361. json_object *UpdateFirmware;
  12362. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  12363. if(!is_error(UpdateFirmware))
  12364. {
  12365. // Required data
  12366. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  12367. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  12368. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  12369. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  12370. // Optional data
  12371. if(json_object_object_get(UpdateFirmware, "retries"))
  12372. {
  12373. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  12374. }
  12375. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  12376. {
  12377. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  12378. }
  12379. }
  12380. json_object_put(UpdateFirmware);
  12381. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12382. memset(path, 0, ARRAY_SIZE(path));
  12383. // Wait retrieveData
  12384. if(strlen(retrieveDatestr) > 10)
  12385. {
  12386. do
  12387. {
  12388. sleep(1);
  12389. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  12390. }
  12391. // Ready to download
  12392. system("rm -f /mnt/*");
  12393. if(strncmp(locationstr,"http", 4) == 0)
  12394. {
  12395. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12396. sprintf(ftppath,"/%s", path);
  12397. DEBUG_INFO("locationstr: %s\n", locationstr);
  12398. DEBUG_INFO("protocol: %s\n",protocol);
  12399. DEBUG_INFO("host: %s\n",host);
  12400. DEBUG_INFO("path: %s\n",path);
  12401. DEBUG_INFO("ftppath: %s\n",ftppath);
  12402. int ftppathlen=strlen(ftppath);
  12403. int i=1;
  12404. char filenametemp[50];
  12405. while(i < ftppathlen)
  12406. {
  12407. int len=ftppathlen-i;
  12408. if(ftppath[len]== 47) // '/' ascll code: 47
  12409. {
  12410. DEBUG_INFO("compare '/' all right\n");
  12411. break;
  12412. }
  12413. i=i+1;
  12414. }
  12415. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12416. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12417. filenametemp[i+1] = 0;
  12418. do
  12419. {
  12420. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12421. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12422. sleep(1);
  12423. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  12424. if(!isSuccess)
  12425. {
  12426. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12427. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12428. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12429. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12430. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12431. }
  12432. else
  12433. {
  12434. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12435. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12436. }
  12437. retriesInt--;
  12438. }while((isSuccess == 0)&&(retriesInt >= 0));
  12439. }
  12440. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  12441. {
  12442. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12443. memset(temp, 0, ARRAY_SIZE(temp));
  12444. //DEBUG_INFO("locationstr=%s\n",locationstr);
  12445. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  12446. int ftppathlen=strlen(ftpbuf);
  12447. int i=1;
  12448. char filenametemp[50];
  12449. while(i < ftppathlen)
  12450. {
  12451. int len=ftppathlen-i;
  12452. if(ftpbuf[len]== 47) // '/' ascll code: 47
  12453. {
  12454. DEBUG_INFO(" compare '/' all right\n");
  12455. break;
  12456. }
  12457. i=i+1;
  12458. }
  12459. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12460. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  12461. filenametemp[i+1] = 0;
  12462. strncpy(temp, ftpbuf, ftppathlen-i+1);
  12463. pch=strchr(temp,'@');
  12464. if(pch==NULL)
  12465. {
  12466. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12467. protocol, host, &port, path);
  12468. strcpy(user,"anonymous");
  12469. strcpy(password,"");
  12470. }
  12471. else
  12472. {
  12473. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12474. protocol, user, password, host, &port, path);
  12475. }
  12476. sscanf(host,"%[^/]%s",host1, path1);
  12477. sprintf(ftppath,"%s", path1);
  12478. //DEBUG_INFO("protocol =%s\n",protocol);
  12479. //DEBUG_INFO("user =%s\n",user);
  12480. //DEBUG_INFO("password =%s\n",password);
  12481. //DEBUG_INFO("host1 =%s\n",host1);
  12482. //DEBUG_INFO("port =%d\n",port);
  12483. //DEBUG_INFO("path1 =%s\n",path1);
  12484. //DEBUG_INFO("ftppath=%s\n",ftppath);
  12485. //ftpFile(host, user, password, port, ftppath, fname);
  12486. //download firmware pthred
  12487. if(port == 0)
  12488. {
  12489. port = 21;
  12490. }
  12491. do
  12492. {
  12493. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  12494. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12495. sleep(1);
  12496. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  12497. if(!isSuccess)
  12498. {
  12499. //BulldogUtil.sleepMs(interval*1000);
  12500. DEBUG_INFO("Update firmware request and download file fail.\n");
  12501. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12502. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12503. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  12504. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12505. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12506. }
  12507. else
  12508. {
  12509. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  12510. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12511. }
  12512. retriesInt--;
  12513. }while((!isSuccess)&&(retriesInt >= 0));
  12514. }
  12515. else
  12516. {
  12517. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  12518. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12519. sleep(1);
  12520. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  12521. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12522. }
  12523. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  12524. interLock.isUpdateFirmwareGoing = 0;
  12525. pthread_exit(NULL);
  12526. }
  12527. int handleCertificateSignedRequest(char *uuid, char *payload)
  12528. {
  12529. mtrace();
  12530. int result = PASS;
  12531. json_object *CertificateSigned;
  12532. DEBUG_INFO("handleCertificateSignedRequest...\n");
  12533. CertificateSigned = json_tokener_parse(payload);
  12534. if(!is_error(CertificateSigned))
  12535. {
  12536. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  12537. }
  12538. json_object_put(CertificateSigned);
  12539. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  12540. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  12541. fclose(fp);
  12542. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12543. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  12544. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  12545. sendCertificateSignedConfirmation(uuid);
  12546. return result;
  12547. }
  12548. int handleDeleteCertificateRequest(char *uuid, char *payload)
  12549. {
  12550. mtrace();
  12551. int result = PASS;
  12552. json_object *DeleteCertificate;
  12553. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  12554. DeleteCertificate = json_tokener_parse(payload);
  12555. if(!is_error(DeleteCertificate))
  12556. {
  12557. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  12558. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  12559. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12560. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12561. }
  12562. json_object_put(DeleteCertificate);
  12563. /*
  12564. * TODO: Delete certificateSigned process
  12565. */
  12566. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  12567. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  12568. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  12569. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  12570. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  12571. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  12572. sendDeleteCertificateConfirmation(uuid);
  12573. return result;
  12574. }
  12575. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  12576. {
  12577. mtrace();
  12578. int result = PASS;
  12579. json_object *ExtendedTriggerMessage;
  12580. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  12581. ExtendedTriggerMessage = json_tokener_parse(payload);
  12582. if(!is_error(ExtendedTriggerMessage))
  12583. {
  12584. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  12585. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  12586. {
  12587. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  12588. }
  12589. else
  12590. {
  12591. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  12592. }
  12593. }
  12594. json_object_put(ExtendedTriggerMessage);
  12595. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  12596. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  12597. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  12598. {
  12599. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  12600. }
  12601. else
  12602. {
  12603. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  12604. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  12605. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  12606. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  12607. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  12608. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  12609. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  12610. {
  12611. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  12612. }
  12613. else
  12614. {
  12615. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  12616. }
  12617. }
  12618. sendExtendedTriggerMessageConfirmation(uuid);
  12619. //==========================
  12620. // Trigger message
  12621. //==========================
  12622. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  12623. {
  12624. //sendBootNotificationRequest();
  12625. server_sign = FALSE;
  12626. }
  12627. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  12628. {
  12629. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  12630. }
  12631. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  12632. {
  12633. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  12634. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  12635. {
  12636. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  12637. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  12638. }
  12639. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  12640. }
  12641. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  12642. {
  12643. refreshStartTimer(&clientTime.Heartbeat);
  12644. clientTime.Heartbeat.tv_sec -= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  12645. }
  12646. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  12647. {
  12648. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12649. {
  12650. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  12651. }
  12652. else
  12653. {
  12654. for(int idx=0;idx< gunTotalNumber;idx++)
  12655. {
  12656. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  12657. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  12658. }
  12659. }
  12660. }
  12661. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  12662. {
  12663. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  12664. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  12665. {
  12666. 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\" &");
  12667. }
  12668. }
  12669. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  12670. {
  12671. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  12672. {
  12673. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  12674. }
  12675. else
  12676. {
  12677. for(int idx=0;idx< gunTotalNumber;idx++)
  12678. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  12679. }
  12680. }
  12681. return result;
  12682. }
  12683. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12684. {
  12685. mtrace();
  12686. int result = PASS;
  12687. json_object *GetInstalledCertificateIds;
  12688. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12689. GetInstalledCertificateIds = json_tokener_parse(payload);
  12690. if(!is_error(GetInstalledCertificateIds))
  12691. {
  12692. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  12693. }
  12694. json_object_put(GetInstalledCertificateIds);
  12695. /*
  12696. * TODO: Return installed certificate process
  12697. */
  12698. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  12699. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  12700. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  12701. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  12702. sendGetInstalledCertificateIdsConfirmation(uuid);
  12703. return result;
  12704. }
  12705. int handleGetLogRequest(char *uuid, char *payload)
  12706. {
  12707. mtrace();
  12708. int result = PASS;
  12709. json_object *GetLog;
  12710. DEBUG_INFO("handleGetLogRequest...\n");
  12711. GetLog = json_tokener_parse(payload);
  12712. if(!is_error(GetLog))
  12713. {
  12714. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12715. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12716. if(json_object_object_get(GetLog, "retries") != NULL)
  12717. {
  12718. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12719. }
  12720. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12721. {
  12722. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12723. }
  12724. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12725. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12726. {
  12727. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12728. }
  12729. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12730. {
  12731. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12732. }
  12733. }
  12734. json_object_put(GetLog);
  12735. /*
  12736. * TODO: Upload log process
  12737. */
  12738. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  12739. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  12740. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  12741. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  12742. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  12743. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  12744. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  12745. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  12746. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  12747. sendGetLogConfirmation(uuid);
  12748. return result;
  12749. }
  12750. int handleInstallCertificateRequest(char *uuid, char *payload)
  12751. {
  12752. mtrace();
  12753. int result = PASS;
  12754. json_object *InstallCertificate;
  12755. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12756. InstallCertificate = json_tokener_parse(payload);
  12757. if(!is_error(InstallCertificate))
  12758. {
  12759. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12760. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12761. /*
  12762. * TODO: Install certificate process
  12763. */
  12764. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  12765. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  12766. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  12767. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  12768. sendInstallCertificateConfirmation(uuid);
  12769. }
  12770. json_object_put(InstallCertificate);
  12771. return result;
  12772. }
  12773. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  12774. {
  12775. mtrace();
  12776. int result = PASS;
  12777. json_object *SignedUpdateFirmware;
  12778. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12779. SignedUpdateFirmware = json_tokener_parse(payload);
  12780. if(!is_error(SignedUpdateFirmware))
  12781. {
  12782. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12783. {
  12784. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12785. }
  12786. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12787. {
  12788. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12789. }
  12790. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12791. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12792. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12793. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12794. {
  12795. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12796. }
  12797. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12798. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12799. }
  12800. json_object_put(SignedUpdateFirmware);
  12801. /*
  12802. * TODO: Upgrade firmware process
  12803. */
  12804. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12805. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12806. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12807. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12808. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12809. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12810. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12811. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12812. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12813. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12814. sendInstallCertificateConfirmation(uuid);
  12815. return result;
  12816. }
  12817. int handleUnknownRequest(char *uuid, char *payload)
  12818. {
  12819. mtrace();
  12820. int result = PASS;
  12821. DEBUG_INFO("handleUnknownRequest...\n");
  12822. sendUnknownConfirmation(uuid);
  12823. result = PASS;
  12824. return result;
  12825. }
  12826. //==========================================
  12827. // Handle server response routine
  12828. //==========================================
  12829. void handleAuthorizeResponse(char *payload, int gun_index)
  12830. {
  12831. mtrace();
  12832. char expiryDatestr[30]={0};
  12833. char parentIdTagstr[20]={0};
  12834. char statusstr[20]={0};
  12835. int expiryDateISNULL=FALSE;
  12836. int parentIdTagISNULL=FALSE;
  12837. DEBUG_INFO("handleAuthorizeResponse...\n");
  12838. json_object *Authorize;
  12839. Authorize = json_tokener_parse(payload);
  12840. if(!is_error(Authorize))
  12841. {
  12842. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12843. {
  12844. // Required data
  12845. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12846. // Optional data
  12847. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12848. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12849. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12850. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12851. }
  12852. }
  12853. json_object_put(Authorize);
  12854. if(expiryDateISNULL == FALSE)
  12855. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12856. if(parentIdTagISNULL == FALSE)
  12857. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12858. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12859. //Update idTag information to authorization cache if supproted
  12860. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12861. {
  12862. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12863. }
  12864. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12865. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12866. authorizeRetryTimes = 0;
  12867. }
  12868. void handleBootNotificationResponse(char *payload, int gun_index)
  12869. {
  12870. mtrace();
  12871. char statusStr[12]={0};
  12872. char currentTimeStr[30]={0};
  12873. int intervalInt = 0;
  12874. DEBUG_INFO("handleBootNotificationResponse...\n");
  12875. json_object *BootNotification;
  12876. BootNotification = json_tokener_parse(payload);
  12877. if(!is_error(BootNotification))
  12878. {
  12879. // Required data
  12880. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12881. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12882. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12883. }
  12884. json_object_put(BootNotification);
  12885. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12886. BootNotificationInterval = intervalInt;
  12887. HeartBeatWaitTime = intervalInt;
  12888. //write back to ShmOCPP16Data->BootNotification
  12889. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12890. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12891. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12892. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12893. {
  12894. server_sign = TRUE;
  12895. server_pending =FALSE;
  12896. }
  12897. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12898. {
  12899. server_pending = TRUE;
  12900. }
  12901. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12902. srand(time(NULL));
  12903. refreshStartTimer(&clientTime.Heartbeat);
  12904. clientTime.Heartbeat.tv_sec -= (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12905. SetOcppConnStatus(TRUE);
  12906. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12907. }
  12908. void handleDataTransferResponse(char *payload, int gun_index)
  12909. {
  12910. char sstr[160]={0};//sstr[200]={ 0 };
  12911. int c = 0;
  12912. char *loc;
  12913. DEBUG_INFO("handleDataTransferResponse ...\n");
  12914. loc = strstr(payload, "status");
  12915. c = 0;
  12916. while (loc[3+strlen("status")+c] != '\"')
  12917. {
  12918. sstr[c] = loc[3+strlen("status")+c];
  12919. c++;
  12920. }
  12921. sstr[c] = '\0';
  12922. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12923. }
  12924. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12925. {
  12926. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12927. //struct json_object *obj;
  12928. // obj = json_tokener_parse(payload);
  12929. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12930. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12931. //No fields are defined.
  12932. }
  12933. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12934. {
  12935. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12936. //struct json_object *obj;
  12937. // obj = json_tokener_parse(payload);
  12938. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12939. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12940. //No fields are defined.
  12941. }
  12942. void handleHeartbeatResponse(char *payload, int gun_index)
  12943. {
  12944. mtrace();
  12945. DEBUG_INFO("handleHeartbeatResponse...\n");
  12946. json_object *Heartbeat;
  12947. Heartbeat = json_tokener_parse(payload);
  12948. if(!is_error(Heartbeat))
  12949. {
  12950. // Required data
  12951. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12952. }
  12953. json_object_put(Heartbeat);
  12954. if(FirstHeartBeat == 0)
  12955. {
  12956. FirstHeartBeat = 1;
  12957. DEBUG_INFO("FirstHeartBeat \n");
  12958. }
  12959. HeartBeatWithNOResponse = 0;
  12960. refreshStartTimer(&clientTime.Heartbeat);
  12961. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12962. }
  12963. void handleMeterValuesResponse(char *payload, int gun_index)
  12964. {
  12965. mtrace();
  12966. DEBUG_INFO("handleMeterValuesResponse...\n");
  12967. isQueueSendable = 1;
  12968. }
  12969. void handleStartTransactionResponse(char *payload, int gun_index)
  12970. {
  12971. mtrace();
  12972. //int transactionIdInt = 0;
  12973. FILE *outfile;
  12974. char data[100]={0};
  12975. DEBUG_INFO("handleStartTransactionResponse...\n");
  12976. json_object *StartTransaction;
  12977. StartTransaction = json_tokener_parse(payload);
  12978. if(!is_error(StartTransaction))
  12979. {
  12980. // Required data
  12981. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12982. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12983. // Optional data
  12984. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12985. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12986. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12987. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12988. }
  12989. json_object_put(StartTransaction);
  12990. isQueueSendable = 1;
  12991. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12992. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12993. //-----------Start : write to the Queue TransactionId file -----------------//
  12994. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12995. {}
  12996. else
  12997. {
  12998. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12999. if(log == NULL)
  13000. {
  13001. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  13002. return ;
  13003. }
  13004. else
  13005. {
  13006. fclose(log);
  13007. }
  13008. }
  13009. // open file for writing
  13010. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  13011. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  13012. {
  13013. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  13014. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  13015. fputs(data, outfile);
  13016. fclose (outfile);
  13017. }
  13018. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13019. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13020. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  13021. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  13022. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13023. }
  13024. void handleStatusNotificationResponse(char *payload, int gun_index)
  13025. {
  13026. mtrace();
  13027. DEBUG_INFO("handleStatusNotificationResponse...\n");
  13028. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  13029. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13030. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  13031. }
  13032. void handleStopTransactionnResponse(char *payload, int gun_index)
  13033. {
  13034. mtrace();
  13035. DEBUG_INFO("handleStopTransactionnResponse...\n");
  13036. json_object *StopTransaction;
  13037. StopTransaction = json_tokener_parse(payload);
  13038. if(!is_error(StopTransaction))
  13039. {
  13040. // Optional data
  13041. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  13042. {
  13043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  13044. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  13045. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  13046. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  13047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  13048. }
  13049. }
  13050. json_object_put(StopTransaction);
  13051. isQueueSendable = 1;
  13052. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  13053. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  13054. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  13055. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  13056. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  13057. SetTransactionIdZero(queueOpInfo.stopTransactionId);
  13058. }
  13059. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  13060. {
  13061. mtrace();
  13062. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  13063. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  13064. }
  13065. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  13066. {
  13067. mtrace();
  13068. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  13069. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  13070. }
  13071. void handleSignCertificateResponse(char *payload, int gun_index)
  13072. {
  13073. mtrace();
  13074. DEBUG_INFO("handleSignCertificateResponse...\n");
  13075. json_object *SignCertificate;
  13076. SignCertificate = json_tokener_parse(payload);
  13077. if(!is_error(SignCertificate))
  13078. {
  13079. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  13080. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  13081. }
  13082. json_object_put(SignCertificate);
  13083. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  13084. }
  13085. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13086. {
  13087. mtrace();
  13088. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  13089. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  13090. }
  13091. //==========================================
  13092. // Handle Error routine
  13093. //==========================================
  13094. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  13095. {
  13096. mtrace();
  13097. #ifdef SystemLogMessage
  13098. DEBUG_INFO("errorCode: %s\n", errorCode);
  13099. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  13100. DEBUG_INFO("errorDetails: %s\n", payload);
  13101. #endif
  13102. }
  13103. //===============================================
  13104. // Common routine
  13105. //===============================================
  13106. int initialConfigurationTable(void)
  13107. {
  13108. //clock_t start_t, end_t, total_t;
  13109. FILE *fp;
  13110. FILE *outfile;
  13111. char str[512]={0};
  13112. char sstr[256]={0};
  13113. int c = 0;
  13114. char *loc;
  13115. int confVersion = 10;
  13116. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  13117. //start_t = clock();
  13118. //printf("Starting of the program, start_t = %ld\n", start_t);
  13119. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  13120. // Check configuration file size is correct
  13121. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  13122. {
  13123. struct stat st;
  13124. stat("/Storage/OCPP/OCPPConfiguration", &st);
  13125. if(st.st_size < 3100)
  13126. {
  13127. system("rm -f /Storage/OCPP/OCPPConfiguration");
  13128. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  13129. }
  13130. }
  13131. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  13132. {
  13133. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13134. if(outfile == NULL)
  13135. {
  13136. DEBUG_INFO("Error opening file\n");
  13137. return FALSE;
  13138. }
  13139. /*Core Profile*/
  13140. //AllowOfflineTxForUnknownId
  13141. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  13144. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13145. //AuthorizationCacheEnabled
  13146. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13150. //AuthorizeRemoteTxRequests
  13151. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  13154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13155. //BlinkRepeat
  13156. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13160. //ClockAlignedDataInterval
  13161. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13165. //ConnectionTimeOut
  13166. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13170. //GetConfigurationMaxKeys
  13171. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13173. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  13174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13175. // HeartbeatInterval
  13176. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  13179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13180. // LightIntensity
  13181. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13185. // LocalAuthorizeOffline
  13186. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  13187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13190. // LocalPreAuthorize
  13191. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  13192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13195. // MaxEnergyOnInvalidId
  13196. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13200. // MeterValuesAlignedData
  13201. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13204. 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" );
  13205. else
  13206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13208. // MeterValuesAlignedDataMaxLength
  13209. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  13213. else
  13214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  13215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13216. // MeterValuesSampledData
  13217. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13220. 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" );
  13221. else
  13222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  13223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13224. // MeterValuesSampledDataMaxLength
  13225. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13227. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  13229. else
  13230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  13231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13232. // MeterValueSampleInterval
  13233. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  13236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13237. // MinimumStatusDuration
  13238. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  13241. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  13242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13243. // NumberOfConnectors
  13244. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13246. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13247. {
  13248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13249. }
  13250. else
  13251. {
  13252. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13253. }
  13254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13255. // ResetRetries
  13256. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13259. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13260. // ConnectorPhaseRotation
  13261. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13265. // ConnectorPhaseRotationMaxLength
  13266. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13270. // StopTransactionOnEVSideDisconnect
  13271. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13275. // StopTransactionOnInvalidId
  13276. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  13277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13280. // StopTxnAlignedData
  13281. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  13282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  13284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13285. // StopTxnAlignedDataMaxLength
  13286. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13290. // StopTxnSampledData
  13291. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13293. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  13295. else
  13296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  13297. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13298. // StopTxnSampledDataMaxLength
  13299. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13301. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13302. {
  13303. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  13304. }
  13305. else
  13306. {
  13307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  13308. }
  13309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13310. // SupportedFeatureProfiles
  13311. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13312. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13314. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13315. // SupportedFeatureProfilesMaxLength
  13316. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13320. // TransactionMessageAttempts
  13321. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13324. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13326. // TransactionMessageRetryInterval
  13327. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13330. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13332. // UnlockConnectorOnEVSideDisconnect
  13333. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13336. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13337. // WebSocketPingInterval
  13338. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13342. // QueueOffLineMeterValues
  13343. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  13344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  13345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  13346. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  13347. // AuthorizationKey
  13348. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13352. // SecurityProfile
  13353. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13355. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13357. // DefaultPrice
  13358. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13362. // CustomDisplayCostAndPrice
  13363. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13367. // CustomIdleFeeAfterStop
  13368. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13372. // TimeOffset
  13373. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  13376. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13377. // NextTimeOffsetTransitionDateTime
  13378. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  13381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13382. // TimeOffsetNextTransition
  13383. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13385. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  13386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13387. // SystemUptimeSec
  13388. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  13389. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  13390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  13391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  13392. // FreeVend
  13393. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  13394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "Free-FreeVend");
  13395. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE") );
  13396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  13397. // Configuration Version
  13398. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  13399. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  13401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13402. //* Local Auth List Management Profile*/
  13403. #if 0
  13404. //For OCTT Test Case
  13405. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13408. #endif
  13409. #if 1
  13410. //LocalAuthListEnabled
  13411. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13413. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13415. #endif
  13416. //LocalAuthListMaxLength
  13417. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  13420. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13421. //SendLocalListMaxLength
  13422. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13423. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13424. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13425. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13426. //ReserveConnectorZeroSupported
  13427. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13430. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13431. //* Smart Charging Profile */
  13432. //ChargeProfileMaxStackLevel
  13433. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13437. // ChargingScheduleAllowedChargingRateUnit
  13438. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13439. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  13441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13442. // ChargingScheduleMaxPeriods
  13443. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13447. // ConnectorSwitch3to1PhaseSupported
  13448. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  13451. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13452. // MaxChargingProfilesInstalled
  13453. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13456. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13457. fclose(outfile);
  13458. }
  13459. else
  13460. {
  13461. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  13462. char keystr[60]={0};
  13463. char readonlystr[10]={0};
  13464. char valuestr[256]={0};
  13465. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  13466. if(fp == NULL) {
  13467. DEBUG_INFO("Error opening file");
  13468. return FALSE;
  13469. }
  13470. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  13471. {
  13472. //DEBUG_INFO("Get Configuration \n");
  13473. if(strlen(str) > 0)
  13474. {
  13475. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13476. //*************************key*********************************/
  13477. if(strstr(str, "key") != NULL)
  13478. {
  13479. loc = strstr(str, "key");
  13480. c = 0;
  13481. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13482. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13483. {
  13484. sstr[c] = loc[strlen("key")+3+c];
  13485. c++;
  13486. }
  13487. sstr[c] = '\0';
  13488. strcpy(keystr,sstr);
  13489. }
  13490. //*************************readonly*********************************/
  13491. if(strstr(str, "readonly") != NULL)
  13492. {
  13493. loc = strstr(str, "readonly");
  13494. c = 0;
  13495. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13496. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  13497. {
  13498. sstr[c] = loc[strlen("readonly")+2+c];
  13499. c++;
  13500. }
  13501. sstr[c] = '\0';
  13502. strcpy(readonlystr,sstr);
  13503. }
  13504. //*************************value*********************************/
  13505. if(strstr(str, "value") != NULL)
  13506. {
  13507. loc = strstr(str, "value");
  13508. c = 0;
  13509. memset(sstr ,0, ARRAY_SIZE(sstr) );
  13510. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  13511. {
  13512. sstr[c] = loc[strlen("value")+3+c];
  13513. c++;
  13514. }
  13515. sstr[c] = '\0';
  13516. strcpy(valuestr,sstr);
  13517. }
  13518. // DEBUG_INFO("keystr=%s\n",keystr);
  13519. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  13520. // DEBUG_INFO("valuestr=%s\n",valuestr);
  13521. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  13522. {
  13523. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13524. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  13526. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13527. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  13528. }
  13529. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  13530. {
  13531. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13532. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  13534. }
  13535. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  13536. {
  13537. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  13539. }
  13540. if(strcmp(keystr, "BlinkRepeat") == 0)
  13541. {
  13542. //Charger.BlinkRepeat = Integer.parseInt(value);
  13543. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  13545. }
  13546. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  13547. {
  13548. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  13550. }
  13551. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  13552. {
  13553. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  13555. }
  13556. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  13557. {
  13558. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  13560. }
  13561. if(strcmp(keystr, "HeartbeatInterval") == 0)
  13562. {
  13563. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  13565. HeartBeatWaitTime = atoi(valuestr);
  13566. }
  13567. if(strcmp(keystr, "LightIntensity") == 0)
  13568. {
  13569. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13570. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  13571. }
  13572. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  13573. {
  13574. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13575. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  13576. }
  13577. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  13578. {
  13579. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  13581. }
  13582. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  13583. {
  13584. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13585. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  13586. }
  13587. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  13588. {
  13589. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  13591. }
  13592. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  13593. {
  13594. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13595. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  13596. }
  13597. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  13598. {
  13599. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  13601. }
  13602. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  13603. {
  13604. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  13606. }
  13607. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  13608. {
  13609. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13610. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  13611. }
  13612. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  13613. {
  13614. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13615. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  13616. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  13617. }
  13618. if(strcmp(keystr, "NumberOfConnectors") == 0)
  13619. {
  13620. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  13622. }
  13623. if(strcmp(keystr, "ResetRetries") == 0)
  13624. {
  13625. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  13627. }
  13628. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  13629. {
  13630. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  13632. }
  13633. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  13634. {
  13635. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  13637. }
  13638. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  13639. {
  13640. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  13642. }
  13643. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  13644. {
  13645. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  13647. }
  13648. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  13649. {
  13650. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  13652. }
  13653. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  13654. {
  13655. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13657. }
  13658. if(strcmp(keystr, "StopTxnSampledData") == 0)
  13659. {
  13660. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  13662. }
  13663. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  13664. {
  13665. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  13667. }
  13668. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  13669. {
  13670. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13671. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  13672. }
  13673. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  13674. {
  13675. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  13677. }
  13678. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  13679. {
  13680. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  13682. TransactionMessageAttemptsValue = atoi(valuestr);
  13683. }
  13684. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  13685. {
  13686. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13687. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  13688. TransactionMessageRetryIntervalValue = atoi(valuestr);
  13689. }
  13690. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  13691. {
  13692. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  13694. }
  13695. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  13696. {
  13697. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  13699. }
  13700. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  13701. {
  13702. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  13704. }
  13705. if(strcmp(keystr, "AuthorizationKey") == 0)
  13706. {
  13707. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13708. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  13709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  13710. }
  13711. if(strcmp(keystr, "SecurityProfile") == 0)
  13712. {
  13713. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  13715. }
  13716. if(strcmp(keystr, "DefaultPrice") == 0)
  13717. {
  13718. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  13720. }
  13721. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  13722. {
  13723. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  13725. }
  13726. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  13727. {
  13728. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  13730. }
  13731. if(strcmp(keystr, "TimeOffset") == 0)
  13732. {
  13733. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  13735. }
  13736. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  13737. {
  13738. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13739. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  13740. }
  13741. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  13742. {
  13743. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13744. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  13745. }
  13746. if(strcmp(keystr, "SystemUptimeSec") == 0)
  13747. {
  13748. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%s", valuestr);
  13750. }
  13751. if(strcmp(keystr, "FreeVend") == 0)
  13752. {
  13753. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode ? "TRUE" : "FALSE"));
  13755. }
  13756. if(strcmp(keystr, "ConfigurationVersion") == 0)
  13757. {
  13758. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  13760. }
  13761. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  13762. {
  13763. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  13765. }
  13766. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  13767. {
  13768. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13769. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  13770. }
  13771. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  13772. {
  13773. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  13775. }
  13776. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  13777. {
  13778. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  13780. }
  13781. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  13782. {
  13783. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  13785. }
  13786. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  13787. {
  13788. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  13790. }
  13791. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  13792. {
  13793. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  13795. }
  13796. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  13797. {
  13798. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  13800. }
  13801. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13802. {
  13803. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13805. }
  13806. }
  13807. }
  13808. fclose(fp);
  13809. }
  13810. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13811. {
  13812. return PASS;
  13813. }
  13814. else
  13815. {
  13816. return FAIL;
  13817. }
  13818. }
  13819. void StoreConfigurationTable(void)
  13820. {
  13821. FILE *outfile;
  13822. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13823. if(outfile == NULL)
  13824. {
  13825. DEBUG_INFO("Error opening file");
  13826. return ;
  13827. }
  13828. /*Core Profile*/
  13829. //AllowOfflineTxForUnknownId
  13830. /*
  13831. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13832. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13835. */
  13836. //DEBUG_INFO("data=%s\n",data);
  13837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13838. //AuthorizationCacheEnabled
  13839. /*
  13840. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13843. */
  13844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13845. //AuthorizeRemoteTxRequests
  13846. /*
  13847. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13850. */
  13851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13852. //BlinkRepeat
  13853. /*
  13854. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13857. */
  13858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13859. //ClockAlignedDataInterval
  13860. /*
  13861. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13864. */
  13865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13866. //ConnectionTimeOut
  13867. /*
  13868. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13871. */
  13872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13873. //GetConfigurationMaxKeys
  13874. /*
  13875. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13878. */
  13879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13880. // HeartbeatInterval
  13881. /*
  13882. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13885. */
  13886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13887. // LightIntensity
  13888. /*
  13889. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13892. */
  13893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13894. // LocalAuthorizeOffline
  13895. /*
  13896. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13899. */
  13900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13901. // LocalPreAuthorize
  13902. /*
  13903. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13906. */
  13907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13908. // MaxEnergyOnInvalidId
  13909. /*
  13910. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13913. */
  13914. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13916. // MeterValuesAlignedData
  13917. /*
  13918. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13921. */
  13922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13923. // MeterValuesAlignedDataMaxLength
  13924. /*
  13925. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13928. */
  13929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13930. // MeterValuesSampledData
  13931. /*
  13932. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13935. */
  13936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13937. // MeterValuesSampledDataMaxLength
  13938. /*
  13939. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13942. */
  13943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13944. // MeterValueSampleInterval
  13945. /*
  13946. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13949. */
  13950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13951. // MinimumStatusDuration
  13952. /*
  13953. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13956. */
  13957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13958. // NumberOfConnectors
  13959. /*
  13960. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13963. {
  13964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13965. }
  13966. else
  13967. {
  13968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13969. }
  13970. */
  13971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13972. // ResetRetries
  13973. /*
  13974. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13977. */
  13978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13979. // ConnectorPhaseRotation
  13980. /*
  13981. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13984. */
  13985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13986. // ConnectorPhaseRotationMaxLength
  13987. /*
  13988. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13991. */
  13992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13993. // StopTransactionOnEVSideDisconnect
  13994. /*
  13995. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13998. */
  13999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  14000. // StopTransactionOnInvalidId
  14001. /*
  14002. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  14003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  14004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  14005. */
  14006. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  14007. // StopTxnAlignedData
  14008. /*
  14009. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  14010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  14011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  14012. */
  14013. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  14014. // StopTxnAlignedDataMaxLength
  14015. /*
  14016. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  14017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  14018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  14019. */
  14020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  14021. // StopTxnSampledData
  14022. /*
  14023. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  14024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  14025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  14026. */
  14027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  14028. // StopTxnSampledDataMaxLength
  14029. /*
  14030. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  14031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  14032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  14033. */
  14034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  14035. // SupportedFeatureProfiles
  14036. /*
  14037. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  14038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  14039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  14040. */
  14041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  14042. // SupportedFeatureProfilesMaxLength
  14043. /*
  14044. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  14045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  14046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  14047. */
  14048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  14049. // TransactionMessageAttempts
  14050. /*
  14051. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  14052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  14053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  14054. */
  14055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14056. // TransactionMessageRetryInterval
  14057. /*
  14058. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  14059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  14060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  14061. */
  14062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14063. // UnlockConnectorOnEVSideDisconnect
  14064. /*
  14065. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  14066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  14067. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  14068. */
  14069. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  14070. // WebSocketPingInterval
  14071. /*
  14072. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  14073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  14074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  14075. */
  14076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14077. // QueueOffLineMeterValues
  14078. /*
  14079. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  14080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  14081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  14082. */
  14083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  14084. // AuthorizationKey
  14085. /*
  14086. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  14087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  14088. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  14089. */
  14090. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14091. // SecurityProfile
  14092. /*
  14093. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  14094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  14095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  14096. */
  14097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14098. // DefaultPrice
  14099. /*
  14100. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  14101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  14102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  14103. */
  14104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  14105. // CustomDisplayCostAndPrice
  14106. /*
  14107. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  14108. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  14109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  14110. */
  14111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  14112. // CustomIdleFeeAfterStop
  14113. /*
  14114. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  14115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  14116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  14117. */
  14118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  14119. // TimeOffset
  14120. /*
  14121. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  14122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  14123. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  14124. */
  14125. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  14126. // NextTimeOffsetTransitionDateTime
  14127. /*
  14128. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  14129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  14130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  14131. */
  14132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  14133. // TimeOffsetNextTransition
  14134. /*
  14135. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  14136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  14137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  14138. */
  14139. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  14140. // SystemUptimeSec
  14141. /*
  14142. ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility = 1;
  14143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemName, "SystemUptimeSec");
  14144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "0" );
  14145. */
  14146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SystemUptimeSec", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData);
  14147. // FreeVend
  14148. /*
  14149. ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility = 1;
  14150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemName, "FreeVend");
  14151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "FALSE" );
  14152. */
  14153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","FreeVend", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData);
  14154. // ConfigurationVersion
  14155. /*
  14156. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  14157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  14158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  14159. */
  14160. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  14161. //* Local Auth List Management Profile*/
  14162. //LocalAuthListEnabled
  14163. /*
  14164. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  14165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  14166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  14167. */
  14168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14169. //LocalAuthListMaxLength
  14170. /*
  14171. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  14172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  14173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  14174. */
  14175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  14176. //SendLocalListMaxLength
  14177. /*
  14178. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  14179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  14180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  14181. */
  14182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  14183. //ReserveConnectorZeroSupported
  14184. /*
  14185. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  14186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  14187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  14188. */
  14189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14190. //* Smart Charging Profile */
  14191. //ChargeProfileMaxStackLevel
  14192. /*
  14193. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  14194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  14195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  14196. */
  14197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14198. // ChargingScheduleAllowedChargingRateUnit
  14199. /*
  14200. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  14201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  14202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  14203. */
  14204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14205. // ChargingScheduleMaxPeriods
  14206. /*
  14207. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  14208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  14209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  14210. */
  14211. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14212. // ConnectorSwitch3to1PhaseSupported
  14213. /*
  14214. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  14215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  14216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  14217. */
  14218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14219. // MaxChargingProfilesInstalled
  14220. /*
  14221. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  14222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  14223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  14224. */
  14225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14226. fclose(outfile);
  14227. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14228. }
  14229. void getKeyValue(char *keyReq)
  14230. {
  14231. int isEmpty = FALSE;
  14232. int isKnowKey = FALSE;
  14233. DEBUG_INFO("keyReq = %s\n", keyReq);
  14234. if((keyReq == NULL) || (strlen(keyReq) == 0))
  14235. isEmpty = TRUE;
  14236. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  14237. {
  14238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  14239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  14240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14241. {
  14242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  14243. }
  14244. else
  14245. {
  14246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  14247. }
  14248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  14249. isKnowKey = TRUE;
  14250. }
  14251. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  14252. {
  14253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  14254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  14255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14256. {
  14257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  14258. }
  14259. else
  14260. {
  14261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  14262. }
  14263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  14264. isKnowKey = TRUE;
  14265. }
  14266. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  14267. {
  14268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  14269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  14270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14271. {
  14272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  14273. }
  14274. else
  14275. {
  14276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  14277. }
  14278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  14279. isKnowKey = TRUE;
  14280. }
  14281. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  14282. {
  14283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  14284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  14285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14286. {
  14287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  14288. }
  14289. else
  14290. {
  14291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  14292. }
  14293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  14294. isKnowKey = TRUE;
  14295. }
  14296. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  14297. {
  14298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  14299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  14300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14301. {
  14302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  14303. }
  14304. else
  14305. {
  14306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  14307. }
  14308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  14309. isKnowKey = TRUE;
  14310. }
  14311. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  14312. {
  14313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  14314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  14315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14316. {
  14317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  14318. }
  14319. else
  14320. {
  14321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  14322. }
  14323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  14324. isKnowKey = TRUE;
  14325. }
  14326. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  14327. {
  14328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  14329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  14330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14331. {
  14332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  14333. }
  14334. else
  14335. {
  14336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  14337. }
  14338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  14339. isKnowKey = TRUE;
  14340. }
  14341. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  14342. {
  14343. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  14344. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  14345. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14346. {
  14347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  14348. }
  14349. else
  14350. {
  14351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  14352. }
  14353. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  14354. isKnowKey = TRUE;
  14355. }
  14356. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  14357. {
  14358. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  14359. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  14360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14361. {
  14362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  14363. }
  14364. else
  14365. {
  14366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  14367. }
  14368. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  14369. isKnowKey = TRUE;
  14370. }
  14371. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  14372. {
  14373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  14374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  14375. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14376. {
  14377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  14378. }
  14379. else
  14380. {
  14381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  14382. }
  14383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  14384. isKnowKey = TRUE;
  14385. }
  14386. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  14387. {
  14388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  14389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  14390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14391. {
  14392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  14393. }
  14394. else
  14395. {
  14396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  14397. }
  14398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  14399. isKnowKey = TRUE;
  14400. }
  14401. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  14402. {
  14403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  14404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  14405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14406. {
  14407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14408. }
  14409. else
  14410. {
  14411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14412. }
  14413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  14414. isKnowKey = TRUE;
  14415. }
  14416. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  14417. {
  14418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  14419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  14420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14421. {
  14422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14423. }
  14424. else
  14425. {
  14426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14427. }
  14428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  14429. isKnowKey = TRUE;
  14430. }
  14431. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  14432. {
  14433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  14434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  14435. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14436. {
  14437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14438. }
  14439. else
  14440. {
  14441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14442. }
  14443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  14444. isKnowKey = TRUE;
  14445. }
  14446. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  14447. {
  14448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  14449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  14450. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14451. {
  14452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  14453. }
  14454. else
  14455. {
  14456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  14457. }
  14458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  14459. isKnowKey = TRUE;
  14460. }
  14461. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  14462. {
  14463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  14464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  14465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14466. {
  14467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14468. }
  14469. else
  14470. {
  14471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14472. }
  14473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  14474. isKnowKey = TRUE;
  14475. }
  14476. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  14477. {
  14478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  14479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  14480. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14481. {
  14482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  14483. }
  14484. else
  14485. {
  14486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  14487. }
  14488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  14489. isKnowKey = TRUE;
  14490. }
  14491. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  14492. {
  14493. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  14494. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  14495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14496. {
  14497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  14498. }
  14499. else
  14500. {
  14501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  14502. }
  14503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  14504. isKnowKey = TRUE;
  14505. }
  14506. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  14507. {
  14508. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  14509. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  14510. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14511. {
  14512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  14513. }
  14514. else
  14515. {
  14516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  14517. }
  14518. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  14519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  14520. isKnowKey = TRUE;
  14521. }
  14522. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  14523. {
  14524. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  14525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  14526. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14527. {
  14528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  14529. }
  14530. else
  14531. {
  14532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  14533. }
  14534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  14535. isKnowKey = TRUE;
  14536. }
  14537. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  14538. {
  14539. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  14540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  14541. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14542. {
  14543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  14544. }
  14545. else
  14546. {
  14547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  14548. }
  14549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  14550. isKnowKey = TRUE;
  14551. }
  14552. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  14553. {
  14554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  14555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  14556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14557. {
  14558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14559. }
  14560. else
  14561. {
  14562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14563. }
  14564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  14565. isKnowKey = TRUE;
  14566. }
  14567. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  14568. {
  14569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  14570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  14571. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14572. {
  14573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14574. }
  14575. else
  14576. {
  14577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14578. }
  14579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  14580. isKnowKey = TRUE;
  14581. }
  14582. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  14583. {
  14584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  14585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  14586. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14587. {
  14588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  14589. }
  14590. else
  14591. {
  14592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  14593. }
  14594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  14595. isKnowKey = TRUE;
  14596. }
  14597. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  14598. {
  14599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  14600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  14601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14602. {
  14603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  14604. }
  14605. else
  14606. {
  14607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  14608. }
  14609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  14610. isKnowKey = TRUE;
  14611. }
  14612. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  14613. {
  14614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  14615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  14616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14617. {
  14618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14619. }
  14620. else
  14621. {
  14622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14623. }
  14624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  14625. isKnowKey = TRUE;
  14626. }
  14627. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  14628. {
  14629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  14630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  14631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14632. {
  14633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  14634. }
  14635. else
  14636. {
  14637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  14638. }
  14639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  14640. isKnowKey = TRUE;
  14641. }
  14642. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  14643. {
  14644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  14645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  14646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14647. {
  14648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14649. }
  14650. else
  14651. {
  14652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14653. }
  14654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  14655. isKnowKey = TRUE;
  14656. }
  14657. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  14658. {
  14659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  14660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  14661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14662. {
  14663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  14664. }
  14665. else
  14666. {
  14667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  14668. }
  14669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  14670. isKnowKey = TRUE;
  14671. }
  14672. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  14673. {
  14674. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  14675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  14676. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14677. {
  14678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14679. }
  14680. else
  14681. {
  14682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14683. }
  14684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  14685. isKnowKey = TRUE;
  14686. }
  14687. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  14688. {
  14689. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  14690. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  14691. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14692. {
  14693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  14694. }
  14695. else
  14696. {
  14697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  14698. }
  14699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  14700. isKnowKey = TRUE;
  14701. }
  14702. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  14703. {
  14704. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  14705. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  14706. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14707. {
  14708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  14709. }
  14710. else
  14711. {
  14712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  14713. }
  14714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  14715. isKnowKey = TRUE;
  14716. }
  14717. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  14718. {
  14719. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  14720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  14721. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14722. {
  14723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  14724. }
  14725. else
  14726. {
  14727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  14728. }
  14729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  14730. isKnowKey = TRUE;
  14731. }
  14732. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  14733. {
  14734. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  14735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  14736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14737. {
  14738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  14739. }
  14740. else
  14741. {
  14742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  14743. }
  14744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  14745. isKnowKey = TRUE;
  14746. }
  14747. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  14748. {
  14749. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  14750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  14751. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14752. {
  14753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  14754. }
  14755. else
  14756. {
  14757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  14758. }
  14759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  14760. isKnowKey = TRUE;
  14761. }
  14762. /*
  14763. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  14764. {
  14765. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  14766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  14767. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  14768. {
  14769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  14770. }
  14771. else
  14772. {
  14773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  14774. }
  14775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  14776. isKnowKey = TRUE;
  14777. }*/
  14778. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  14779. {
  14780. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  14781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  14782. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14783. {
  14784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  14785. }
  14786. else
  14787. {
  14788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  14789. }
  14790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  14791. isKnowKey = TRUE;
  14792. }
  14793. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  14794. {
  14795. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  14796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  14797. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  14798. {
  14799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  14800. }
  14801. else
  14802. {
  14803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  14804. }
  14805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  14806. isKnowKey = TRUE;
  14807. }
  14808. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  14809. {
  14810. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  14811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  14812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14813. {
  14814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14815. }
  14816. else
  14817. {
  14818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14819. }
  14820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14821. isKnowKey = TRUE;
  14822. }
  14823. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14824. {
  14825. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14827. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14828. {
  14829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14830. }
  14831. else
  14832. {
  14833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14834. }
  14835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14836. isKnowKey = TRUE;
  14837. }
  14838. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14839. {
  14840. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14843. {
  14844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14845. }
  14846. else
  14847. {
  14848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14849. }
  14850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14851. isKnowKey = TRUE;
  14852. }
  14853. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14854. {
  14855. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14857. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14858. {
  14859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14860. }
  14861. else
  14862. {
  14863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14864. }
  14865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14866. isKnowKey = TRUE;
  14867. }
  14868. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14869. {
  14870. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14872. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14873. {
  14874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14875. }
  14876. else
  14877. {
  14878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14879. }
  14880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14881. isKnowKey = TRUE;
  14882. }
  14883. if(isEmpty || strcmp(keyReq, "SystemUptimeSec") == 0 )
  14884. {
  14885. struct sysinfo s_info;
  14886. int error = sysinfo(&s_info);
  14887. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SystemUptimeSec].Item, "SystemUptimeSec");
  14888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Key, "SystemUptimeSec");
  14889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemAccessibility == 1)
  14890. {
  14891. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "0"/*"FALSE"*/);
  14892. }
  14893. else
  14894. {
  14895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].ReadOnly, "1"/*"TRUE"*/);
  14896. }
  14897. if(error != 0)
  14898. {
  14899. DEBUG_WARN("System uptime get error: %d\n", error);
  14900. }
  14901. else
  14902. {
  14903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SystemUptimeSec].ItemData, "%ld", s_info.uptime);
  14904. sprintf((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SystemUptimeSec].Value, "%ld", s_info.uptime);
  14905. }
  14906. isKnowKey = TRUE;
  14907. }
  14908. if(isEmpty || strcmp(keyReq, "FreeVend") == 0 )
  14909. {
  14910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_FreeVend].Item, "FreeVend");
  14911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Key, "FreeVend");
  14912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  14913. {
  14914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "0"/*"FALSE"*/);
  14915. }
  14916. else
  14917. {
  14918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].ReadOnly, "1"/*"TRUE"*/);
  14919. }
  14920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_FreeVend].Value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  14921. isKnowKey = TRUE;
  14922. }
  14923. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14924. {
  14925. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14928. {
  14929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14930. }
  14931. else
  14932. {
  14933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14934. }
  14935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14936. isKnowKey = TRUE;
  14937. }
  14938. #if 1
  14939. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14940. {
  14941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14943. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14944. {
  14945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14946. }
  14947. else
  14948. {
  14949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14950. }
  14951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14952. isKnowKey = TRUE;
  14953. }
  14954. #endif
  14955. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14956. {
  14957. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14959. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14960. {
  14961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14962. }
  14963. else
  14964. {
  14965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14966. }
  14967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14968. isKnowKey = TRUE;
  14969. }
  14970. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14971. {
  14972. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14974. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14975. {
  14976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14977. }
  14978. else
  14979. {
  14980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14981. }
  14982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14983. isKnowKey = TRUE;
  14984. }
  14985. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14986. {
  14987. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14989. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14990. {
  14991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14992. }
  14993. else
  14994. {
  14995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14996. }
  14997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14998. isKnowKey = TRUE;
  14999. }
  15000. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  15001. {
  15002. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  15003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  15004. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15005. {
  15006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  15007. }
  15008. else
  15009. {
  15010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  15011. }
  15012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  15013. isKnowKey = TRUE;
  15014. }
  15015. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  15016. {
  15017. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  15018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  15019. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15020. {
  15021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  15022. }
  15023. else
  15024. {
  15025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  15026. }
  15027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  15028. isKnowKey = TRUE;
  15029. }
  15030. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  15031. {
  15032. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  15033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  15034. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15035. {
  15036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  15037. }
  15038. else
  15039. {
  15040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  15041. }
  15042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  15043. isKnowKey = TRUE;
  15044. }
  15045. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  15046. {
  15047. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  15048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  15049. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15050. {
  15051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  15052. }
  15053. else
  15054. {
  15055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  15056. }
  15057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  15058. isKnowKey = TRUE;
  15059. }
  15060. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  15061. {
  15062. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  15063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  15064. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15065. {
  15066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  15067. }
  15068. else
  15069. {
  15070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  15071. }
  15072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  15073. isKnowKey = TRUE;
  15074. }
  15075. //=========================================================
  15076. if(!isEmpty && !isKnowKey)
  15077. {
  15078. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  15079. strcpy(unknownkey[UnknownKeynum], keyReq);
  15080. UnknownKeynum = UnknownKeynum + 1;
  15081. }
  15082. }
  15083. void processUnkownKey(void)
  15084. {
  15085. DEBUG_INFO("processUnkownKey...\n");
  15086. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  15087. for(int index=0; index < UnknownKeynum; index++)
  15088. {
  15089. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  15090. {
  15091. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  15092. }
  15093. }
  15094. }
  15095. int setKeyValue(char *key, char *value)
  15096. {
  15097. int isSuccess = NotSupported;
  15098. int check_ascii=0;
  15099. char str[256]={0};
  15100. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  15101. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  15102. {
  15103. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  15104. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  15105. {
  15106. strcpy(str, (const char*)value);
  15107. for(int i = 0; str[i]; i++){
  15108. str[i] = tolower(str[i]);
  15109. }
  15110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15111. isSuccess = ConfigurationStatus_Accepted;
  15112. }
  15113. else
  15114. {
  15115. isSuccess = ConfigurationStatus_Rejected;
  15116. }
  15117. }
  15118. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  15119. {
  15120. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  15121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  15122. {
  15123. strcpy(str, (const char*)value);
  15124. for(int i = 0; str[i]; i++){
  15125. str[i] = tolower(str[i]);
  15126. }
  15127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15128. isSuccess = ConfigurationStatus_Accepted;
  15129. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  15130. }
  15131. else
  15132. {
  15133. isSuccess = ConfigurationStatus_Rejected;
  15134. }
  15135. }
  15136. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  15137. {
  15138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  15139. {
  15140. strcpy(str, (const char*)value);
  15141. for(int i = 0; str[i]; i++)
  15142. {
  15143. str[i] = tolower(str[i]);
  15144. }
  15145. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  15146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15147. isSuccess = ConfigurationStatus_Accepted;
  15148. }
  15149. else
  15150. {
  15151. isSuccess = ConfigurationStatus_Rejected;
  15152. }
  15153. }
  15154. if(strcmp(key, "BlinkRepeat") == 0)
  15155. {
  15156. //Charger.BlinkRepeat = Integer.parseInt(value);
  15157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  15158. {
  15159. check_ascii = value[0];
  15160. if( (check_ascii < 48) || (check_ascii > 57) )
  15161. {
  15162. isSuccess = ConfigurationStatus_Rejected;
  15163. }
  15164. else
  15165. {
  15166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  15167. isSuccess = ConfigurationStatus_Accepted;
  15168. }
  15169. }
  15170. else
  15171. {
  15172. isSuccess = ConfigurationStatus_Rejected;
  15173. }
  15174. }
  15175. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  15176. {
  15177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  15178. {
  15179. check_ascii = value[0];
  15180. if( (check_ascii < 48) || (check_ascii > 57) )
  15181. {
  15182. isSuccess = ConfigurationStatus_Rejected;
  15183. }
  15184. else
  15185. {
  15186. if((atoi(value) == 0) || (atoi(value) >= 5))
  15187. {
  15188. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  15189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  15190. isSuccess = ConfigurationStatus_Accepted;
  15191. }
  15192. else
  15193. isSuccess = ConfigurationStatus_Rejected;
  15194. }
  15195. }
  15196. else
  15197. {
  15198. isSuccess = ConfigurationStatus_Rejected;
  15199. }
  15200. }
  15201. if(strcmp(key, "ConnectionTimeOut") == 0 )
  15202. {
  15203. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  15204. {
  15205. check_ascii = value[0];
  15206. if( (check_ascii < 48) || (check_ascii > 57) )
  15207. {
  15208. isSuccess = ConfigurationStatus_Rejected;
  15209. }
  15210. else
  15211. {
  15212. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  15213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  15214. isSuccess = ConfigurationStatus_Accepted;
  15215. }
  15216. }
  15217. else
  15218. {
  15219. isSuccess = ConfigurationStatus_Rejected;
  15220. }
  15221. }
  15222. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  15223. {
  15224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  15225. {
  15226. check_ascii = value[0];
  15227. if( (check_ascii < 48) || (check_ascii > 57) )
  15228. {
  15229. isSuccess = ConfigurationStatus_Rejected;
  15230. }
  15231. else
  15232. {
  15233. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  15235. isSuccess = ConfigurationStatus_Accepted;
  15236. }
  15237. }
  15238. else
  15239. {
  15240. isSuccess = ConfigurationStatus_Rejected;
  15241. }
  15242. }
  15243. if(strcmp(key, "HeartbeatInterval") == 0)
  15244. {
  15245. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  15246. {
  15247. check_ascii = value[0];
  15248. if( (check_ascii < 48) || (check_ascii > 57) )
  15249. {
  15250. isSuccess = ConfigurationStatus_Rejected;
  15251. }
  15252. else
  15253. {
  15254. if((atoi(value) == 0) || (atoi(value) >= 10))
  15255. {
  15256. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  15257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  15258. HeartBeatWaitTime = atoi(value);
  15259. isSuccess = ConfigurationStatus_Accepted;
  15260. }
  15261. else
  15262. {
  15263. isSuccess = ConfigurationStatus_Rejected;
  15264. }
  15265. }
  15266. }
  15267. else
  15268. {
  15269. isSuccess = ConfigurationStatus_Rejected;
  15270. }
  15271. }
  15272. if(strcmp(key, "LightIntensity") == 0)
  15273. {
  15274. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  15275. {
  15276. check_ascii = value[0];
  15277. if( (check_ascii < 48) || (check_ascii > 57) )
  15278. {
  15279. isSuccess = ConfigurationStatus_Rejected;
  15280. }
  15281. else
  15282. {
  15283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  15284. isSuccess = ConfigurationStatus_Accepted;
  15285. }
  15286. }
  15287. else
  15288. {
  15289. isSuccess = ConfigurationStatus_Rejected;
  15290. }
  15291. }
  15292. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  15293. {
  15294. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  15295. {
  15296. strcpy(str, (const char*)value);
  15297. for(int i = 0; str[i]; i++)
  15298. {
  15299. str[i] = tolower(str[i]);
  15300. }
  15301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15302. isSuccess = ConfigurationStatus_Accepted;
  15303. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  15304. }
  15305. else
  15306. {
  15307. isSuccess = ConfigurationStatus_Rejected;
  15308. }
  15309. }
  15310. if(strcmp(key, "LocalPreAuthorize") == 0)
  15311. {
  15312. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  15313. {
  15314. strcpy(str, (const char*)value);
  15315. for(int i = 0; str[i]; i++)
  15316. {
  15317. str[i] = tolower(str[i]);
  15318. }
  15319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15320. isSuccess = ConfigurationStatus_Accepted;
  15321. }
  15322. else
  15323. {
  15324. isSuccess = ConfigurationStatus_Rejected;
  15325. }
  15326. }
  15327. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  15328. {
  15329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  15330. {
  15331. check_ascii = value[0];
  15332. if( (check_ascii < 48) || (check_ascii > 57) )
  15333. {
  15334. isSuccess = ConfigurationStatus_Rejected;
  15335. }
  15336. else
  15337. {
  15338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  15339. isSuccess = ConfigurationStatus_Accepted;
  15340. }
  15341. }
  15342. else
  15343. {
  15344. isSuccess = ConfigurationStatus_Rejected;
  15345. }
  15346. }
  15347. if(strcmp(key, "MeterValuesAlignedData") == 0)
  15348. {
  15349. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  15350. {
  15351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  15352. isSuccess = ConfigurationStatus_Accepted;
  15353. }
  15354. else
  15355. {
  15356. isSuccess = ConfigurationStatus_Rejected;
  15357. }
  15358. }
  15359. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  15360. {
  15361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  15362. {
  15363. check_ascii = value[0];
  15364. if( (check_ascii < 48) || (check_ascii > 57) )
  15365. {
  15366. isSuccess = ConfigurationStatus_Rejected;
  15367. }
  15368. else
  15369. {
  15370. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  15372. isSuccess = ConfigurationStatus_Accepted;
  15373. }
  15374. }
  15375. else
  15376. {
  15377. isSuccess = ConfigurationStatus_Rejected;
  15378. }
  15379. }
  15380. if(strcmp(key, "MeterValuesSampledData") == 0 )
  15381. {
  15382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  15383. {
  15384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  15385. isSuccess = ConfigurationStatus_Accepted;
  15386. }
  15387. else
  15388. {
  15389. isSuccess = ConfigurationStatus_Rejected;
  15390. }
  15391. }
  15392. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  15393. {
  15394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  15395. {
  15396. check_ascii = value[0];
  15397. if( (check_ascii < 48) || (check_ascii > 57) )
  15398. {
  15399. isSuccess = ConfigurationStatus_Rejected;
  15400. }
  15401. else
  15402. {
  15403. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  15405. isSuccess = ConfigurationStatus_Accepted;
  15406. }
  15407. }
  15408. else
  15409. {
  15410. isSuccess = ConfigurationStatus_Rejected;
  15411. }
  15412. }
  15413. if(strcmp(key, "MeterValueSampleInterval") == 0)
  15414. {
  15415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  15416. {
  15417. check_ascii = value[0];
  15418. if( (check_ascii < 48) || (check_ascii > 57) )
  15419. {
  15420. isSuccess = ConfigurationStatus_Rejected;
  15421. }
  15422. else
  15423. {
  15424. if((atoi(value) == 0) || (atoi(value) >= 5))
  15425. {
  15426. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  15427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  15428. isSuccess = ConfigurationStatus_Accepted;
  15429. }
  15430. else
  15431. {
  15432. isSuccess = ConfigurationStatus_Rejected;
  15433. }
  15434. }
  15435. }
  15436. else
  15437. {
  15438. isSuccess = ConfigurationStatus_Rejected;
  15439. }
  15440. }
  15441. if(strcmp(key, "MinimumStatusDuration") == 0)
  15442. {
  15443. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  15444. {
  15445. check_ascii = value[0];
  15446. if( (check_ascii < 48) || (check_ascii > 57) )
  15447. {
  15448. isSuccess = ConfigurationStatus_Rejected;
  15449. }
  15450. else
  15451. {
  15452. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  15453. {
  15454. isSuccess = ConfigurationStatus_Rejected;
  15455. }
  15456. else
  15457. {
  15458. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  15459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  15460. server_cycle_Status = atoi(value); //StatusNotification Cycle
  15461. isSuccess = ConfigurationStatus_Accepted;
  15462. }
  15463. }
  15464. }
  15465. else
  15466. {
  15467. isSuccess = ConfigurationStatus_Rejected;
  15468. }
  15469. }
  15470. if(strcmp(key, "NumberOfConnectors") == 0)
  15471. {
  15472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  15473. {
  15474. check_ascii = value[0];
  15475. if( (check_ascii < 48) || (check_ascii > 57) )
  15476. {
  15477. isSuccess = ConfigurationStatus_Rejected;
  15478. }
  15479. else
  15480. {
  15481. //Charger.ResetRetries = Integer.parseInt(value);
  15482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  15483. isSuccess = ConfigurationStatus_Accepted;
  15484. }
  15485. }
  15486. else
  15487. {
  15488. isSuccess = ConfigurationStatus_Rejected;
  15489. }
  15490. }
  15491. if(strcmp(key, "ResetRetries") == 0)
  15492. {
  15493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  15494. {
  15495. check_ascii = value[0];
  15496. if( (check_ascii < 48) || (check_ascii > 57) )
  15497. {
  15498. isSuccess = ConfigurationStatus_Rejected;
  15499. }
  15500. else
  15501. {
  15502. //Charger.ResetRetries = Integer.parseInt(value);
  15503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  15504. isSuccess = ConfigurationStatus_Accepted;
  15505. }
  15506. }
  15507. else
  15508. {
  15509. isSuccess = ConfigurationStatus_Rejected;
  15510. }
  15511. }
  15512. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  15513. {
  15514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  15515. {
  15516. strcpy(str, (const char*)value);
  15517. for(int i = 0; str[i]; i++)
  15518. {
  15519. str[i] = tolower(str[i]);
  15520. }
  15521. if(strcmp(str, "notapplicable")== 0)
  15522. {
  15523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  15524. isSuccess = ConfigurationStatus_Accepted;
  15525. }
  15526. else if(strcmp(str, "unknown")== 0)
  15527. {
  15528. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  15529. isSuccess = ConfigurationStatus_Accepted;
  15530. }
  15531. else if(strcmp(str, "rst")== 0)
  15532. {
  15533. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  15534. isSuccess = ConfigurationStatus_Accepted;
  15535. }
  15536. else if(strcmp(str, "rts")== 0)
  15537. {
  15538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  15539. isSuccess = ConfigurationStatus_Accepted;
  15540. }
  15541. else if(strcmp(str, "srt")== 0)
  15542. {
  15543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  15544. isSuccess = ConfigurationStatus_Accepted;
  15545. }
  15546. else if(strcmp(str, "str")== 0)
  15547. {
  15548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  15549. isSuccess = ConfigurationStatus_Accepted;
  15550. }
  15551. else if(strcmp(str, "trs")== 0)
  15552. {
  15553. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  15554. isSuccess = ConfigurationStatus_Accepted;
  15555. }
  15556. else if(strcmp(str, "tsr")== 0)
  15557. {
  15558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  15559. isSuccess = ConfigurationStatus_Accepted;
  15560. }
  15561. else
  15562. {
  15563. isSuccess = ConfigurationStatus_Rejected;
  15564. }
  15565. }
  15566. else
  15567. {
  15568. isSuccess = ConfigurationStatus_Rejected;
  15569. }
  15570. }
  15571. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  15572. {
  15573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  15574. {
  15575. check_ascii = value[0];
  15576. if( (check_ascii < 48) || (check_ascii > 57) )
  15577. {
  15578. isSuccess = ConfigurationStatus_Rejected;
  15579. }
  15580. else
  15581. {
  15582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  15583. isSuccess = ConfigurationStatus_Accepted;
  15584. }
  15585. }
  15586. else
  15587. {
  15588. isSuccess = ConfigurationStatus_Rejected;
  15589. }
  15590. }
  15591. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  15592. {
  15593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  15594. {
  15595. strcpy(str, (const char*)value);
  15596. for(int i = 0; str[i]; i++)
  15597. {
  15598. str[i] = tolower(str[i]);
  15599. }
  15600. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15602. isSuccess = ConfigurationStatus_Accepted;
  15603. }
  15604. else
  15605. {
  15606. isSuccess = ConfigurationStatus_Rejected;
  15607. }
  15608. }
  15609. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  15610. {
  15611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  15612. {
  15613. strcpy(str, (const char*)value);
  15614. for(int i = 0; str[i]; i++)
  15615. {
  15616. str[i] = tolower(str[i]);
  15617. }
  15618. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  15619. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15620. isSuccess = ConfigurationStatus_Accepted;
  15621. }
  15622. else
  15623. {
  15624. isSuccess = ConfigurationStatus_Rejected;
  15625. }
  15626. }
  15627. if(strcmp(key, "StopTxnAlignedData") == 0)
  15628. {
  15629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  15630. {
  15631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  15632. isSuccess = ConfigurationStatus_Accepted;
  15633. }
  15634. else
  15635. {
  15636. isSuccess = ConfigurationStatus_Rejected;
  15637. }
  15638. }
  15639. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  15640. {
  15641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  15642. {
  15643. check_ascii = value[0];
  15644. if( (check_ascii < 48) || (check_ascii > 57) )
  15645. {
  15646. isSuccess = ConfigurationStatus_Rejected;
  15647. }
  15648. else
  15649. {
  15650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  15651. isSuccess = ConfigurationStatus_Accepted;
  15652. }
  15653. }
  15654. else
  15655. {
  15656. isSuccess = ConfigurationStatus_Rejected;
  15657. }
  15658. }
  15659. if(strcmp(key, "StopTxnSampledData") == 0)
  15660. {
  15661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  15662. {
  15663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  15664. isSuccess = ConfigurationStatus_Accepted;
  15665. }
  15666. else
  15667. {
  15668. isSuccess = ConfigurationStatus_Rejected;
  15669. }
  15670. }
  15671. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  15672. {
  15673. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  15674. {
  15675. check_ascii = value[0];
  15676. if( (check_ascii < 48) || (check_ascii > 57) )
  15677. {
  15678. isSuccess = ConfigurationStatus_Rejected;
  15679. }
  15680. else
  15681. {
  15682. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  15683. isSuccess = ConfigurationStatus_Accepted;
  15684. }
  15685. }
  15686. else
  15687. {
  15688. isSuccess = ConfigurationStatus_Rejected;
  15689. }
  15690. }
  15691. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  15692. {
  15693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  15694. {
  15695. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  15696. isSuccess = ConfigurationStatus_Accepted;
  15697. }
  15698. else
  15699. {
  15700. isSuccess = ConfigurationStatus_Rejected;
  15701. }
  15702. }
  15703. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  15704. {
  15705. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  15706. {
  15707. check_ascii = value[0];
  15708. if( (check_ascii < 48) || (check_ascii > 57) )
  15709. {
  15710. isSuccess = ConfigurationStatus_Rejected;
  15711. }
  15712. else
  15713. {
  15714. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  15715. isSuccess = ConfigurationStatus_Accepted;
  15716. }
  15717. }
  15718. else
  15719. {
  15720. isSuccess = ConfigurationStatus_Rejected;
  15721. }
  15722. }
  15723. if(strcmp(key, "TransactionMessageAttempts") == 0)
  15724. {
  15725. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  15726. {
  15727. check_ascii = value[0];
  15728. if( (check_ascii < 48) || (check_ascii > 57) )
  15729. {
  15730. isSuccess = ConfigurationStatus_Rejected;
  15731. }
  15732. else
  15733. {
  15734. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  15735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  15736. TransactionMessageAttemptsValue = atoi(value);
  15737. isSuccess = ConfigurationStatus_Accepted;
  15738. }
  15739. }
  15740. else
  15741. {
  15742. isSuccess = ConfigurationStatus_Rejected;
  15743. }
  15744. }
  15745. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  15746. {
  15747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  15748. {
  15749. check_ascii = value[0];
  15750. if( (check_ascii < 48) || (check_ascii > 57) )
  15751. {
  15752. isSuccess = ConfigurationStatus_Rejected;
  15753. }
  15754. else
  15755. {
  15756. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  15757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  15758. TransactionMessageRetryIntervalValue = atoi(value);
  15759. isSuccess = ConfigurationStatus_Accepted;
  15760. }
  15761. }
  15762. else
  15763. {
  15764. isSuccess = ConfigurationStatus_Rejected;
  15765. }
  15766. }
  15767. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  15768. {
  15769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  15770. {
  15771. strcpy(str, (const char*)value);
  15772. for(int i = 0; str[i]; i++)
  15773. {
  15774. str[i] = tolower(str[i]);
  15775. }
  15776. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  15777. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15778. isSuccess = ConfigurationStatus_Accepted;
  15779. }
  15780. else
  15781. {
  15782. isSuccess = ConfigurationStatus_Rejected;
  15783. }
  15784. }
  15785. if(strcmp(key, "WebSocketPingInterval") == 0)
  15786. {
  15787. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  15788. {
  15789. check_ascii = value[0];
  15790. if( (check_ascii < 48) || (check_ascii > 57) )
  15791. {
  15792. isSuccess = ConfigurationStatus_Rejected;
  15793. }
  15794. else
  15795. {
  15796. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  15797. isSuccess = ConfigurationStatus_Accepted;
  15798. }
  15799. }
  15800. else
  15801. {
  15802. isSuccess = ConfigurationStatus_Rejected;
  15803. }
  15804. }
  15805. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  15806. {
  15807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  15808. {
  15809. strcpy(str, (const char*)value);
  15810. for(int i = 0; str[i]; i++)
  15811. {
  15812. str[i] = tolower(str[i]);
  15813. }
  15814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15815. isSuccess = ConfigurationStatus_Accepted;
  15816. }
  15817. else
  15818. {
  15819. isSuccess = ConfigurationStatus_Rejected;
  15820. }
  15821. }
  15822. if(strcmp(key, "AuthorizationKey") == 0)
  15823. {
  15824. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  15825. {
  15826. strcpy(str, (const char*)value);
  15827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  15828. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15829. isSuccess = ConfigurationStatus_Accepted;
  15830. }
  15831. else
  15832. {
  15833. isSuccess = ConfigurationStatus_Rejected;
  15834. }
  15835. }
  15836. if(strcmp(key, "SecurityProfile") == 0)
  15837. {
  15838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  15839. {
  15840. check_ascii = value[0];
  15841. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  15842. {
  15843. isSuccess = ConfigurationStatus_Rejected;
  15844. }
  15845. else if(check_ascii == 0x33)
  15846. {
  15847. isSuccess = NotSupported;
  15848. }
  15849. else
  15850. {
  15851. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  15852. {
  15853. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15854. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15855. isSuccess = ConfigurationStatus_Accepted;
  15856. }
  15857. else
  15858. isSuccess = ConfigurationStatus_Rejected;
  15859. }
  15860. }
  15861. else
  15862. {
  15863. isSuccess = ConfigurationStatus_Rejected;
  15864. }
  15865. }
  15866. if(strcmp(key, "DefaultPrice") == 0)
  15867. {
  15868. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15869. {
  15870. strcpy(str, (const char*)value);
  15871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15872. isSuccess = ConfigurationStatus_Accepted;
  15873. }
  15874. else
  15875. {
  15876. isSuccess = ConfigurationStatus_Rejected;
  15877. }
  15878. }
  15879. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15880. {
  15881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15882. {
  15883. strcpy(str, (const char*)value);
  15884. for(int i = 0; str[i]; i++)
  15885. {
  15886. str[i] = tolower(str[i]);
  15887. }
  15888. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15889. isSuccess = ConfigurationStatus_Accepted;
  15890. }
  15891. else
  15892. {
  15893. isSuccess = ConfigurationStatus_Rejected;
  15894. }
  15895. }
  15896. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15897. {
  15898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15899. {
  15900. strcpy(str, (const char*)value);
  15901. for(int i = 0; str[i]; i++)
  15902. {
  15903. str[i] = tolower(str[i]);
  15904. }
  15905. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15906. isSuccess = ConfigurationStatus_Accepted;
  15907. }
  15908. else
  15909. {
  15910. isSuccess = ConfigurationStatus_Rejected;
  15911. }
  15912. }
  15913. if(strcmp(key, "TimeOffset") == 0)
  15914. {
  15915. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15916. {
  15917. strcpy(str, (const char*)value);
  15918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15919. isSuccess = ConfigurationStatus_Accepted;
  15920. }
  15921. else
  15922. {
  15923. isSuccess = ConfigurationStatus_Rejected;
  15924. }
  15925. }
  15926. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15927. {
  15928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15929. {
  15930. strcpy(str, (const char*)value);
  15931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15932. isSuccess = ConfigurationStatus_Accepted;
  15933. }
  15934. else
  15935. {
  15936. isSuccess = ConfigurationStatus_Rejected;
  15937. }
  15938. }
  15939. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15940. {
  15941. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15942. {
  15943. strcpy(str, (const char*)value);
  15944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15945. isSuccess = ConfigurationStatus_Accepted;
  15946. }
  15947. else
  15948. {
  15949. isSuccess = ConfigurationStatus_Rejected;
  15950. }
  15951. }
  15952. if(strcmp(key, "SystemUptimeSec") == 0)
  15953. {
  15954. isSuccess = NotSupported;
  15955. }
  15956. if(strcmp(key, "FreeVend") == 0)
  15957. {
  15958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemAccessibility == 1)
  15959. {
  15960. strcpy(str, (const char*)value);
  15961. for(int i = 0; str[i]; i++)
  15962. {
  15963. str[i] = tolower(str[i]);
  15964. }
  15965. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = ((strcmp(str, "true")==0) ? 1 : 0 );
  15966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[FreeVend].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15967. isSuccess = ConfigurationStatus_Accepted;
  15968. }
  15969. else
  15970. {
  15971. isSuccess = ConfigurationStatus_Rejected;
  15972. }
  15973. }
  15974. #if 0
  15975. //For OCPP Test Case
  15976. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15977. {
  15978. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15979. {
  15980. strcpy(str, (const char*)value);
  15981. for(int i = 0; str[i]; i++)
  15982. {
  15983. str[i] = tolower(str[i]);
  15984. }
  15985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15986. isSuccess = ConfigurationStatus_Accepted;
  15987. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15988. }
  15989. else
  15990. {
  15991. isSuccess = ConfigurationStatus_Rejected;
  15992. }
  15993. }
  15994. #endif
  15995. #if 1
  15996. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15997. {
  15998. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15999. {
  16000. strcpy(str, (const char*)value);
  16001. for(int i = 0; str[i]; i++)
  16002. {
  16003. str[i] = tolower(str[i]);
  16004. }
  16005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16006. isSuccess = ConfigurationStatus_Accepted;
  16007. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  16008. }
  16009. else
  16010. {
  16011. isSuccess = ConfigurationStatus_Rejected;
  16012. }
  16013. }
  16014. #endif
  16015. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  16016. {
  16017. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  16018. {
  16019. check_ascii = value[0];
  16020. if( (check_ascii < 48) || (check_ascii > 57) )
  16021. {
  16022. isSuccess = ConfigurationStatus_Rejected;
  16023. }
  16024. else
  16025. {
  16026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  16027. isSuccess = ConfigurationStatus_Accepted;
  16028. }
  16029. }
  16030. else
  16031. {
  16032. isSuccess = ConfigurationStatus_Rejected;
  16033. }
  16034. }
  16035. if(strcmp(key, "SendLocalListMaxLength") == 0)
  16036. {
  16037. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  16038. {
  16039. check_ascii = value[0];
  16040. if( (check_ascii < 48) || (check_ascii > 57) )
  16041. {
  16042. isSuccess = ConfigurationStatus_Rejected;
  16043. }
  16044. else
  16045. {
  16046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  16047. isSuccess = ConfigurationStatus_Accepted;
  16048. }
  16049. }
  16050. else
  16051. {
  16052. isSuccess = ConfigurationStatus_Rejected;
  16053. }
  16054. }
  16055. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  16056. {
  16057. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  16058. {
  16059. strcpy(str, (const char*)value);
  16060. for(int i = 0; str[i]; i++)
  16061. {
  16062. str[i] = tolower(str[i]);
  16063. }
  16064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16065. isSuccess = ConfigurationStatus_Accepted;
  16066. }
  16067. else
  16068. {
  16069. isSuccess = ConfigurationStatus_Rejected;
  16070. }
  16071. }
  16072. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  16073. {
  16074. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  16075. {
  16076. check_ascii = value[0];
  16077. if( (check_ascii < 48) || (check_ascii > 57) )
  16078. {
  16079. isSuccess = ConfigurationStatus_Rejected;
  16080. }
  16081. else
  16082. {
  16083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  16084. isSuccess = ConfigurationStatus_Accepted;
  16085. }
  16086. }
  16087. else
  16088. {
  16089. isSuccess = ConfigurationStatus_Rejected;
  16090. }
  16091. }
  16092. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  16093. {
  16094. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  16095. {
  16096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  16097. isSuccess = ConfigurationStatus_Accepted;
  16098. }
  16099. else
  16100. {
  16101. isSuccess = ConfigurationStatus_Rejected;
  16102. }
  16103. }
  16104. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  16105. {
  16106. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  16107. {
  16108. check_ascii = value[0];
  16109. if( (check_ascii < 48) || (check_ascii > 57) )
  16110. {
  16111. isSuccess = ConfigurationStatus_Rejected;
  16112. }
  16113. else
  16114. {
  16115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  16116. isSuccess = ConfigurationStatus_Accepted;
  16117. }
  16118. }
  16119. else
  16120. {
  16121. isSuccess = ConfigurationStatus_Rejected;
  16122. }
  16123. }
  16124. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  16125. {
  16126. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  16127. {
  16128. strcpy(str, (const char*)value);
  16129. for(int i = 0; str[i]; i++)
  16130. {
  16131. str[i] = tolower(str[i]);
  16132. }
  16133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  16134. isSuccess = ConfigurationStatus_Accepted;
  16135. }
  16136. else
  16137. {
  16138. isSuccess = ConfigurationStatus_Rejected;
  16139. }
  16140. }
  16141. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  16142. {
  16143. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  16144. {
  16145. check_ascii = value[0];
  16146. if( (check_ascii < 48) || (check_ascii > 57) )
  16147. {
  16148. isSuccess = ConfigurationStatus_Rejected;
  16149. }
  16150. else
  16151. {
  16152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  16153. isSuccess = ConfigurationStatus_Accepted;
  16154. }
  16155. }
  16156. else
  16157. {
  16158. isSuccess = ConfigurationStatus_Rejected;
  16159. }
  16160. }
  16161. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16162. return isSuccess;
  16163. }
  16164. int TransactionMessageAttemptsGet(void)
  16165. {
  16166. return TransactionMessageAttemptsValue;
  16167. }
  16168. int FirstHeartBeatResponse(void)
  16169. {
  16170. return FirstHeartBeat;
  16171. }
  16172. int TransactionMessageRetryIntervalGet(void)
  16173. {
  16174. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16175. }
  16176. int ReadHttpStatus(int sock)
  16177. {
  16178. //char c;
  16179. char buff[1024]="",*ptr=buff+1;
  16180. int bytes_received, status;
  16181. DEBUG_INFO("Begin Response ..\n");
  16182. while((bytes_received = recv(sock, ptr, 1, 0))){
  16183. if(bytes_received==-1){
  16184. perror("ReadHttpStatus");
  16185. exit(1);
  16186. }
  16187. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  16188. ptr++;
  16189. }
  16190. *ptr=0;
  16191. ptr=buff+1;
  16192. sscanf(ptr,"%*s %d ", &status);
  16193. DEBUG_INFO("%s\n",ptr);
  16194. DEBUG_INFO("status=%d\n",status);
  16195. DEBUG_INFO("End Response ..\n");
  16196. return (bytes_received>0)?status:0;
  16197. }
  16198. //the only filed that it parsed is 'Content-Length'
  16199. int ParseHeader(int sock)
  16200. {
  16201. //char c;
  16202. char buff[1024]="",*ptr=buff+4;
  16203. int bytes_received;
  16204. DEBUG_INFO("Begin HEADER ..\n");
  16205. while((bytes_received = recv(sock, ptr, 1, 0))){
  16206. if(bytes_received==-1){
  16207. perror("Parse Header");
  16208. exit(1);
  16209. }
  16210. if(
  16211. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  16212. (ptr[-1]=='\r') && (*ptr=='\n' )
  16213. ) break;
  16214. ptr++;
  16215. }
  16216. *ptr=0;
  16217. ptr=buff+4;
  16218. //printf("%s",ptr);
  16219. if(bytes_received){
  16220. ptr=strstr(ptr,"Content-Length:");
  16221. if(ptr){
  16222. sscanf(ptr,"%*s %d",&bytes_received);
  16223. }else
  16224. bytes_received=-1; //unknown size
  16225. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  16226. }
  16227. DEBUG_INFO("End HEADER ..\n");
  16228. return bytes_received ;
  16229. }
  16230. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16231. {
  16232. int result = TRUE;
  16233. char rmFileCmd[100]={0};
  16234. char FilePath[100]={0};
  16235. char ftpbuf[200];
  16236. int systemresult;
  16237. sprintf(FilePath,"/mnt/%s",filename);
  16238. system("ping 8.8.8.8 &");
  16239. if((access(FilePath,F_OK))!=-1)
  16240. {
  16241. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16242. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16243. system(rmFileCmd);
  16244. }
  16245. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16246. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16247. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16248. systemresult = system(ftpbuf);
  16249. if(systemresult != 0)
  16250. {
  16251. DEBUG_INFO("http DownLoad error!\n");
  16252. result = FALSE;
  16253. }
  16254. system("pkill ping");
  16255. return result;
  16256. }
  16257. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16258. {
  16259. int result = TRUE;
  16260. char rmFileCmd[100]={0};
  16261. char FilePath[100]={0};
  16262. char ftpbuf[200];
  16263. int systemresult;
  16264. sprintf(FilePath,"/mnt/%s",filename);
  16265. system("ping 8.8.8.8 &");
  16266. if((access(FilePath,F_OK))!=-1)
  16267. {
  16268. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16269. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16270. system(rmFileCmd);
  16271. }
  16272. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16273. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16274. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16275. systemresult = system(ftpbuf);
  16276. if(systemresult != 0)
  16277. {
  16278. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16279. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16280. systemresult = system(ftpbuf);
  16281. if(systemresult != 0)
  16282. {
  16283. DEBUG_WARN("wget error!\n");
  16284. result = FALSE;
  16285. }
  16286. }
  16287. system("pkill ping");
  16288. return result;
  16289. }
  16290. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16291. {
  16292. char rmFileCmd[100]={0};
  16293. char FilePath[100]={0};
  16294. char buf[512];
  16295. int systemresult = 0;
  16296. //DEBUG_INFO("filename=%s\n",filename);
  16297. //DEBUG_INFO("url=%s\n",url);
  16298. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16299. if((access(FilePath,F_OK))!=-1)
  16300. {
  16301. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16302. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16303. system(rmFileCmd);
  16304. }
  16305. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16306. if(fp == NULL)
  16307. {
  16308. DEBUG_INFO("log is NULL\n");
  16309. return FALSE;
  16310. }
  16311. else
  16312. {
  16313. fprintf(fp, "%s\n", url);
  16314. fprintf(fp, "%s\n", filename);
  16315. fclose(fp);
  16316. }
  16317. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16318. if(phpFP == NULL)
  16319. {
  16320. DEBUG_INFO("PHP upload fail.\n");
  16321. return FALSE;
  16322. }
  16323. else
  16324. {
  16325. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16326. {
  16327. if(strstr(buf, "result") != NULL)
  16328. {
  16329. sscanf(buf, "result: %d", &systemresult);
  16330. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16331. }
  16332. }
  16333. pclose(phpFP);
  16334. }
  16335. if(systemresult != 1)
  16336. {
  16337. DEBUG_INFO("HTTP upload error!\n");
  16338. return FALSE;
  16339. }
  16340. return TRUE;
  16341. }
  16342. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16343. {
  16344. int result = FALSE;
  16345. char ftpbuf[200];
  16346. int systemresult;
  16347. /*
  16348. // Domaind name transfer to IP address
  16349. struct hostent* server;
  16350. char *IPbuffer;
  16351. server = gethostbyname(location);
  16352. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16353. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16354. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16355. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16356. systemresult = system(ftpbuf);
  16357. if(systemresult != 0)
  16358. {
  16359. DEBUG_INFO("ftpput error!\n");
  16360. }
  16361. else
  16362. {
  16363. result = TRUE;
  16364. DEBUG_INFO("ftpput OK!\n");
  16365. }
  16366. return result;
  16367. }
  16368. int GetOcppServerURL()
  16369. {
  16370. int result = FALSE;
  16371. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16372. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16373. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16374. struct yuarel url;
  16375. char urlStr[512];
  16376. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  16377. {
  16378. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  16379. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16380. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16381. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  16382. if(yuarel_parse(&url, urlStr) != -1)
  16383. {
  16384. sprintf(OcppProtocol, "%s", url.scheme);
  16385. sprintf(OcppHost, "%s", url.host);
  16386. if(url.path == NULL)
  16387. OcppTempPath[0] = '\0';
  16388. else
  16389. {
  16390. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  16391. {
  16392. sprintf(OcppTempPath, "%s/", url.path);
  16393. }
  16394. else
  16395. {
  16396. sprintf(OcppTempPath, "%s", url.path);
  16397. }
  16398. }
  16399. if(url.port == 0)
  16400. {
  16401. if(strcmp(OcppProtocol, "wss") == 0)
  16402. OcppPort = 443;
  16403. else
  16404. OcppPort = 80;
  16405. }
  16406. else
  16407. OcppPort = url.port;
  16408. result = TRUE;
  16409. }
  16410. }
  16411. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  16412. {
  16413. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  16414. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  16415. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  16416. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  16417. if(yuarel_parse(&url, urlStr) != -1)
  16418. {
  16419. sprintf(OcppProtocol, "%s", url.scheme);
  16420. sprintf(OcppHost, "%s", url.host);
  16421. if(url.path == NULL)
  16422. OcppTempPath[0] = '\0';
  16423. else
  16424. sprintf(OcppTempPath, "%s", url.path);
  16425. if(url.port == 0)
  16426. {
  16427. if(strcmp(OcppProtocol, "wss") == 0)
  16428. OcppPort = 443;
  16429. else
  16430. OcppPort = 80;
  16431. }
  16432. else
  16433. OcppPort = url.port;
  16434. result = TRUE;
  16435. }
  16436. }
  16437. else
  16438. {
  16439. strcpy(OcppHost,"");
  16440. }
  16441. return result;
  16442. }
  16443. int GetOcppPath()
  16444. {
  16445. int result = FALSE;
  16446. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  16447. {
  16448. if(OcppTempPath == NULL)
  16449. {
  16450. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16451. }
  16452. else
  16453. {
  16454. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16455. }
  16456. result = TRUE;
  16457. goto End;
  16458. }
  16459. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  16460. {
  16461. if(OcppTempPath == NULL)
  16462. {
  16463. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  16464. }
  16465. else
  16466. {
  16467. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  16468. }
  16469. result = TRUE;
  16470. goto End;
  16471. }
  16472. else
  16473. {
  16474. strcpy(OcppPath,"");
  16475. }
  16476. End:
  16477. return result;
  16478. }
  16479. int GetOcppPort()
  16480. {
  16481. return OcppPort;
  16482. }
  16483. int GetOcppConnStatus(void)
  16484. {
  16485. return ShmOCPP16Data->OcppConnStatus;
  16486. }
  16487. void SetOcppConnStatus(uint8_t status)
  16488. {
  16489. ShmOCPP16Data->OcppConnStatus = status;
  16490. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  16491. }
  16492. int GetHeartBeatWithNOResponse(void)
  16493. {
  16494. return HeartBeatWithNOResponse;
  16495. }
  16496. void SetHeartBeatWithNOResponse(void)
  16497. {
  16498. HeartBeatWithNOResponse = 0;
  16499. }
  16500. void GetStartTransactionIdTag(int gun_index)
  16501. {
  16502. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  16503. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16504. }
  16505. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  16506. {
  16507. char ch;
  16508. FILE *fptr1;
  16509. int temptransactionId;
  16510. char str[100]={0};
  16511. temptransactionId = 0;
  16512. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  16513. {
  16514. DEBUG_INFO("IdTag is empty.\n");
  16515. return temptransactionId;
  16516. }
  16517. /*------ Read the file ----------------*/
  16518. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  16519. if (!fptr1)
  16520. {
  16521. DEBUG_INFO("QueueTransactionId file open error.\n");
  16522. //printf(" File not found or unable to open the input file!!\n");
  16523. return temptransactionId;
  16524. }
  16525. ch=fgetc(fptr1);
  16526. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  16527. rewind(fptr1);
  16528. if(ch!=EOF)
  16529. {
  16530. // printf("%c",ch);
  16531. while (fgets(str, 100, fptr1) != NULL)
  16532. {
  16533. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16534. if(str[0]=='\0')
  16535. {
  16536. break;
  16537. }
  16538. char *revbuf[8] = {0}; // Variable store string split
  16539. int num = 0;// Quantity after string split
  16540. DEBUG_INFO("Transaction queue data= %s\n", str);
  16541. splitstring(str,",",revbuf,&num); // String split
  16542. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  16543. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  16544. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  16545. DEBUG_INFO("------------------------------\n");
  16546. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  16547. {
  16548. if(isStopTransaction)
  16549. {
  16550. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  16551. {
  16552. temptransactionId = atoi(revbuf[2]);
  16553. //break;
  16554. }
  16555. }
  16556. else
  16557. {
  16558. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  16559. {
  16560. temptransactionId = atoi(revbuf[2]);
  16561. //break;
  16562. }
  16563. }
  16564. }
  16565. }
  16566. }
  16567. else
  16568. DEBUG_INFO("EOF\n");
  16569. fclose(fptr1);
  16570. /*------- End of reading ---------------*/
  16571. return temptransactionId;
  16572. }
  16573. void SetTransactionIdZero(int transactionId)
  16574. {
  16575. char ch;
  16576. FILE *fptr1, *fptr2;
  16577. int temptransactionId = 0;
  16578. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  16579. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  16580. if (!fptr1)
  16581. {
  16582. //printf(" File not found or unable to open the input file!!\n");
  16583. return ;
  16584. }
  16585. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  16586. if (!fptr2)
  16587. {
  16588. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  16589. fclose(fptr1);
  16590. return ;
  16591. }
  16592. ch=fgetc(fptr1);
  16593. rewind(fptr1);
  16594. if(ch!=EOF)
  16595. {
  16596. // copy all contents to the temporary file except the specific line
  16597. while (fgets(str, 100, fptr1) != NULL)
  16598. {
  16599. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16600. if(str[0]=='\0')
  16601. {
  16602. break;
  16603. }
  16604. char *revbuf[8] = {0};
  16605. int num = 0;
  16606. strcpy(strtemp, str);
  16607. splitstring(str,",",revbuf,&num);
  16608. if(revbuf[2][0] != '\0')
  16609. {
  16610. temptransactionId = atoi(revbuf[2]);
  16611. if(transactionId != temptransactionId)
  16612. {
  16613. fprintf(fptr2, "%s\n", strtemp);
  16614. }
  16615. }
  16616. }
  16617. }
  16618. fclose(fptr1);
  16619. fclose(fptr2);
  16620. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  16621. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  16622. /*------ Read the file ----------------*/
  16623. }
  16624. int InternetDisconnect(void)
  16625. {
  16626. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  16627. }
  16628. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16629. void storeTempStopTransaction(int gun_index)
  16630. {
  16631. char guid[37]={0};
  16632. int tempIndex = 0;
  16633. char TempStopTransaction[256];
  16634. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16635. DEBUG_INFO("storeTempStopTransaction...\n");
  16636. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  16637. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  16638. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  16639. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16640. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16641. {
  16642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16643. {
  16644. tempIndex = ((gun_index==2) ? 1: 0);
  16645. }
  16646. else
  16647. {
  16648. tempIndex = gun_index;
  16649. }
  16650. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16651. {
  16652. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16653. {
  16654. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  16655. }
  16656. }// END OF CHAdeMO_QUANTITY
  16657. }
  16658. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16659. {
  16660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16661. {
  16662. tempIndex = ((gun_index==2) ? 1: 0);
  16663. }
  16664. else
  16665. {
  16666. tempIndex = gun_index;
  16667. }
  16668. for (int index = 0; index < CCS_QUANTITY; index++)
  16669. {
  16670. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16671. {
  16672. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  16673. }
  16674. }// END OF CCS_QUANTITY
  16675. }
  16676. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16677. {
  16678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16679. {
  16680. tempIndex = ((gun_index==2) ? 1: 0);
  16681. }
  16682. else
  16683. {
  16684. tempIndex = gun_index;
  16685. }
  16686. for (int index = 0; index < GB_QUANTITY; index++)
  16687. {
  16688. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16689. {
  16690. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  16691. }
  16692. }// END OF GB_QUANTITY
  16693. }
  16694. else if(gunType[gun_index] == GUN_TYPE_DO)
  16695. {
  16696. tempIndex = gun_index;
  16697. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16698. {
  16699. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16700. {
  16701. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  16702. }
  16703. }
  16704. }
  16705. else
  16706. {
  16707. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16708. {
  16709. tempIndex = 2;
  16710. }
  16711. else
  16712. {
  16713. tempIndex = gun_index;
  16714. }
  16715. for (int index = 0; index < AC_QUANTITY; index++)
  16716. {
  16717. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16718. {
  16719. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  16720. }
  16721. }// END OF AC_QUANTITY
  16722. }
  16723. //Stop Transaction Time
  16724. struct timeval tmnow;
  16725. struct tm *tm;
  16726. char buf[28];//, usec_buf[6];
  16727. gettimeofday(&tmnow, NULL);
  16728. time_t t;
  16729. t = time(NULL);
  16730. /*UTC time and date*/
  16731. tm = gmtime(&t);
  16732. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  16733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  16734. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  16735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  16736. random_uuid(guid);
  16737. /***********************************transactionData******************************************************/
  16738. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  16739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  16740. //=================================
  16741. //1. Transaction_Begin
  16742. //=================================
  16743. //============================== Energy.Active.Import.Interval ===========================================
  16744. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16745. {
  16746. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  16747. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16748. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  16749. 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*/]);
  16750. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16751. if((gunType[gun_index] == GUN_TYPE_CHAdeMO)||(gunType[gun_index] == GUN_TYPE_CCS)||(gunType[gun_index] == GUN_TYPE_GBT)||(gunType[gun_index] == GUN_TYPE_DO))
  16752. {
  16753. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  16754. }
  16755. else
  16756. {
  16757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  16758. }
  16759. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  16760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16761. }
  16762. //=================================
  16763. //2. Transaction_End
  16764. //=================================
  16765. //2.1====================================== Current.Import L1 ==============================================
  16766. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16767. {
  16768. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  16769. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16770. {
  16771. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16772. {
  16773. tempIndex = ((gun_index==2) ? 1: 0);
  16774. }
  16775. else
  16776. {
  16777. tempIndex = gun_index;
  16778. }
  16779. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16780. {
  16781. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16782. {
  16783. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16784. }
  16785. }// End of for CHAdeMO_QUANTITY
  16786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16787. }
  16788. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16789. {
  16790. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16791. {
  16792. tempIndex = ((gun_index==2) ? 1: 0);
  16793. }
  16794. else
  16795. {
  16796. tempIndex = gun_index;
  16797. }
  16798. for (int index = 0; index < CCS_QUANTITY; index++)
  16799. {
  16800. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16801. {
  16802. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16803. }
  16804. }// End of for CCS_QUANTITY
  16805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16806. }
  16807. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16808. {
  16809. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16810. {
  16811. tempIndex = ((gun_index==2) ? 1: 0);
  16812. }
  16813. else
  16814. {
  16815. tempIndex = gun_index;
  16816. }
  16817. for (int index = 0; index < GB_QUANTITY; index++)
  16818. {
  16819. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16820. {
  16821. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16822. }
  16823. }// End of for GB_QUANTITY
  16824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16825. }
  16826. else if(gunType[gun_index] == GUN_TYPE_DO)
  16827. {
  16828. tempIndex = gun_index;
  16829. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16830. {
  16831. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16832. {
  16833. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  16834. }
  16835. }
  16836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  16837. }
  16838. else
  16839. {
  16840. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16841. {
  16842. tempIndex = 2;
  16843. }
  16844. else
  16845. {
  16846. tempIndex = gun_index;
  16847. }
  16848. for (int index = 0; index < AC_QUANTITY; index++)
  16849. {
  16850. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16851. {
  16852. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  16853. }
  16854. }// End of for AC_QUANTITY
  16855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16856. }
  16857. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  16859. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  16860. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  16861. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  16862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16863. }
  16864. //2.2===================================== Energy.Active.Import.Interval ==========================================
  16865. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  16866. {
  16867. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16868. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16869. {
  16870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16871. {
  16872. tempIndex = ((gun_index==2) ? 1: 0);
  16873. }
  16874. else
  16875. {
  16876. tempIndex = gun_index;
  16877. }
  16878. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16879. {
  16880. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16881. {
  16882. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16883. }
  16884. }// END OF CHAdeMO_QUANTITY
  16885. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16886. }
  16887. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16888. {
  16889. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16890. {
  16891. tempIndex = ((gun_index==2) ? 1: 0);
  16892. }
  16893. else
  16894. {
  16895. tempIndex = gun_index;
  16896. }
  16897. for (int index = 0; index < CCS_QUANTITY; index++)
  16898. {
  16899. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16900. {
  16901. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16902. }
  16903. }// END OF CCS_QUANTITY
  16904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16905. }
  16906. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16907. {
  16908. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16909. {
  16910. tempIndex = ((gun_index==2) ? 1: 0);
  16911. }
  16912. else
  16913. {
  16914. tempIndex = gun_index;
  16915. }
  16916. for (int index = 0; index < GB_QUANTITY; index++)
  16917. {
  16918. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16919. {
  16920. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16921. }
  16922. }// END OF GB_QUANTITY
  16923. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16924. }
  16925. else if(gunType[gun_index] == GUN_TYPE_DO)
  16926. {
  16927. tempIndex = gun_index;
  16928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16929. {
  16930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16931. {
  16932. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16933. }
  16934. }
  16935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16936. }
  16937. else
  16938. {
  16939. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16940. {
  16941. tempIndex = 2;
  16942. }
  16943. else
  16944. {
  16945. tempIndex = gun_index;
  16946. }
  16947. for (int index = 0; index < AC_QUANTITY; index++)
  16948. {
  16949. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16950. {
  16951. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16952. }
  16953. }// END OF AC_QUANTITY
  16954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16955. }
  16956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16959. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16961. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16962. }
  16963. //2.3====================================== Power.Active.Import =========================================
  16964. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16965. {
  16966. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16967. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16968. {
  16969. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16970. {
  16971. tempIndex = ((gun_index==2) ? 1: 0);
  16972. }
  16973. else
  16974. {
  16975. tempIndex = gun_index;
  16976. }
  16977. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16978. {
  16979. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16980. {
  16981. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16982. }
  16983. } // End for CHAdeMO_QUANTITY
  16984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16985. }
  16986. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16987. {
  16988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16989. {
  16990. tempIndex = ((gun_index==2) ? 1: 0);
  16991. }
  16992. else
  16993. {
  16994. tempIndex = gun_index;
  16995. }
  16996. for (int index = 0; index < CCS_QUANTITY; index++)
  16997. {
  16998. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16999. {
  17000. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17001. }
  17002. } // END for CCS_QUANTITY
  17003. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17004. }
  17005. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17006. {
  17007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17008. {
  17009. tempIndex = ((gun_index==2) ? 1: 0);
  17010. }
  17011. else
  17012. {
  17013. tempIndex = gun_index;
  17014. }
  17015. for (int index = 0; index < GB_QUANTITY; index++)
  17016. {
  17017. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17018. {
  17019. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17020. }
  17021. }// END for GB_QUANTITY
  17022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17023. }
  17024. else if(gunType[gun_index] == GUN_TYPE_DO)
  17025. {
  17026. tempIndex = gun_index;
  17027. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17028. {
  17029. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17030. {
  17031. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17032. }
  17033. }
  17034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  17035. }
  17036. else
  17037. {
  17038. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17039. {
  17040. tempIndex = 2;
  17041. }
  17042. else
  17043. {
  17044. tempIndex = gun_index;
  17045. }
  17046. for (int index = 0; index < AC_QUANTITY; index++)
  17047. {
  17048. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17049. {
  17050. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  17051. }
  17052. } // END for AC_QUANTITY
  17053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17054. }
  17055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17056. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  17057. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  17058. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  17059. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  17060. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  17061. }
  17062. //2.4====================================== Voltage L1 ====================================================
  17063. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17064. {
  17065. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17066. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17067. {
  17068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17069. {
  17070. tempIndex = ((gun_index==2) ? 1: 0);
  17071. }
  17072. else
  17073. {
  17074. tempIndex = gun_index;
  17075. }
  17076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17077. {
  17078. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17079. {
  17080. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17081. }
  17082. } // END OF FOR CHAdeMO_QUANTITY
  17083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17084. }
  17085. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17086. {
  17087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17088. {
  17089. tempIndex = ((gun_index==2) ? 1: 0);
  17090. }
  17091. else
  17092. {
  17093. tempIndex = gun_index;
  17094. }
  17095. for (int index = 0; index < CCS_QUANTITY; index++)
  17096. {
  17097. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17098. {
  17099. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17100. }
  17101. } // END OF FOR CCS_QUANTITY
  17102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17103. }
  17104. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17105. {
  17106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17107. {
  17108. tempIndex = ((gun_index==2) ? 1: 0);
  17109. }
  17110. else
  17111. {
  17112. tempIndex = gun_index;
  17113. }
  17114. for (int index = 0; index < GB_QUANTITY; index++)
  17115. {
  17116. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17117. {
  17118. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17119. }
  17120. } // END OF FOR GB_QUANTITY
  17121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17122. }
  17123. else if(gunType[gun_index] == GUN_TYPE_DO)
  17124. {
  17125. tempIndex = gun_index;
  17126. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17127. {
  17128. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17129. {
  17130. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  17131. }
  17132. }
  17133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  17134. }
  17135. else
  17136. {
  17137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17138. {
  17139. tempIndex = 2;
  17140. }
  17141. else
  17142. {
  17143. tempIndex = gun_index;
  17144. }
  17145. for (int index = 0; index < AC_QUANTITY; index++)
  17146. {
  17147. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17148. {
  17149. 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
  17150. }
  17151. } // END OF FOR AC_QUANTITY
  17152. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17153. }
  17154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  17156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  17157. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  17158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  17159. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17160. }
  17161. //2.5============================================== End SoC =========================================================
  17162. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17163. {
  17164. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17165. 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))
  17166. {
  17167. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17168. {
  17169. tempIndex = ((gun_index==2) ? 1: 0);
  17170. }
  17171. else
  17172. {
  17173. tempIndex = gun_index;
  17174. }
  17175. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17176. {
  17177. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17178. {
  17179. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17180. {
  17181. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  17182. }
  17183. }
  17184. }
  17185. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17186. {
  17187. for (int index = 0; index < CCS_QUANTITY; index++)
  17188. {
  17189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17190. {
  17191. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  17192. }
  17193. }
  17194. }
  17195. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17196. {
  17197. for (int index = 0; index < GB_QUANTITY; index++)
  17198. {
  17199. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17200. {
  17201. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  17202. }
  17203. }
  17204. }
  17205. else if(gunType[gun_index] == GUN_TYPE_DO)
  17206. {
  17207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17208. {
  17209. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17210. {
  17211. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  17212. }
  17213. }
  17214. }
  17215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  17217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  17219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  17220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17221. } // END FOR DC CASE
  17222. }
  17223. //2.6====================================== Current.Import L2 ==============================================
  17224. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17225. {
  17226. // AC 3 phase L2 current
  17227. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17228. {
  17229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17230. {
  17231. tempIndex = 2;
  17232. }
  17233. else
  17234. {
  17235. tempIndex = gun_index;
  17236. }
  17237. for (int index = 0; index < AC_QUANTITY; index++)
  17238. {
  17239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17240. {
  17241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  17242. }
  17243. }// End of for AC_QUANTITY
  17244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  17245. }
  17246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  17248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  17249. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  17250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17251. }
  17252. //2.7====================================== Current.Import L3 ==============================================
  17253. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  17254. {
  17255. // AC 3 phase L3 current
  17256. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17257. {
  17258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17259. {
  17260. tempIndex = 2;
  17261. }
  17262. else
  17263. {
  17264. tempIndex = gun_index;
  17265. }
  17266. for (int index = 0; index < AC_QUANTITY; index++)
  17267. {
  17268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17269. {
  17270. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  17271. }
  17272. }// End of for AC_QUANTITY
  17273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  17274. }
  17275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  17277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  17278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  17279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  17280. }
  17281. //2.9====================================== Voltage L2 ====================================================
  17282. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17283. {
  17284. // AC 3 phase L2 volatge
  17285. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17286. {
  17287. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17288. {
  17289. tempIndex = 2;
  17290. }
  17291. else
  17292. {
  17293. tempIndex = gun_index;
  17294. }
  17295. for (int index = 0; index < AC_QUANTITY; index++)
  17296. {
  17297. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17298. {
  17299. 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
  17300. }
  17301. } // END OF FOR AC_QUANTITY
  17302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  17303. }
  17304. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  17306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  17307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  17308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17309. }
  17310. //2.10====================================== Voltage L3 ====================================================
  17311. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  17312. {
  17313. // AC 3 phase L3 volatge
  17314. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  17315. {
  17316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17317. {
  17318. tempIndex = 2;
  17319. }
  17320. else
  17321. {
  17322. tempIndex = gun_index;
  17323. }
  17324. for (int index = 0; index < AC_QUANTITY; index++)
  17325. {
  17326. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17327. {
  17328. 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
  17329. }
  17330. } // END OF FOR AC_QUANTITY
  17331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  17332. }
  17333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  17334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  17335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  17336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  17337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  17338. }
  17339. //====================== Start SoC ================================
  17340. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  17341. {
  17342. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  17343. 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))
  17344. {
  17345. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  17346. {
  17347. tempIndex = ((gun_index==2) ? 1: 0);
  17348. }
  17349. else
  17350. {
  17351. tempIndex = gun_index;
  17352. }
  17353. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17354. {
  17355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17356. {
  17357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  17358. {
  17359. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  17360. }
  17361. }
  17362. }
  17363. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17364. {
  17365. for (int index = 0; index < CCS_QUANTITY; index++)
  17366. {
  17367. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17368. {
  17369. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  17370. }
  17371. }
  17372. }
  17373. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17374. {
  17375. for (int index = 0; index < GB_QUANTITY; index++)
  17376. {
  17377. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17378. {
  17379. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  17380. }
  17381. }
  17382. }
  17383. else if(gunType[gun_index] == GUN_TYPE_DO)
  17384. {
  17385. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17386. {
  17387. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17388. {
  17389. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  17390. }
  17391. }
  17392. }
  17393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  17394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  17395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  17396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  17397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  17398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  17399. } // END FOR DC CASE
  17400. }
  17401. //======================================== Message create ==============================================
  17402. json_object *StopTransaction = json_object_new_object();
  17403. json_object *transactionDatas = json_object_new_array();
  17404. json_object *sampledValues = json_object_new_array();
  17405. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  17406. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  17407. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  17408. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  17409. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  17410. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  17411. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  17412. {
  17413. json_object *transactionData = json_object_new_object();
  17414. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  17415. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  17416. {
  17417. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  17418. {
  17419. json_object *sampledValue = json_object_new_object();
  17420. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  17421. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  17422. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  17423. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  17424. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  17425. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  17426. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  17427. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  17428. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  17429. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  17430. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  17431. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  17432. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  17433. json_object_array_add(sampledValues, sampledValue);
  17434. }
  17435. }
  17436. json_object_object_add(transactionData, "sampledValue", sampledValues);
  17437. json_object_array_add(transactionDatas, transactionData);
  17438. }
  17439. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  17440. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  17441. ,MESSAGE_TYPE_CALL
  17442. ,guid
  17443. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  17444. json_object_put(StopTransaction);
  17445. // Check File "TempStopTransaction" Exist
  17446. if((access(TempStopTransaction,F_OK))!=-1)
  17447. {
  17448. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  17449. fclose(fopen(TempStopTransaction, "w"));
  17450. }
  17451. else
  17452. {
  17453. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  17454. FILE *log = fopen(TempStopTransaction, "w+");
  17455. if(log == NULL)
  17456. {
  17457. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  17458. return ;
  17459. }
  17460. else
  17461. {
  17462. fclose(log);
  17463. }
  17464. }
  17465. //Add TempStopTransaction | Update TempStopTransaction
  17466. // open file for writing
  17467. FILE *outfile;
  17468. outfile = fopen (TempStopTransaction, "a");
  17469. //DEBUG_INFO("data = %s\n", queuedata);
  17470. fputs(queuedata, outfile);
  17471. fputs("\n", outfile);
  17472. fclose (outfile);
  17473. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17474. }
  17475. void checkTempStopTransaction(int gun_index)
  17476. {
  17477. FILE *fptr1;
  17478. char ch;
  17479. char str[QUEUE_MESSAGE_LENGTH]={0};
  17480. char guid[37]={0};
  17481. char tempdata[65]={0};
  17482. char connectorStr[2]={0};
  17483. char TempStopTransaction[256];
  17484. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  17485. fptr1 = fopen(TempStopTransaction, "r");
  17486. //TempStopTransaction格式: 槍號,StopTransaction封包
  17487. if (!fptr1)
  17488. {
  17489. //printf(" File not found or unable to open the input file!!\n");
  17490. return ;
  17491. }
  17492. ch=fgetc(fptr1);
  17493. //printf(" Now the content of the file %s is : \n",fname);
  17494. rewind(fptr1);
  17495. if(ch!=EOF)
  17496. {
  17497. // copy all contents to the temporary file except the specific line
  17498. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  17499. {
  17500. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  17501. if(str[0]=='\0')
  17502. {
  17503. break;
  17504. }
  17505. //TempStopTransaction格式: 槍號,StopTransaction封包
  17506. strncpy(connectorStr, str, 1);
  17507. if(atoi(connectorStr) != (gun_index+1))
  17508. {
  17509. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  17510. fclose(fptr1);
  17511. return ;
  17512. }
  17513. //random_uuid(guid);
  17514. strncpy(guid, str+6, 36); //copy guid
  17515. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  17516. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  17517. {
  17518. //DEBUG_INFO("StopTransaction mapitem pass\n");
  17519. }
  17520. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  17521. OCPP_insert_transaction_msg(NO, str);
  17522. memset(str,0,ARRAY_SIZE(str));
  17523. }
  17524. }
  17525. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  17526. fclose(fptr1);
  17527. remove(TempStopTransaction); // remove the original file
  17528. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  17529. }
  17530. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  17531. {
  17532. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  17533. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  17534. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  17535. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  17536. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  17537. }
  17538. int GetWebSocketPingInterval(void)
  17539. {
  17540. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  17541. }
  17542. int GetServerSign(void)
  17543. {
  17544. return server_sign;
  17545. }
  17546. uint8_t GetOcppSecurityProfile()
  17547. {
  17548. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  17549. }
  17550. void GetOcppChargerBoxId(uint8_t *data)
  17551. {
  17552. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  17553. }
  17554. void GetOcppSecurityPassword(uint8_t *data)
  17555. {
  17556. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  17557. }
  17558. void SetOcppVersion(uint8_t *version)
  17559. {
  17560. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  17561. DEBUG_INFO("ocpp version: %s\n", version);
  17562. if(strstr((char*)version, "ocpp1.6") != NULL)
  17563. {
  17564. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  17565. }
  17566. else if(strstr((char*)version, "ocpp2.0") != NULL)
  17567. {
  17568. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  17569. system("pkill OcppBackend");
  17570. }
  17571. }
  17572. void SetServerSign(int value)
  17573. {
  17574. server_sign = value;
  17575. }
  17576. int GetBootNotificationInterval(void)
  17577. {
  17578. return BootNotificationInterval;
  17579. }
  17580. int GetInternetConn(void)
  17581. {
  17582. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  17583. }
  17584. int GetBackendConnectionTimeout(void)
  17585. {
  17586. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  17587. }
  17588. int isConnectorInitMode(int gun_index)
  17589. {
  17590. int tempIndex = 0;
  17591. int result = TRUE;
  17592. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  17593. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  17594. {
  17595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17596. {
  17597. tempIndex = ((gun_index==2) ? 1: 0);
  17598. }
  17599. else
  17600. {
  17601. tempIndex = gun_index;
  17602. }
  17603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17604. {
  17605. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  17606. {
  17607. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17608. } //end of the same index
  17609. }//end of for CHAdeMO_QUANTITY
  17610. }
  17611. else if(gunType[gun_index] == GUN_TYPE_CCS)
  17612. {
  17613. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17614. {
  17615. tempIndex = ((gun_index==2) ? 1: 0);
  17616. }
  17617. else
  17618. {
  17619. tempIndex = gun_index;
  17620. }
  17621. for (int index = 0; index < CCS_QUANTITY; index++)
  17622. {
  17623. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  17624. {
  17625. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17626. } //end of the same index
  17627. } // end of for CCS_QUANTITY
  17628. }
  17629. else if(gunType[gun_index] == GUN_TYPE_GBT)
  17630. {
  17631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17632. {
  17633. tempIndex = ((gun_index==2) ? 1: 0);
  17634. }
  17635. else
  17636. {
  17637. tempIndex = gun_index;
  17638. }
  17639. for (int index = 0; index < GB_QUANTITY; index++)
  17640. {
  17641. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  17642. {
  17643. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17644. } //end of the same index
  17645. } // end of for GB_QUANTITY
  17646. }
  17647. else if(gunType[gun_index] == GUN_TYPE_DO)
  17648. {
  17649. tempIndex = gun_index;
  17650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17651. {
  17652. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  17653. {
  17654. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17655. } //end of the same index
  17656. }
  17657. }
  17658. else
  17659. {
  17660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17661. {
  17662. tempIndex = 2;
  17663. }
  17664. else
  17665. {
  17666. tempIndex = gun_index;
  17667. }
  17668. for (int index = 0; index < AC_QUANTITY; index++)
  17669. {
  17670. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  17671. {
  17672. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  17673. }//end of the same index
  17674. }//end of for AC_QUANTITY
  17675. }
  17676. return result;
  17677. }
  17678. void refreshProcDogTimer()
  17679. {
  17680. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  17681. }
  17682. void InitialSystemValue(void)
  17683. {
  17684. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  17685. locallistVersion=0;
  17686. BootNotificationInterval = 0;
  17687. authorizeRetryTimes = 0;
  17688. GunStatusInterval = 10;
  17689. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  17690. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  17691. //Hear Beat
  17692. HeartBeatWithNOResponse = 0;
  17693. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  17694. FirstHeartBeat = 0;
  17695. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  17696. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  17697. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  17698. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  17699. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  17700. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  17701. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  17702. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  17703. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  17704. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  17705. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  17706. //Status && ConnectorPlugIn Setting
  17707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17708. {
  17709. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  17710. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  17711. }
  17712. for (int index = 0; index < CCS_QUANTITY; index++)
  17713. {
  17714. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  17715. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  17716. }
  17717. for (int index = 0; index < GB_QUANTITY; index++)
  17718. {
  17719. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  17720. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  17721. }
  17722. for (int index = 0; index < AC_QUANTITY; index++)
  17723. {
  17724. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  17725. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  17726. }
  17727. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17728. {
  17729. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  17730. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  17731. }
  17732. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  17733. {
  17734. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  17735. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  17736. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  17737. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  17738. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  17739. }
  17740. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  17741. refreshStartTimer(&clientTime.Heartbeat);
  17742. sleep(1);
  17743. }
  17744. void LWS_Send(char *str)
  17745. {
  17746. //=====================================================
  17747. // Check InternetConn 0: disconnected, 1: connected
  17748. //====================================================
  17749. if(GetOcppConnStatus() == 0)
  17750. {
  17751. DEBUG_INFO("offline now !!!\n");
  17752. return;
  17753. }
  17754. // Only disable isWebsocketSendable operation initiated by charger
  17755. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17756. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17757. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17758. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17759. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17760. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17761. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17762. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17763. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17764. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17765. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17766. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17767. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17768. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17769. {
  17770. isWebsocketSendable = 0;
  17771. }
  17772. pthread_mutex_lock(&lock_send);
  17773. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17774. sprintf((char *)SendBuffer, "%s", str);
  17775. SendBufLen = strlen(str);
  17776. pthread_mutex_unlock(&lock_send);
  17777. lws_callback_on_writable(wsi_client);
  17778. //lws_service(context, 0);
  17779. //sleep(1);
  17780. }
  17781. void LWS_SendNow(char *str)
  17782. {
  17783. //=====================================================
  17784. // Check InternetConn 0: disconnected, 1: connected
  17785. //====================================================
  17786. if(GetOcppConnStatus() == 0)
  17787. {
  17788. DEBUG_INFO("offline now !!!\n");
  17789. return;
  17790. }
  17791. // Only disable isWebsocketSendable operation initiated by charger
  17792. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17793. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17794. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17795. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17796. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17797. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17798. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17799. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17800. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17801. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17802. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17803. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17804. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17805. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17806. {
  17807. isWebsocketSendable = 0;
  17808. }
  17809. pthread_mutex_lock(&lock_send);
  17810. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17811. sprintf((char *)SendBuffer, "%s", str);
  17812. SendBufLen = strlen(str);
  17813. pthread_mutex_unlock(&lock_send);
  17814. lws_callback_on_writable(wsi_client);
  17815. lws_service(context, 0);
  17816. //sleep(1);
  17817. }