MessageHandler.c 847 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknown key
  21. //===============================
  22. static char unknownkey[10][36] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int locallistVersion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  58. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  59. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  60. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  61. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  62. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  63. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  64. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  65. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  66. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  67. static int TransactionMessageAttemptsValue = 0;
  68. static int TransactionMessageRetryIntervalValue = 0;
  69. static int TempMeterValueInterval = 0;
  70. static struct OCPPAuthLocalElemet
  71. {
  72. int listVersionInt;
  73. char idTagstr[21];
  74. char parentIdTag[21];
  75. char expiryDate[36];
  76. char idTagstatus[16];
  77. }idTagQuery;
  78. //=============================================
  79. // OCPP HeartBeat Response Not Receive Counts
  80. //============================================
  81. static int HeartBeatWithNOResponse = 0;
  82. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  83. extern sqlite3 *db;
  84. int TransactionMessageAttemptsGet(void);
  85. int TransactionMessageRetryIntervalGet(void);
  86. int GetOcppConnStatus(void);
  87. void SetOcppConnStatus(uint8_t status);
  88. int setKeyValue(char *key, char *value);
  89. void OCPP_get_TableAuthlocalAllData(void);
  90. void processUnkownKey(void);
  91. struct StructOCPPMeterValue
  92. {
  93. unsigned char TimeStamp[28];
  94. struct StructSampledValue SampledValue[10];
  95. };
  96. struct ClientTime
  97. {
  98. unsigned int Heartbeat;
  99. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  100. unsigned int StartTransaction;
  101. unsigned int StopTransaction;
  102. unsigned int MeterValues[CONNECTOR_QUANTITY];
  103. }clientTime;
  104. typedef union
  105. {
  106. //Operations Initiated by Central System
  107. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  108. struct
  109. {
  110. //CsMsgValue[0]
  111. unsigned char StatusNotificationReq:1; //bit 0,
  112. unsigned char StatusNotificationConf:1; //bit 1,
  113. unsigned char TriggerMeterValue:1; //bit 2,
  114. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  115. unsigned char isOnCharging:1; //bit 4,
  116. unsigned char :3; //bit5~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // TTIA routine
  356. //=========================================
  357. int sendTTIAInfo(uint8_t gun_index)
  358. {
  359. static int sn = 0;
  360. int result = FAIL;
  361. struct hostent *server;
  362. int udp_socket_fd;
  363. struct sockaddr_in dest_addr = {0};
  364. uint8_t tx_buf[80] = {0};
  365. uint8_t logBuf[256]= {0};
  366. uint8_t tx_len, tempIndex, socStart, socEnd;
  367. uint16_t PresentChargedEnergy;
  368. struct tm tmStart, tmEnd;
  369. DEBUG_INFO("sendTTIAInfo...\n");
  370. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  371. {
  372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  373. {
  374. tempIndex = ((gun_index==2) ? 1: 0);
  375. }
  376. else
  377. {
  378. tempIndex = gun_index;
  379. }
  380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  381. {
  382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  383. {
  384. socStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc;
  385. socEnd = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  386. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*10);
  387. }
  388. }
  389. }
  390. else if(gunType[gun_index] == GUN_TYPE_CCS)
  391. {
  392. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  393. {
  394. tempIndex = ((gun_index==2) ? 1: 0);
  395. }
  396. else
  397. {
  398. tempIndex = gun_index;
  399. }
  400. for (int index = 0; index < CCS_QUANTITY; index++)
  401. {
  402. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  403. {
  404. socStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc;
  405. socEnd = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  406. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*10);
  407. }
  408. }
  409. }
  410. else if(gunType[gun_index] == GUN_TYPE_GBT)
  411. {
  412. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  413. {
  414. tempIndex = ((gun_index==2) ? 1: 0);
  415. }
  416. else
  417. {
  418. tempIndex = gun_index;
  419. }
  420. for (int index = 0; index < GB_QUANTITY; index++)
  421. {
  422. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  423. {
  424. socStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc;
  425. socEnd = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  426. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*10);
  427. }
  428. }
  429. }
  430. else if(gunType[gun_index] == GUN_TYPE_DO)
  431. {
  432. tempIndex = gun_index;
  433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  434. {
  435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  436. {
  437. socStart = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc;
  438. socEnd = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  439. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*10);
  440. }
  441. }
  442. }
  443. else
  444. {
  445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  446. {
  447. tempIndex = 2;
  448. }
  449. else
  450. {
  451. tempIndex = gun_index;
  452. }
  453. for (int index = 0; index < AC_QUANTITY; index++)
  454. {
  455. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  456. {
  457. socStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatteryStartSoc;
  458. socEnd = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].EvBatterySoc;
  459. PresentChargedEnergy = (uint16_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*10);
  460. }
  461. }// END
  462. }
  463. // Message assembly
  464. sprintf((char*)&tx_buf[0], "APTS"); // Protocol ID
  465. tx_buf[4] = 0x02; // Protocol Version
  466. tx_buf[5] = 0xb0; // Message ID
  467. tx_buf[6] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId & 0xff; // CustomerID low byte
  468. tx_buf[7] = (ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId>>8) & 0xff; // CustomerID high byte
  469. tx_buf[8] = 0x00; // CarID low byte
  470. tx_buf[9] = 0x00; // CarID high byte
  471. tx_buf[10] = 0x00; // ID Storage
  472. tx_buf[11] = 0x00; // Driver lowest byte
  473. tx_buf[12] = 0x00; // Driver 2nd byte
  474. tx_buf[13] = 0x00; // Driver 3rd byte
  475. tx_buf[14] = 0x00; // Driver highest byte
  476. tx_buf[15] = sn & 0xff; // Sequence SN low byte
  477. tx_buf[16] = (sn>>8) & 0xff; // Sequence SN high byte
  478. tx_buf[17] = 0x00; // Reserve
  479. tx_buf[18] = 60 & 0xff; // Payload length low byte
  480. tx_buf[19] = (60>>8) & 0xff; // Payload length high byte
  481. // EVSE provider
  482. memcpy((char*)&tx_buf[20], ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider, 15);
  483. // EVSE provider
  484. tx_buf[35] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo;
  485. // EVSE id
  486. tx_buf[36] = ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId;
  487. // Connector id
  488. tx_buf[37] = gun_index;
  489. // EVSE station
  490. memcpy((char*)&tx_buf[38], ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation, 15);
  491. // Vehicle SN
  492. memcpy(&tx_buf[53], &ShmOCPP16Data->StartTransaction[gun_index].IdTag, 8);
  493. // Mileage
  494. tx_buf[61] = 0x00; // lowest byte
  495. tx_buf[62] = 0x00; // 2nd byte
  496. tx_buf[63] = 0x00; // highest byte
  497. // Start date time 6 bytes
  498. if((sscanf((char*)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  499. {
  500. tx_buf[64] = (tmStart.tm_year-2000);
  501. tx_buf[65] = tmStart.tm_mon;
  502. tx_buf[66] = tmStart.tm_mday;
  503. tx_buf[67] = tmStart.tm_hour;
  504. tx_buf[68] = tmStart.tm_min;
  505. tx_buf[69] = tmStart.tm_sec;
  506. }
  507. // Stop date time 6 bytes
  508. 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))
  509. {
  510. tx_buf[70] = (tmEnd.tm_year-2000);
  511. tx_buf[71] = tmEnd.tm_mon;
  512. tx_buf[72] = tmEnd.tm_mday;
  513. tx_buf[73] = tmEnd.tm_hour;
  514. tx_buf[74] = tmEnd.tm_min;
  515. tx_buf[75] = tmEnd.tm_sec;
  516. }
  517. // Session energy 2 bytes
  518. tx_buf[76] = PresentChargedEnergy & 0xff;
  519. tx_buf[77] = (PresentChargedEnergy>>8) & 0xff;
  520. // Start SOC 1 byte
  521. tx_buf[78] = socStart;
  522. // Stop SOC 1 byte
  523. tx_buf[79] = socEnd;
  524. // Open socket
  525. udp_socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  526. if(udp_socket_fd == -1)
  527. {
  528. DEBUG_ERROR("UDP socket create failed!\n");
  529. }
  530. else
  531. {
  532. // Get server DNS entry
  533. server = gethostbyname((char*)ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  534. if (server == NULL)
  535. {
  536. DEBUG_ERROR("ERROR, no such host as %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  537. }
  538. else
  539. {
  540. // Build the server's Internet address
  541. bzero((char *) &dest_addr, sizeof(dest_addr));
  542. dest_addr.sin_family = AF_INET;
  543. bcopy((char *)server->h_addr, (char *)&dest_addr.sin_addr.s_addr, server->h_length);
  544. dest_addr.sin_port = htons(ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  545. if((tx_len = sendto(udp_socket_fd, tx_buf, ARRAY_SIZE(tx_buf), 0, &dest_addr, sizeof(dest_addr))) >= 0)
  546. {
  547. for(uint8_t idx=0;idx<ARRAY_SIZE(tx_buf);idx++)
  548. {
  549. sprintf((char*)logBuf, "%s %02X", logBuf, tx_buf[idx]);
  550. }
  551. DEBUG_TTIA_INFO("TX raw data length: %d\n", tx_len);
  552. DEBUG_TTIA_INFO("Message raw: %s\n", logBuf);
  553. DEBUG_TTIA_INFO("OCPP Transaction ID: %d\n", ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  554. DEBUG_TTIA_INFO("TTIA server address: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  555. DEBUG_TTIA_INFO("TTIA server port: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  556. DEBUG_TTIA_INFO("---------- Header ----------\n");
  557. DEBUG_TTIA_INFO("ProtocolID: APTS\n");
  558. DEBUG_TTIA_INFO("ProtocolVer: 0x02\n");
  559. DEBUG_TTIA_INFO("MessageID: 0xB0\n");
  560. DEBUG_TTIA_INFO("CustomerID: 0x%04X\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  561. DEBUG_TTIA_INFO("CarID: 0x0000\n");
  562. DEBUG_TTIA_INFO("IDStorage: 0x00\n");
  563. DEBUG_TTIA_INFO("DriverID: 0x00000000\n");
  564. DEBUG_TTIA_INFO("Sequence: %d\n", sn);
  565. DEBUG_TTIA_INFO("Reserved: 0x00\n");
  566. DEBUG_TTIA_INFO("Len: 0x3C\n");
  567. DEBUG_TTIA_INFO("--------- Payload ---------\n");
  568. DEBUG_TTIA_INFO("EquipmentProvider: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  569. DEBUG_TTIA_INFO("TransportationCompanyNo: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  570. DEBUG_TTIA_INFO("ChargeBoxId: %d\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  571. DEBUG_TTIA_INFO("Gun index: %d\n", gun_index);
  572. DEBUG_TTIA_INFO("evseStation: %s\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  573. DEBUG_TTIA_INFO("EV vehicle: %s\n", ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  574. DEBUG_TTIA_INFO("EV mileage: 000000\n");
  575. DEBUG_TTIA_INFO("Session start data time: %s\n", ShmOCPP16Data->StartTransaction[gun_index].Timestamp);
  576. DEBUG_TTIA_INFO("Session stop data time: %s\n", ShmOCPP16Data->StopTransaction[gun_index].Timestamp);
  577. DEBUG_TTIA_INFO("Session charged energy (kwh): %f\n", (PresentChargedEnergy/10.0));
  578. DEBUG_TTIA_INFO("Session start SOC: %d\n", socStart);
  579. DEBUG_TTIA_INFO("Session end SOC: %d\n", socEnd);
  580. DEBUG_TTIA_INFO("=========================================\n");
  581. sn++;
  582. result = PASS;
  583. }
  584. else
  585. {
  586. DEBUG_ERROR("UDP sent out fail.\n");
  587. }
  588. }
  589. }
  590. return result;
  591. }
  592. //=========================================
  593. // Save configuration
  594. //=========================================
  595. int runShellCmd(const char*cmd)
  596. {
  597. int result = FAIL;
  598. char buf[256];
  599. FILE *fp;
  600. fp = popen(cmd, "r");
  601. if(fp != NULL)
  602. {
  603. while(fgets(buf, sizeof(buf), fp) != NULL)
  604. {
  605. DEBUG_INFO("%s\n", buf);
  606. }
  607. result = PASS;
  608. }
  609. pclose(fp);
  610. return result;
  611. }
  612. int StoreUsrConfigData(struct SysConfigData *UsrData)
  613. {
  614. int result = PASS;
  615. int fd,wrd;
  616. unsigned int i,Chk;
  617. unsigned char *ptr, *BufTmp;
  618. int MtdBlockSize = 0x300000;
  619. Chk=0;
  620. ptr=(unsigned char *)UsrData;
  621. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  622. {
  623. memset(BufTmp,0,MtdBlockSize);
  624. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  625. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  626. Chk+=*(BufTmp+i);
  627. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  628. // Output configuration to file.
  629. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  630. if (fd < 0)
  631. {
  632. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  633. free(BufTmp);
  634. return 0;
  635. }
  636. wrd=write(fd, BufTmp, MtdBlockSize);
  637. close(fd);
  638. if(wrd<MtdBlockSize)
  639. {
  640. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  641. free(BufTmp);
  642. return 0;
  643. }
  644. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  645. DEBUG_INFO("Erase /dev/mtd10.\n");
  646. runShellCmd("flash_erase /dev/mtd10 0 0");
  647. DEBUG_INFO("Write /dev/mtd10.\n");
  648. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  649. DEBUG_INFO("Erase /dev/mtd11.\n");
  650. runShellCmd("flash_erase /dev/mtd11 0 0");
  651. DEBUG_INFO("Write /dev/mtd11.\n");
  652. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  653. system("rm -f /mnt/EvseConfig.bin");
  654. DEBUG_INFO("EvseConfig write to flash OK\n");
  655. }
  656. else
  657. {
  658. DEBUG_ERROR("alloc BlockSize NG\r\n");
  659. result = FAIL;
  660. }
  661. if(BufTmp!=NULL)
  662. free(BufTmp);
  663. return result;
  664. }
  665. //=========================================
  666. // Sqlite3 related function
  667. //=========================================
  668. static int selectSqlCount = 0;
  669. static int callback(void *data, int argc, char **argv, char **azColName){
  670. int i;
  671. //printf("%s: ", (const char*)data);
  672. selectSqlCount = argc;
  673. for(i = 0; i<argc; i++){
  674. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  675. }
  676. //printf("\n");
  677. return 0;
  678. }
  679. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  680. //int i;
  681. //printf("%s:\n", (const char*)data);
  682. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  683. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  684. return 0;
  685. }
  686. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  687. //printf("%s:\n", (const char*)data);
  688. //idTag
  689. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  690. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  691. //parentIdTag
  692. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  693. //expir_date
  694. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  695. //status
  696. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  697. //version
  698. if(columenCount > 5)
  699. idTagQuery.listVersionInt = atoi(columnValue[5]);
  700. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  701. return 0;
  702. }
  703. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  704. {
  705. // localversion = argv[5] ? atoi(argv[5]) : 0;
  706. // printf("localversion=%d\n", localversion);
  707. return 0;
  708. }
  709. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  710. {
  711. for (int i = 0; i < n_columns; i++)
  712. {
  713. DEBUG_INFO("%s\t", col_values[i]);
  714. }
  715. DEBUG_INFO("\n");
  716. return 0;
  717. }
  718. int OCPP_cleanLocalCache()
  719. {
  720. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  721. char *errMsg = 0;
  722. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  723. if (SQLITE_OK != rc)
  724. {
  725. DEBUG_INFO("SQL error: %s\n",errMsg);
  726. return FALSE;
  727. }
  728. return TRUE;
  729. }
  730. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  731. {
  732. int isSuccess = TRUE;
  733. int ret = 0;
  734. //const char* data = "Callback function called";
  735. char sql[300];
  736. char zErrMsg[200];
  737. memset(sql, 0, 300);
  738. memset(zErrMsg, 0, 200);
  739. 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);
  740. //* Execute SQL statement */
  741. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  742. if( ret != SQLITE_OK )
  743. {
  744. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  745. isSuccess = FALSE;
  746. }
  747. return isSuccess;
  748. }
  749. void OCPP_getIdTagFromLocalCache(char idTag[])
  750. {
  751. int rc = 0;
  752. char sql[100];
  753. char zErrMsg[100];
  754. memset(sql, 0, 100);
  755. memset(zErrMsg, 0, 100);
  756. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  757. memset(&idTagQuery, 0, sizeof(idTagQuery));
  758. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  759. /* Execute SQL statement */
  760. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  761. if( rc != SQLITE_OK )
  762. {
  763. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  764. }
  765. }
  766. void OCPP_getListVerion()
  767. {
  768. int rc = 0;
  769. // const char* data = "Callback function called";
  770. char sql[100];
  771. char zErrMsg[100];
  772. memset(sql, 0, 100);
  773. memset(zErrMsg, 0, 100);
  774. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  775. /* Execute SQL statement */
  776. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  777. if( rc != SQLITE_OK )
  778. {
  779. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  780. }
  781. }
  782. void OCPP_get_TableAuthlocalAllData(void)
  783. {
  784. int rc = 0;
  785. char sql[100];
  786. char zErrMsg[100];
  787. memset(sql, 0, 100);
  788. memset(zErrMsg, 0, 100);
  789. sprintf(sql,"select * from ocpp_auth_local ");
  790. /* Execute SQL statement */
  791. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  792. if( rc != SQLITE_OK )
  793. {
  794. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  795. }
  796. //return ver;
  797. }
  798. int OCPP_cleanLocalList()
  799. {
  800. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  801. char *errMsg = 0;
  802. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  803. if (SQLITE_OK != rc)
  804. {
  805. DEBUG_INFO("%s\n",errMsg);
  806. return FALSE;
  807. }
  808. return TRUE;
  809. }
  810. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  811. {
  812. int isSuccess = FALSE;
  813. int ret = 0;
  814. //const char* data = "Callback function called";
  815. char sql[300];
  816. char zErrMsg[200];
  817. memset(sql, 0, 300);
  818. memset(zErrMsg, 0, 200);
  819. 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);
  820. //* Execute SQL statement */
  821. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  822. if( ret != SQLITE_OK )
  823. {
  824. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  825. return isSuccess;
  826. }
  827. memset(sql, 0, 300);
  828. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  829. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  830. if( ret != SQLITE_OK )
  831. {
  832. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  833. return isSuccess;
  834. }
  835. isSuccess = TRUE;
  836. return isSuccess;
  837. }
  838. void OCPP_getIdTagFromLocalList(char idTag[])
  839. {
  840. int rc = 0;
  841. // const char* data = "Callback function called";
  842. char sql[100];
  843. char zErrMsg[100];
  844. memset(sql, 0, 100);
  845. memset(zErrMsg, 0, 100);
  846. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  847. memset(&idTagQuery, 0, sizeof(idTagQuery));
  848. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  849. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  850. /* Execute SQL statement */
  851. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  852. if( rc != SQLITE_OK )
  853. {
  854. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  855. }
  856. //return ver;
  857. }
  858. void OCPP_deleteIdTagFromLocalList(char idTag[])
  859. {
  860. //int ver = 0;
  861. //int isSuccess = FALSE;
  862. int rc = 0;
  863. char sql[100];
  864. char zErrMsg[100];
  865. memset(sql, 0, 100);
  866. memset(zErrMsg, 0, 100);
  867. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  868. //* Execute SQL statement */
  869. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  870. if( rc != SQLITE_OK )
  871. {
  872. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  873. }
  874. }
  875. int getCurrentYear()
  876. {
  877. int result = 0;
  878. time_t CurrentTime;
  879. struct tm *tm;
  880. CurrentTime = time(NULL);
  881. tm=localtime(&CurrentTime);
  882. result = (tm->tm_year + 1900);
  883. return result;
  884. }
  885. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  886. {
  887. int result = PASS;
  888. char* errMsg = NULL;
  889. char sqlStr[8192];
  890. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  891. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  892. {
  893. result = FAIL;
  894. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  895. }
  896. 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));
  897. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  898. {
  899. result = FAIL;
  900. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  901. }
  902. return result;
  903. }
  904. //==========================================
  905. // Check time passed since today
  906. //==========================================
  907. long long DiffTimebWithNow(struct timeb ST)
  908. {
  909. //return milli-second
  910. struct timeb ET;
  911. long long StartTime,StopTime;
  912. ftime(&ET);
  913. StartTime=(long long)ST.time;
  914. StopTime=(long long)ET.time;
  915. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  916. }
  917. int getTimePassSinceToday(uint8_t gun_index)
  918. {
  919. int result = -1;
  920. static time_t lastTime[4];
  921. time_t t;
  922. struct tm *tmStartToday;
  923. struct timeb tbStartToday;
  924. t=time(NULL);
  925. if(difftime(t, lastTime[gun_index])>0)
  926. {
  927. tmStartToday=localtime(&t);
  928. tmStartToday->tm_hour = 0;
  929. tmStartToday->tm_min = 0;
  930. tmStartToday->tm_sec = 0;
  931. tbStartToday.time = mktime(tmStartToday);
  932. tbStartToday.millitm = 0;
  933. result = DiffTimebWithNow(tbStartToday)/1000;
  934. lastTime[gun_index] = t;
  935. }
  936. return result;
  937. }
  938. void getNowDatetime(uint8_t *data)
  939. {
  940. time_t t = time(NULL);
  941. struct tm tm = *localtime(&t);
  942. 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);
  943. }
  944. int syncDateTimeRTC(uint8_t *data)
  945. {
  946. struct ParsingResult
  947. {
  948. int result;
  949. int scanedElement;
  950. int year;
  951. int month;
  952. int mday;
  953. int hour;
  954. int min;
  955. int sec;
  956. int tz_hour;
  957. int tz_min;
  958. float minSec;
  959. }result;
  960. struct tm tmOrg;
  961. struct tm *tmTarget;
  962. struct timeb tbTarget;
  963. char buf[128];
  964. memset(&result, 0x00, sizeof(struct ParsingResult));
  965. result.result = PASS;
  966. if(strstr((char*)data, ".") != NULL)
  967. {
  968. // Original data with mini second
  969. if(strstr((char*)data, "Z") != NULL)
  970. {
  971. // Original data with Z
  972. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  973. &result.year,
  974. &result.month,
  975. &result.mday,
  976. &result.hour,
  977. &result.min,
  978. &result.sec,
  979. &result.minSec);
  980. }
  981. else
  982. {
  983. // Original data without Z
  984. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  985. &result.year,
  986. &result.month,
  987. &result.mday,
  988. &result.hour,
  989. &result.min,
  990. &result.sec,
  991. &result.minSec,
  992. &result.tz_hour,
  993. &result.tz_min);
  994. }
  995. }
  996. else
  997. {
  998. // Original data without mini second
  999. if(strstr((char*)data, "Z") != NULL)
  1000. {
  1001. // Original data with Z
  1002. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  1003. &result.year,
  1004. &result.month,
  1005. &result.mday,
  1006. &result.hour,
  1007. &result.min,
  1008. &result.sec);
  1009. }
  1010. else
  1011. {
  1012. // Original data without Z
  1013. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  1014. &result.year,
  1015. &result.month,
  1016. &result.mday,
  1017. &result.hour,
  1018. &result.min,
  1019. &result.sec,
  1020. &result.tz_hour,
  1021. &result.tz_min);
  1022. }
  1023. }
  1024. tmOrg.tm_year = result.year - 1900;
  1025. tmOrg.tm_mon = result.month - 1;
  1026. tmOrg.tm_mday = result.mday;
  1027. tmOrg.tm_hour = result.hour;
  1028. tmOrg.tm_min = result.min;
  1029. tmOrg.tm_sec = result.sec;
  1030. tmOrg.tm_gmtoff = 0;
  1031. tbTarget.time = mktime(&tmOrg);
  1032. tbTarget.timezone = 0;
  1033. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  1034. tmTarget = gmtime(&tbTarget.time);
  1035. 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);
  1036. //DEBUG_INFO(" org date time: %s\n", data);
  1037. //DEBUG_INFO("parse date time: %s\n", buf);
  1038. system(buf);
  1039. system("/sbin/hwclock -w --systohc");
  1040. if(result.scanedElement < 6)
  1041. result.result = FAIL;
  1042. return result.result;
  1043. }
  1044. //==========================================
  1045. // GetCompositeSchedule logic related function
  1046. //==========================================
  1047. int DiffTimebSec(struct timeb ST, struct timeb ET)
  1048. {
  1049. //return milli-second
  1050. unsigned int StartTime,StopTime;
  1051. StartTime=(unsigned int)ST.time;
  1052. StopTime=(unsigned int)ET.time;
  1053. return (StopTime-StartTime);
  1054. }
  1055. int DiffTimebWithNowSec(struct timeb ST)
  1056. {
  1057. //return milli-second
  1058. struct timeb ET;
  1059. unsigned int StartTime,StopTime;
  1060. ftime(&ET);
  1061. StartTime=(unsigned int)ST.time;
  1062. StopTime=(unsigned int)ET.time;
  1063. return (StopTime-StartTime);
  1064. }
  1065. int getStartStop(uint8_t *start, uint8_t *stop)
  1066. {
  1067. int result = -1;
  1068. struct tm tmStart;
  1069. struct timeb tbStart;
  1070. struct tm tmStop;
  1071. struct timeb tbStop;
  1072. 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) &&
  1073. (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))
  1074. {
  1075. //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);
  1076. //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);
  1077. tmStart.tm_year -= 1900;
  1078. tmStart.tm_mon -= 1;
  1079. tbStart.time = mktime(&tmStart);
  1080. tbStart.millitm = 0;
  1081. tmStop.tm_year -= 1900;
  1082. tmStop.tm_mon -= 1;
  1083. tbStop.time = mktime(&tmStop);
  1084. tbStop.millitm = 0;
  1085. result = DiffTimebSec(tbStart, tbStop);
  1086. //DEBUG_INFO("getStartStop(): %d\n", result);
  1087. }
  1088. else
  1089. {
  1090. DEBUG_WARN("Start or stop date parsing error.\r\n");
  1091. }
  1092. return result;
  1093. }
  1094. int isOvertNow(uint8_t *start)
  1095. {
  1096. int result = NO;
  1097. struct ParsingResult
  1098. {
  1099. int result;
  1100. int scanedElement;
  1101. int year;
  1102. int month;
  1103. int mday;
  1104. int hour;
  1105. int min;
  1106. int sec;
  1107. int tz_hour;
  1108. int tz_min;
  1109. float minSec;
  1110. }parsingResult;
  1111. struct tm tmStart;
  1112. struct timeb tbStart;
  1113. if(strstr((char*)start, ".") != NULL)
  1114. {
  1115. // Original data with mini second
  1116. if(strstr((char*)start, "Z") != NULL)
  1117. {
  1118. // Original data with Z
  1119. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  1120. &parsingResult.year,
  1121. &parsingResult.month,
  1122. &parsingResult.mday,
  1123. &parsingResult.hour,
  1124. &parsingResult.min,
  1125. &parsingResult.sec,
  1126. &parsingResult.minSec);
  1127. }
  1128. else
  1129. {
  1130. // Original data without Z
  1131. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  1132. &parsingResult.year,
  1133. &parsingResult.month,
  1134. &parsingResult.mday,
  1135. &parsingResult.hour,
  1136. &parsingResult.min,
  1137. &parsingResult.sec,
  1138. &parsingResult.minSec,
  1139. &parsingResult.tz_hour,
  1140. &parsingResult.tz_min);
  1141. }
  1142. }
  1143. else
  1144. {
  1145. // Original data without mini second
  1146. if(strstr((char*)start, "Z") != NULL)
  1147. {
  1148. // Original data with Z
  1149. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  1150. &parsingResult.year,
  1151. &parsingResult.month,
  1152. &parsingResult.mday,
  1153. &parsingResult.hour,
  1154. &parsingResult.min,
  1155. &parsingResult.sec);
  1156. }
  1157. else
  1158. {
  1159. // Original data without Z
  1160. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  1161. &parsingResult.year,
  1162. &parsingResult.month,
  1163. &parsingResult.mday,
  1164. &parsingResult.hour,
  1165. &parsingResult.min,
  1166. &parsingResult.sec,
  1167. &parsingResult.tz_hour,
  1168. &parsingResult.tz_min);
  1169. }
  1170. }
  1171. if(parsingResult.scanedElement >= 6)
  1172. {
  1173. tmStart.tm_year = parsingResult.year - 1900;
  1174. tmStart.tm_mon = parsingResult.month - 1;
  1175. tmStart.tm_mday = parsingResult.mday;
  1176. tmStart.tm_hour = parsingResult.hour;
  1177. tmStart.tm_min = parsingResult.min;
  1178. tmStart.tm_sec = parsingResult.sec;
  1179. tmStart.tm_gmtoff = 0;
  1180. tbStart.time = mktime(&tmStart);
  1181. tbStart.timezone = 0;
  1182. tbStart.millitm = 0;
  1183. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  1184. if(DiffTimebWithNowSec(tbStart) <= 0)
  1185. result = NO;
  1186. else
  1187. result = YES;
  1188. }
  1189. else
  1190. {
  1191. DEBUG_WARN("Start date parsing error.\n");
  1192. }
  1193. return result;
  1194. }
  1195. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  1196. {
  1197. int result = -1;
  1198. struct tm tmStart;
  1199. struct timeb tbStart;
  1200. struct tm tmStop;
  1201. struct timeb tbStop;
  1202. 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) &&
  1203. (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))
  1204. {
  1205. tmStart.tm_year -= 1900;
  1206. tmStart.tm_mon -= 1;
  1207. tbStart.time = mktime(&tmStart);
  1208. tbStart.millitm = 0;
  1209. tmStop.tm_year -= 1900;
  1210. tmStop.tm_mon -= 1;
  1211. tbStop.time = mktime(&tmStop);
  1212. tbStop.millitm = 0;
  1213. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  1214. }
  1215. return result;
  1216. }
  1217. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1218. {
  1219. FILE *fp;
  1220. char profileFileName[128];
  1221. char *line = NULL;
  1222. size_t len = 0;
  1223. time_t CurrentTime;
  1224. struct tm *tmComposite;
  1225. struct StructChargingProfile maxProfile;
  1226. uint8_t limitMax=0;
  1227. int compositePeriodIdx = 0;
  1228. CurrentTime = time(NULL);
  1229. tmComposite=localtime(&CurrentTime);
  1230. 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);
  1231. if(isUnitA)
  1232. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1233. else
  1234. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1235. compositeProfile->ChargingSchedule.Duration = durationReq;
  1236. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1237. {
  1238. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1239. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1240. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1241. }
  1242. compositeProfile->ChargingProfileId = 0;
  1243. compositeProfile->StackLevel = 99 ;
  1244. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1245. maxProfile.ChargingProfileId = -1;
  1246. maxProfile.ChargingSchedule.Duration = -1;
  1247. system("rm -f /tmp/*.json");
  1248. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1249. // Search max profile
  1250. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1251. if((access(profileFileName, F_OK))!=-1)
  1252. {
  1253. fp = fopen(profileFileName, "r");
  1254. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1255. {
  1256. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1257. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1258. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1259. }
  1260. maxProfile.ChargingProfileId = -1;
  1261. maxProfile.StackLevel = -1;
  1262. while(getline(&line, &len, fp) != -1)
  1263. {
  1264. json_object *obj = NULL;
  1265. obj = json_tokener_parse(line);
  1266. if(is_error(obj))
  1267. {
  1268. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1269. }
  1270. else
  1271. {
  1272. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1273. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1274. )
  1275. {
  1276. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1277. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1278. )
  1279. {
  1280. struct tm tmFrom, tmTo;
  1281. struct timeb tbFrom, tbTo;
  1282. 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) &&
  1283. (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))
  1284. {
  1285. tmFrom.tm_year -= 1900;
  1286. tmFrom.tm_mon -= 1;
  1287. tbFrom.time = mktime(&tmFrom);
  1288. tmTo.tm_year -= 1900;
  1289. tmTo.tm_mon -= 1;
  1290. tbTo.time = mktime(&tmTo);
  1291. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1292. {
  1293. if(maxProfile.ChargingProfileId == -1)
  1294. DEBUG_INFO("MaxProfile found.\n");
  1295. else
  1296. DEBUG_INFO("MaxProfile updated.\n");
  1297. // Required item
  1298. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1299. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1300. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1301. if(isUnitA)
  1302. {
  1303. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1304. 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++)
  1305. {
  1306. 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"));
  1307. 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?
  1308. 3:
  1309. 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")));
  1310. 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")));
  1311. }
  1312. }
  1313. else
  1314. {
  1315. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1316. 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++)
  1317. {
  1318. 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"));
  1319. 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?
  1320. 3:
  1321. 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")));
  1322. 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));
  1323. }
  1324. }
  1325. // Optional item
  1326. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1327. {
  1328. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1329. }
  1330. else
  1331. {
  1332. sprintf((char*)maxProfile.ValidFrom, " ");
  1333. }
  1334. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1335. {
  1336. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1337. }
  1338. else
  1339. {
  1340. sprintf((char*)maxProfile.ValidTo, " ");
  1341. }
  1342. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1343. {
  1344. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1345. }
  1346. else
  1347. {
  1348. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1349. }
  1350. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1351. {
  1352. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1353. }
  1354. else
  1355. {
  1356. maxProfile.TransactionId = -1;
  1357. }
  1358. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1359. {
  1360. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1361. }
  1362. else
  1363. {
  1364. maxProfile.ChargingSchedule.Duration = 86400;
  1365. }
  1366. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1367. {
  1368. 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")));
  1369. }
  1370. else
  1371. {
  1372. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1373. }
  1374. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1375. {
  1376. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1377. }
  1378. else
  1379. {
  1380. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1381. }
  1382. }
  1383. }
  1384. }
  1385. else
  1386. {
  1387. if(maxProfile.ChargingProfileId == -1)
  1388. DEBUG_INFO("MaxProfile found.\n");
  1389. else
  1390. DEBUG_INFO("MaxProfile updated.\n");
  1391. // Required item
  1392. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1393. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1394. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1395. if(isUnitA)
  1396. {
  1397. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1398. 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++)
  1399. {
  1400. 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"));
  1401. 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?
  1402. 3:
  1403. 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")));
  1404. 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")));
  1405. }
  1406. }
  1407. else
  1408. {
  1409. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1410. 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++)
  1411. {
  1412. 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"));
  1413. 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?
  1414. 3:
  1415. 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")));
  1416. 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));
  1417. }
  1418. }
  1419. // Optional item
  1420. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1421. {
  1422. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1423. }
  1424. else
  1425. {
  1426. sprintf((char*)maxProfile.ValidFrom, " ");
  1427. }
  1428. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1429. {
  1430. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1431. }
  1432. else
  1433. {
  1434. sprintf((char*)maxProfile.ValidTo, " ");
  1435. }
  1436. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1437. {
  1438. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1439. }
  1440. else
  1441. {
  1442. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1443. }
  1444. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1445. {
  1446. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1447. }
  1448. else
  1449. {
  1450. maxProfile.TransactionId = -1;
  1451. }
  1452. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1453. {
  1454. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1455. }
  1456. else
  1457. {
  1458. maxProfile.ChargingSchedule.Duration = 86400;
  1459. }
  1460. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1461. {
  1462. 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")));
  1463. }
  1464. else
  1465. {
  1466. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1467. }
  1468. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1469. {
  1470. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1471. }
  1472. else
  1473. {
  1474. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. json_object_put(obj);
  1480. }
  1481. fclose(fp);
  1482. /*
  1483. if(maxProfile.ChargingProfileId !=-1)
  1484. {
  1485. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1486. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1487. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1488. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1489. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1490. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1491. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1492. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1493. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1494. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1495. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1497. {
  1498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1499. {
  1500. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1501. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1502. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1503. }
  1504. }
  1505. }
  1506. else
  1507. DEBUG_INFO("MaxProfile not found.\n");
  1508. DEBUG_INFO("------------------------------------\n");*/
  1509. }
  1510. if(maxProfile.ChargingProfileId != -1)
  1511. {
  1512. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1513. {
  1514. if(maxProfile.ChargingSchedule.Duration != -1)
  1515. {
  1516. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1517. 0:
  1518. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1519. }
  1520. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1521. {
  1522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1523. {
  1524. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1525. 0:
  1526. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1527. if(idxPeriod > 0)
  1528. {
  1529. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1530. {
  1531. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1532. }
  1533. }
  1534. }
  1535. }
  1536. }
  1537. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1538. {
  1539. if(maxProfile.ChargingSchedule.Duration != -1)
  1540. {
  1541. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1542. }
  1543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1544. {
  1545. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1546. {
  1547. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1548. if(idxPeriod > 0)
  1549. {
  1550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1551. {
  1552. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1553. }
  1554. }
  1555. }
  1556. }
  1557. }
  1558. else
  1559. {
  1560. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1561. {
  1562. if(maxProfile.ChargingSchedule.Duration != -1)
  1563. {
  1564. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1565. 0:
  1566. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1567. }
  1568. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1569. {
  1570. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1571. {
  1572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1573. 0:
  1574. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1575. if(idxPeriod > 0)
  1576. {
  1577. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1578. {
  1579. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. else
  1586. {
  1587. if(maxProfile.ChargingSchedule.Duration != -1)
  1588. {
  1589. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1590. 0:
  1591. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1592. }
  1593. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1594. {
  1595. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1596. {
  1597. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1598. 0:
  1599. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1600. if(idxPeriod > 0)
  1601. {
  1602. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1603. {
  1604. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. }
  1611. /*
  1612. DEBUG_INFO("MaxProfile after align.\n");
  1613. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1614. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1615. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1616. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1617. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1618. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1619. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1620. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1621. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1622. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1623. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1625. {
  1626. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1627. {
  1628. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1629. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1630. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1631. }
  1632. }
  1633. DEBUG_INFO("------------------------------------\n");*/
  1634. }
  1635. // Find each profile period quantity
  1636. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1637. {
  1638. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1639. limitMax = idx+1;
  1640. }
  1641. if(maxProfile.ChargingProfileId != -1)
  1642. {
  1643. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1644. {
  1645. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1646. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1647. (maxProfile.ChargingSchedule.Duration > 0))
  1648. {
  1649. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1650. {
  1651. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1652. compositePeriodIdx++;
  1653. }
  1654. else
  1655. {
  1656. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1657. }
  1658. }
  1659. }
  1660. }
  1661. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1662. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1663. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1664. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1665. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1666. {
  1667. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1668. {
  1669. compositeProfile->ChargingProfileId = 1;
  1670. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1671. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1672. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1673. }
  1674. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1675. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1676. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1677. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1678. }
  1679. if(line)
  1680. free(line);
  1681. }
  1682. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1683. {
  1684. FILE *fp;
  1685. char profileFileName[128];
  1686. char *line = NULL;
  1687. size_t len = 0;
  1688. time_t CurrentTime;
  1689. struct tm *tmComposite;
  1690. struct StructChargingProfile maxProfile;
  1691. struct StructChargingProfile defaultTxProfile;
  1692. struct StructChargingProfile txProfile;
  1693. struct StructChargingSchedulePeriod tmpPeriod;
  1694. uint8_t limitMax=0;
  1695. uint8_t limitDef=0;
  1696. uint8_t limitTx=0;
  1697. int compositePeriodIdx = 0;
  1698. CurrentTime = time(NULL);
  1699. tmComposite=localtime(&CurrentTime);
  1700. 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);
  1701. if(isUnitA)
  1702. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1703. else
  1704. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1705. compositeProfile->ChargingSchedule.Duration = durationReq;
  1706. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1707. {
  1708. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1709. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1710. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1711. }
  1712. compositeProfile->ChargingProfileId = 0;
  1713. compositeProfile->StackLevel = 99 ;
  1714. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1715. maxProfile.ChargingProfileId = -1;
  1716. defaultTxProfile.ChargingProfileId = -1;
  1717. txProfile.ChargingProfileId = -1;
  1718. maxProfile.ChargingSchedule.Duration = -1;
  1719. defaultTxProfile.ChargingSchedule.Duration = -1;
  1720. txProfile.ChargingSchedule.Duration = -1;
  1721. system("rm -f /tmp/*.json");
  1722. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1723. /*
  1724. * Search valid charging profile
  1725. */
  1726. //DEBUG_INFO("====================================\n");
  1727. // Search tx profile
  1728. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1729. if((access(profileFileName, F_OK))!=-1)
  1730. {
  1731. fp = fopen(profileFileName, "r");
  1732. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1733. {
  1734. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1735. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1736. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1737. }
  1738. txProfile.ChargingProfileId = -1;
  1739. txProfile.StackLevel = -1;
  1740. while(getline(&line, &len, fp) != -1)
  1741. {
  1742. json_object *obj = NULL;
  1743. obj = json_tokener_parse(line);
  1744. if(is_error(obj))
  1745. {
  1746. DEBUG_ERROR("Parse txProfile from file error.\n");
  1747. }
  1748. else
  1749. {
  1750. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1751. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1752. )
  1753. {
  1754. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1755. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1756. )
  1757. {
  1758. struct tm tmFrom, tmTo;
  1759. struct timeb tbFrom, tbTo;
  1760. 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) &&
  1761. (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))
  1762. {
  1763. tmFrom.tm_year -= 1900;
  1764. tmFrom.tm_mon -= 1;
  1765. tbFrom.time = mktime(&tmFrom);
  1766. tmTo.tm_year -= 1900;
  1767. tmTo.tm_mon -= 1;
  1768. tbTo.time = mktime(&tmTo);
  1769. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1770. {
  1771. if(txProfile.ChargingProfileId == -1)
  1772. DEBUG_INFO("TxProfile found.\n");
  1773. else
  1774. DEBUG_INFO("TxProfile updated.\n");
  1775. // Required item
  1776. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1777. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1778. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1779. if(isUnitA)
  1780. {
  1781. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1782. 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++)
  1783. {
  1784. 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"));
  1785. 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?
  1786. 3:
  1787. 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")));
  1788. 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")));
  1789. }
  1790. }
  1791. else
  1792. {
  1793. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1794. 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++)
  1795. {
  1796. 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"));
  1797. 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?
  1798. 3:
  1799. 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")));
  1800. 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));
  1801. }
  1802. }
  1803. // Optional item
  1804. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1805. {
  1806. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1807. }
  1808. else
  1809. {
  1810. sprintf((char*)txProfile.ValidFrom, " ");
  1811. }
  1812. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1813. {
  1814. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1815. }
  1816. else
  1817. {
  1818. sprintf((char*)txProfile.ValidTo, " ");
  1819. }
  1820. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1821. {
  1822. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1823. }
  1824. else
  1825. {
  1826. sprintf((char*)txProfile.RecurrencyKind, " ");
  1827. }
  1828. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1829. {
  1830. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1831. }
  1832. else
  1833. {
  1834. txProfile.TransactionId = -1;
  1835. }
  1836. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1837. {
  1838. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1839. }
  1840. else
  1841. {
  1842. txProfile.ChargingSchedule.Duration = 86400;
  1843. }
  1844. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1845. {
  1846. 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")));
  1847. }
  1848. else
  1849. {
  1850. 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));
  1851. }
  1852. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1853. {
  1854. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1855. }
  1856. else
  1857. {
  1858. txProfile.ChargingSchedule.MinChargingRate = -1;
  1859. }
  1860. }
  1861. }
  1862. }
  1863. else
  1864. {
  1865. if(txProfile.ChargingProfileId == -1)
  1866. DEBUG_INFO("TxProfile found.\n");
  1867. else
  1868. DEBUG_INFO("TxProfile updated.\n");
  1869. // Required item
  1870. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1871. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1872. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1873. if(isUnitA)
  1874. {
  1875. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1876. 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++)
  1877. {
  1878. 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"));
  1879. 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?
  1880. 3:
  1881. 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")));
  1882. 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")));
  1883. }
  1884. }
  1885. else
  1886. {
  1887. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1888. 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++)
  1889. {
  1890. 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"));
  1891. 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?
  1892. 3:
  1893. 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")));
  1894. 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));
  1895. }
  1896. }
  1897. // Optional item
  1898. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1899. {
  1900. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1901. }
  1902. else
  1903. {
  1904. sprintf((char*)txProfile.ValidFrom, " ");
  1905. }
  1906. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1907. {
  1908. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1909. }
  1910. else
  1911. {
  1912. sprintf((char*)txProfile.ValidTo, " ");
  1913. }
  1914. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1915. {
  1916. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1917. }
  1918. else
  1919. {
  1920. sprintf((char*)txProfile.RecurrencyKind, " ");
  1921. }
  1922. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1923. {
  1924. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1925. }
  1926. else
  1927. {
  1928. txProfile.TransactionId = -1;
  1929. }
  1930. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1931. {
  1932. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1933. }
  1934. else
  1935. {
  1936. txProfile.ChargingSchedule.Duration = 86400;
  1937. }
  1938. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1939. {
  1940. 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")));
  1941. }
  1942. else
  1943. {
  1944. 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));
  1945. }
  1946. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1947. {
  1948. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1949. }
  1950. else
  1951. {
  1952. txProfile.ChargingSchedule.MinChargingRate = -1;
  1953. }
  1954. }
  1955. }
  1956. }
  1957. json_object_put(obj);
  1958. }
  1959. fclose(fp);
  1960. /*
  1961. if(txProfile.ChargingProfileId != -1)
  1962. {
  1963. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1964. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1965. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1966. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1967. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1968. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1969. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1970. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1971. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1972. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1973. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1974. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1975. {
  1976. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1977. {
  1978. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1979. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1980. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1981. }
  1982. }
  1983. }
  1984. else
  1985. DEBUG_INFO("TxProfile not found.\n");*/
  1986. }
  1987. // Search default tx profile
  1988. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1989. if((access(profileFileName, F_OK))==-1)
  1990. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1991. if((access(profileFileName, F_OK))!=-1)
  1992. {
  1993. fp = fopen(profileFileName, "r");
  1994. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1995. {
  1996. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1997. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1998. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1999. }
  2000. defaultTxProfile.ChargingProfileId = -1;
  2001. defaultTxProfile.StackLevel = -1;
  2002. while(getline(&line, &len, fp) != -1)
  2003. {
  2004. json_object *obj = NULL;
  2005. obj = json_tokener_parse(line);
  2006. if(is_error(obj))
  2007. {
  2008. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  2009. }
  2010. else
  2011. {
  2012. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  2013. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  2014. )
  2015. {
  2016. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2017. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2018. )
  2019. {
  2020. struct tm tmFrom, tmTo;
  2021. struct timeb tbFrom, tbTo;
  2022. 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) &&
  2023. (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))
  2024. {
  2025. tmFrom.tm_year -= 1900;
  2026. tmFrom.tm_mon -= 1;
  2027. tbFrom.time = mktime(&tmFrom);
  2028. tmTo.tm_year -= 1900;
  2029. tmTo.tm_mon -= 1;
  2030. tbTo.time = mktime(&tmTo);
  2031. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2032. {
  2033. if(defaultTxProfile.ChargingProfileId == -1)
  2034. DEBUG_INFO("TxDefaultProfile found.\n");
  2035. else
  2036. DEBUG_INFO("TxDefaultProfile updated.\n");
  2037. // Required item
  2038. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2039. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2040. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2041. if(isUnitA)
  2042. {
  2043. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2044. 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++)
  2045. {
  2046. 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"));
  2047. 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?
  2048. 3:
  2049. 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")));
  2050. 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")));
  2051. }
  2052. }
  2053. else
  2054. {
  2055. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2056. 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++)
  2057. {
  2058. 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"));
  2059. 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?
  2060. 3:
  2061. 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")));
  2062. 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));
  2063. }
  2064. }
  2065. // Optional item
  2066. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2067. {
  2068. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2069. }
  2070. else
  2071. {
  2072. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2073. }
  2074. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2075. {
  2076. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2077. }
  2078. else
  2079. {
  2080. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2081. }
  2082. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2083. {
  2084. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2085. }
  2086. else
  2087. {
  2088. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2089. }
  2090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2091. {
  2092. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2093. }
  2094. else
  2095. {
  2096. defaultTxProfile.TransactionId = -1;
  2097. }
  2098. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2099. {
  2100. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2101. }
  2102. else
  2103. {
  2104. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2105. }
  2106. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2107. {
  2108. 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")));
  2109. }
  2110. else
  2111. {
  2112. 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));
  2113. }
  2114. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2115. {
  2116. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2117. }
  2118. else
  2119. {
  2120. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2121. }
  2122. }
  2123. }
  2124. }
  2125. else
  2126. {
  2127. if(defaultTxProfile.ChargingProfileId == -1)
  2128. DEBUG_INFO("TxDefaultProfile found.\n");
  2129. else
  2130. DEBUG_INFO("TxDefaultProfile updated.\n");
  2131. // Required item
  2132. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2133. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2134. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2135. if(isUnitA)
  2136. {
  2137. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2138. 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++)
  2139. {
  2140. 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"));
  2141. 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?
  2142. 3:
  2143. 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")));
  2144. 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")));
  2145. }
  2146. }
  2147. else
  2148. {
  2149. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2150. 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++)
  2151. {
  2152. 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"));
  2153. 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?
  2154. 3:
  2155. 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")));
  2156. 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));
  2157. }
  2158. }
  2159. // Optional item
  2160. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2161. {
  2162. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2163. }
  2164. else
  2165. {
  2166. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  2167. }
  2168. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2169. {
  2170. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2171. }
  2172. else
  2173. {
  2174. sprintf((char*)defaultTxProfile.ValidTo, " ");
  2175. }
  2176. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2177. {
  2178. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2179. }
  2180. else
  2181. {
  2182. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  2183. }
  2184. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2185. {
  2186. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2187. }
  2188. else
  2189. {
  2190. defaultTxProfile.TransactionId = -1;
  2191. }
  2192. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2193. {
  2194. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2195. }
  2196. else
  2197. {
  2198. defaultTxProfile.ChargingSchedule.Duration = 86400;
  2199. }
  2200. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2201. {
  2202. 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")));
  2203. }
  2204. else
  2205. {
  2206. 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));
  2207. }
  2208. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2209. {
  2210. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2211. }
  2212. else
  2213. {
  2214. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2215. }
  2216. }
  2217. }
  2218. }
  2219. json_object_put(obj);
  2220. }
  2221. fclose(fp);
  2222. /*
  2223. if(defaultTxProfile.ChargingProfileId != -1)
  2224. {
  2225. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2226. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2227. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2228. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2229. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2230. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2231. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2232. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2233. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2234. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2235. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2236. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2237. {
  2238. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2239. {
  2240. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2241. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2242. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2243. }
  2244. }
  2245. }
  2246. else
  2247. DEBUG_INFO("TxDefaultProfile not found.\n");
  2248. DEBUG_INFO("------------------------------------\n");*/
  2249. }
  2250. // Search max profile
  2251. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2252. if((access(profileFileName, F_OK))!=-1)
  2253. {
  2254. fp = fopen(profileFileName, "r");
  2255. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2256. {
  2257. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2258. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2259. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2260. }
  2261. maxProfile.ChargingProfileId = -1;
  2262. maxProfile.StackLevel = -1;
  2263. while(getline(&line, &len, fp) != -1)
  2264. {
  2265. json_object *obj = NULL;
  2266. obj = json_tokener_parse(line);
  2267. if(is_error(obj))
  2268. {
  2269. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2270. }
  2271. else
  2272. {
  2273. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2274. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2275. )
  2276. {
  2277. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2278. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2279. )
  2280. {
  2281. struct tm tmFrom, tmTo;
  2282. struct timeb tbFrom, tbTo;
  2283. 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) &&
  2284. (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))
  2285. {
  2286. tmFrom.tm_year -= 1900;
  2287. tmFrom.tm_mon -= 1;
  2288. tbFrom.time = mktime(&tmFrom);
  2289. tmTo.tm_year -= 1900;
  2290. tmTo.tm_mon -= 1;
  2291. tbTo.time = mktime(&tmTo);
  2292. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2293. {
  2294. if(maxProfile.ChargingProfileId == -1)
  2295. DEBUG_INFO("MaxProfile found.\n");
  2296. else
  2297. DEBUG_INFO("MaxProfile updated.\n");
  2298. // Required item
  2299. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2300. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2301. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2302. if(isUnitA)
  2303. {
  2304. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2305. 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++)
  2306. {
  2307. 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"));
  2308. 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?
  2309. 3:
  2310. 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")));
  2311. 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")));
  2312. }
  2313. }
  2314. else
  2315. {
  2316. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2317. 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++)
  2318. {
  2319. 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"));
  2320. 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?
  2321. 3:
  2322. 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")));
  2323. 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));
  2324. }
  2325. }
  2326. // Optional item
  2327. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2328. {
  2329. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2330. }
  2331. else
  2332. {
  2333. sprintf((char*)maxProfile.ValidFrom, " ");
  2334. }
  2335. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2336. {
  2337. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2338. }
  2339. else
  2340. {
  2341. sprintf((char*)maxProfile.ValidTo, " ");
  2342. }
  2343. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2344. {
  2345. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2346. }
  2347. else
  2348. {
  2349. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2350. }
  2351. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2352. {
  2353. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2354. }
  2355. else
  2356. {
  2357. maxProfile.TransactionId = -1;
  2358. }
  2359. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2360. {
  2361. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2362. }
  2363. else
  2364. {
  2365. maxProfile.ChargingSchedule.Duration = 86400;
  2366. }
  2367. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2368. {
  2369. 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")));
  2370. }
  2371. else
  2372. {
  2373. 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));
  2374. }
  2375. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2376. {
  2377. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2378. }
  2379. else
  2380. {
  2381. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2382. }
  2383. }
  2384. }
  2385. }
  2386. else
  2387. {
  2388. if(maxProfile.ChargingProfileId == -1)
  2389. DEBUG_INFO("MaxProfile found.\n");
  2390. else
  2391. DEBUG_INFO("MaxProfile updated.\n");
  2392. // Required item
  2393. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2394. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2395. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2396. if(isUnitA)
  2397. {
  2398. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2399. 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++)
  2400. {
  2401. 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"));
  2402. 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?
  2403. 3:
  2404. 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")));
  2405. 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")));
  2406. }
  2407. }
  2408. else
  2409. {
  2410. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2411. 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++)
  2412. {
  2413. 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"));
  2414. 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?
  2415. 3:
  2416. 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")));
  2417. 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));
  2418. }
  2419. }
  2420. // Optional item
  2421. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2422. {
  2423. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2424. }
  2425. else
  2426. {
  2427. sprintf((char*)maxProfile.ValidFrom, " ");
  2428. }
  2429. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2430. {
  2431. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2432. }
  2433. else
  2434. {
  2435. sprintf((char*)maxProfile.ValidTo, " ");
  2436. }
  2437. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2438. {
  2439. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2440. }
  2441. else
  2442. {
  2443. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2444. }
  2445. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2446. {
  2447. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2448. }
  2449. else
  2450. {
  2451. maxProfile.TransactionId = -1;
  2452. }
  2453. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2454. {
  2455. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2456. }
  2457. else
  2458. {
  2459. maxProfile.ChargingSchedule.Duration = 86400;
  2460. }
  2461. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2462. {
  2463. 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")));
  2464. }
  2465. else
  2466. {
  2467. 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));
  2468. }
  2469. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2470. {
  2471. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2472. }
  2473. else
  2474. {
  2475. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2476. }
  2477. }
  2478. }
  2479. }
  2480. json_object_put(obj);
  2481. }
  2482. fclose(fp);
  2483. /*
  2484. if(maxProfile.ChargingProfileId !=-1)
  2485. {
  2486. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2487. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2488. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2489. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2490. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2491. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2492. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2493. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2494. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2495. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2496. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2497. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2498. {
  2499. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2500. {
  2501. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2502. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2503. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2504. }
  2505. }
  2506. }
  2507. else
  2508. DEBUG_INFO("MaxProfile not found.\n");
  2509. DEBUG_INFO("------------------------------------\n");*/
  2510. }
  2511. /*
  2512. * Align found profile start schedule & periods
  2513. */
  2514. //DEBUG_INFO("====================================\n");
  2515. /*
  2516. // For local test usage, force modify found profile start schedule info
  2517. 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);
  2518. 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);
  2519. 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);
  2520. */
  2521. if(txProfile.ChargingProfileId != -1)
  2522. {
  2523. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2524. {
  2525. if(txProfile.ChargingSchedule.Duration != -1)
  2526. {
  2527. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2528. 0:
  2529. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2530. }
  2531. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2532. {
  2533. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2534. {
  2535. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2536. 0:
  2537. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2538. if(idxPeriod > 0)
  2539. {
  2540. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2541. {
  2542. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2543. }
  2544. }
  2545. }
  2546. }
  2547. }
  2548. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2549. {
  2550. if(txProfile.ChargingSchedule.Duration != -1)
  2551. {
  2552. 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?
  2553. 0:
  2554. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2555. }
  2556. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2557. {
  2558. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2559. {
  2560. 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?
  2561. 0:
  2562. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2563. if(idxPeriod > 0)
  2564. {
  2565. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2566. {
  2567. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2568. }
  2569. }
  2570. }
  2571. }
  2572. }
  2573. else
  2574. {
  2575. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2576. {
  2577. if(txProfile.ChargingSchedule.Duration != -1)
  2578. {
  2579. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2580. 0:
  2581. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2582. }
  2583. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2584. {
  2585. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2586. {
  2587. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2588. 0:
  2589. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2590. if(idxPeriod > 0)
  2591. {
  2592. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2593. {
  2594. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2595. }
  2596. }
  2597. }
  2598. }
  2599. }
  2600. else
  2601. {
  2602. if(txProfile.ChargingSchedule.Duration != -1)
  2603. {
  2604. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2605. 0:
  2606. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2607. }
  2608. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2609. {
  2610. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2611. {
  2612. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2613. 0:
  2614. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2615. if(idxPeriod > 0)
  2616. {
  2617. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2618. {
  2619. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2620. }
  2621. }
  2622. }
  2623. }
  2624. }
  2625. }
  2626. /*
  2627. DEBUG_INFO("txProfile after align.\n");
  2628. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2629. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2630. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2631. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2632. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2633. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2634. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2635. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2636. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2637. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2638. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2639. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2640. {
  2641. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2642. {
  2643. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2644. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2645. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2646. }
  2647. }*/
  2648. }
  2649. if(defaultTxProfile.ChargingProfileId != -1)
  2650. {
  2651. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2652. {
  2653. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2654. {
  2655. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2656. 0:
  2657. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2658. }
  2659. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2660. {
  2661. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2662. {
  2663. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2664. 0:
  2665. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2666. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2667. {
  2668. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2669. }
  2670. if(idxPeriod > 0)
  2671. {
  2672. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2673. {
  2674. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2681. {
  2682. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2683. {
  2684. 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?
  2685. 0:
  2686. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2687. }
  2688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2689. {
  2690. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2691. {
  2692. 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?
  2693. 0:
  2694. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2695. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2696. {
  2697. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2698. }
  2699. if(idxPeriod > 0)
  2700. {
  2701. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2702. {
  2703. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2704. }
  2705. }
  2706. }
  2707. }
  2708. }
  2709. else
  2710. {
  2711. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2712. {
  2713. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2714. {
  2715. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2716. 0:
  2717. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2718. }
  2719. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2720. {
  2721. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2722. {
  2723. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2724. 0:
  2725. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2726. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2727. {
  2728. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2729. }
  2730. if(idxPeriod > 0)
  2731. {
  2732. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2733. {
  2734. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2735. }
  2736. }
  2737. }
  2738. }
  2739. }
  2740. else
  2741. {
  2742. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2743. {
  2744. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2745. 0:
  2746. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2747. }
  2748. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2749. {
  2750. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2751. {
  2752. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2753. 0:
  2754. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2755. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2756. {
  2757. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2758. }
  2759. if(idxPeriod > 0)
  2760. {
  2761. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2762. {
  2763. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2764. }
  2765. }
  2766. }
  2767. }
  2768. }
  2769. }
  2770. /*
  2771. DEBUG_INFO("defaultTxProfile after align.\n");
  2772. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2773. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2774. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2775. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2776. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2777. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2778. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2779. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2780. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2781. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2782. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2783. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2784. {
  2785. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2786. {
  2787. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2788. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2789. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2790. }
  2791. }
  2792. DEBUG_INFO("------------------------------------\n");*/
  2793. }
  2794. if(maxProfile.ChargingProfileId != -1)
  2795. {
  2796. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2797. {
  2798. if(maxProfile.ChargingSchedule.Duration != -1)
  2799. {
  2800. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2801. 0:
  2802. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2803. }
  2804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2805. {
  2806. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2807. {
  2808. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2809. 0:
  2810. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2811. if(idxPeriod > 0)
  2812. {
  2813. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2814. {
  2815. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2816. }
  2817. }
  2818. }
  2819. }
  2820. }
  2821. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2822. {
  2823. if(maxProfile.ChargingSchedule.Duration != -1)
  2824. {
  2825. 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?
  2826. 0:
  2827. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2828. }
  2829. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2830. {
  2831. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2832. {
  2833. 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?
  2834. 0:
  2835. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2836. if(idxPeriod > 0)
  2837. {
  2838. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2839. {
  2840. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2841. }
  2842. }
  2843. }
  2844. }
  2845. }
  2846. else
  2847. {
  2848. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2849. {
  2850. if(maxProfile.ChargingSchedule.Duration != -1)
  2851. {
  2852. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2853. 0:
  2854. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2855. }
  2856. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2857. {
  2858. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2859. {
  2860. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2861. 0:
  2862. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2863. if(idxPeriod > 0)
  2864. {
  2865. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2866. {
  2867. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2868. }
  2869. }
  2870. }
  2871. }
  2872. }
  2873. else
  2874. {
  2875. if(maxProfile.ChargingSchedule.Duration != -1)
  2876. {
  2877. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2878. 0:
  2879. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2880. }
  2881. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2882. {
  2883. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2884. {
  2885. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2886. 0:
  2887. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2888. if(idxPeriod > 0)
  2889. {
  2890. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2891. {
  2892. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2893. }
  2894. }
  2895. }
  2896. }
  2897. }
  2898. }
  2899. /*
  2900. DEBUG_INFO("MaxProfile after align.\n");
  2901. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2902. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2903. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2904. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2905. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2906. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2907. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2908. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2909. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2910. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2911. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2912. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2913. {
  2914. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2915. {
  2916. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2917. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2918. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2919. }
  2920. }
  2921. DEBUG_INFO("------------------------------------\n");*/
  2922. }
  2923. /*
  2924. * Merge to conposite schedule
  2925. */
  2926. //DEBUG_INFO("====================================\n");
  2927. // Find each profile period quantity
  2928. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2929. {
  2930. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2931. limitMax = idx+1;
  2932. }
  2933. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2934. {
  2935. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2936. limitDef = idx+1;
  2937. }
  2938. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2939. {
  2940. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2941. limitTx = idx+1;
  2942. }
  2943. // TxProfile found, composite schedule based on it
  2944. if(txProfile.ChargingProfileId != -1)
  2945. {
  2946. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2947. {
  2948. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2949. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2950. (txProfile.ChargingSchedule.Duration > 0))
  2951. {
  2952. if(maxProfile.ChargingProfileId != -1)
  2953. {
  2954. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2955. {
  2956. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2957. {
  2958. if((maxProfile.ChargingSchedule.Duration > 0))
  2959. {
  2960. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2961. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2962. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2963. }
  2964. else
  2965. {
  2966. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2967. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2968. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2969. }
  2970. }
  2971. if(idxMaxPeriod == (limitMax-1))
  2972. {
  2973. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2974. {
  2975. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2976. {
  2977. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2978. compositePeriodIdx++;
  2979. }
  2980. else
  2981. {
  2982. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2983. }
  2984. }
  2985. }
  2986. }
  2987. }
  2988. else
  2989. {
  2990. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2991. {
  2992. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2993. compositePeriodIdx++;
  2994. }
  2995. else
  2996. {
  2997. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2998. }
  2999. }
  3000. }
  3001. if(idxTxPeriod == (limitTx-1))
  3002. {
  3003. if(defaultTxProfile.ChargingProfileId != -1)
  3004. {
  3005. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3006. {
  3007. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  3008. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3009. (defaultTxProfile.ChargingSchedule.Duration>0))
  3010. {
  3011. if(maxProfile.ChargingProfileId != -1)
  3012. {
  3013. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3014. {
  3015. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3016. {
  3017. if((maxProfile.ChargingSchedule.Duration > 0))
  3018. {
  3019. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3020. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3021. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  3022. }
  3023. else
  3024. {
  3025. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3026. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3027. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3028. }
  3029. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3030. {
  3031. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3032. {
  3033. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3034. compositePeriodIdx++;
  3035. }
  3036. else
  3037. {
  3038. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3039. }
  3040. }
  3041. // Delete duplicate period
  3042. if(compositePeriodIdx > 1)
  3043. {
  3044. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3045. {
  3046. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3047. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3048. compositePeriodIdx -= 1;
  3049. }
  3050. }
  3051. }
  3052. else
  3053. break;
  3054. }
  3055. }
  3056. else
  3057. {
  3058. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3059. {
  3060. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3061. compositePeriodIdx++;
  3062. }
  3063. else
  3064. {
  3065. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3066. }
  3067. }
  3068. }
  3069. }
  3070. }
  3071. }
  3072. }
  3073. }
  3074. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  3075. else if(defaultTxProfile.ChargingProfileId != -1)
  3076. {
  3077. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  3078. {
  3079. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  3080. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  3081. (defaultTxProfile.ChargingSchedule.Duration > 0))
  3082. {
  3083. if(maxProfile.ChargingProfileId != -1)
  3084. {
  3085. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3086. {
  3087. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  3088. {
  3089. if((maxProfile.ChargingSchedule.Duration > 0))
  3090. {
  3091. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3092. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3093. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  3094. }
  3095. else
  3096. {
  3097. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  3098. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  3099. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  3100. }
  3101. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3102. {
  3103. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3104. {
  3105. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3106. compositePeriodIdx++;
  3107. }
  3108. else
  3109. {
  3110. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3111. }
  3112. }
  3113. // Delete duplicate period
  3114. if(compositePeriodIdx > 1)
  3115. {
  3116. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3117. {
  3118. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3119. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3120. compositePeriodIdx -= 1;
  3121. }
  3122. }
  3123. }
  3124. else
  3125. break;
  3126. }
  3127. }
  3128. else
  3129. {
  3130. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3131. {
  3132. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3133. compositePeriodIdx++;
  3134. }
  3135. else
  3136. {
  3137. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  3138. }
  3139. }
  3140. }
  3141. }
  3142. }
  3143. // Fill other period by MaxProfile
  3144. if(maxProfile.ChargingProfileId != -1)
  3145. {
  3146. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3147. {
  3148. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  3149. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  3150. (maxProfile.ChargingSchedule.Duration > 0))
  3151. {
  3152. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  3153. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3154. {
  3155. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  3156. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  3157. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3158. }
  3159. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  3160. {
  3161. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  3162. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3163. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3164. }
  3165. if(tmpPeriod.Limit != -1)
  3166. {
  3167. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  3168. {
  3169. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  3170. {
  3171. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3172. compositePeriodIdx++;
  3173. }
  3174. else
  3175. {
  3176. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3177. }
  3178. }
  3179. // Delete duplicate period
  3180. if(compositePeriodIdx > 1)
  3181. {
  3182. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3183. {
  3184. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3185. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3186. compositePeriodIdx -= 1;
  3187. }
  3188. }
  3189. }
  3190. }
  3191. }
  3192. }
  3193. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3194. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3195. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3196. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3197. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3198. {
  3199. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3200. {
  3201. compositeProfile->ChargingProfileId = 1;
  3202. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3203. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3204. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3205. }
  3206. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3207. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3208. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3209. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3210. }
  3211. if(line)
  3212. free(line);
  3213. checkChargePointMaxProfile(durationReq, &ShmOCPP16Data->MaxChargingProfile, isUnitA);
  3214. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3215. }
  3216. //==========================================
  3217. // Init all share memory
  3218. //==========================================
  3219. int InitShareMemory()
  3220. {
  3221. int result = PASS;
  3222. int MeterSMId;
  3223. //creat ShmSysConfigAndInfo
  3224. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3225. {
  3226. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3227. result = FAIL;
  3228. }
  3229. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3230. {
  3231. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3232. result = FAIL;
  3233. }
  3234. else
  3235. {}
  3236. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3237. {
  3238. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3239. result = FAIL;
  3240. }
  3241. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3242. {
  3243. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3244. result = FAIL;
  3245. }
  3246. else
  3247. {}
  3248. //creat ShmPsuData
  3249. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3250. {
  3251. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3252. result = FAIL;
  3253. }
  3254. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3255. {
  3256. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3257. result = FAIL;
  3258. }
  3259. else
  3260. {}
  3261. //creat ShmOCPP16Data
  3262. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3263. {
  3264. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3265. result = FAIL;
  3266. }
  3267. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3268. {
  3269. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3270. result = FAIL;
  3271. }
  3272. else
  3273. {}
  3274. /****************************** For Initial Settings************************************************/
  3275. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  3276. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  3277. // allocate Configuration memory address
  3278. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  3279. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3280. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3281. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3282. //offline MeterValue Interval
  3283. TempMeterValueInterval = 0;
  3284. return result;
  3285. }
  3286. int ProcessShareMemory()
  3287. {
  3288. if(InitShareMemory() == FAIL)
  3289. {
  3290. DEBUG_ERROR("InitShareMemory NG\n");
  3291. if(ShmStatusCodeData!=NULL)
  3292. {
  3293. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3294. }
  3295. sleep(5);
  3296. return FAIL;
  3297. }
  3298. return PASS;
  3299. }
  3300. void CheckSystemValue(void)
  3301. {
  3302. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3303. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3304. char filenmae[100]={0};
  3305. char str[100]={0};
  3306. int tempIndex = 0;
  3307. //===============================
  3308. // send Heartbeat
  3309. //===============================
  3310. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3311. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3312. {
  3313. clientTime.Heartbeat=time((time_t*)NULL);
  3314. if(server_sign == TRUE)
  3315. {
  3316. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  3317. }
  3318. else
  3319. {
  3320. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3321. }
  3322. }
  3323. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3324. {
  3325. //parameter for test
  3326. sendHeartbeatRequest(0);
  3327. //==============================================
  3328. // Reset Waiting Time
  3329. //==============================================
  3330. HeartBeatWithNOResponse += 1;
  3331. }
  3332. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3333. {
  3334. //==========================================
  3335. // csu trigger DataTransferReq
  3336. //==========================================
  3337. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  3338. {
  3339. sendDataTransferRequest(gun_index);
  3340. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  3341. }
  3342. //===============================
  3343. // CSU Trigger Authorize Request
  3344. //===============================
  3345. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3346. {
  3347. sendAuthorizeRequest(0);
  3348. authorizeRetryTimes = authorizeRetryTimes + 1;
  3349. if(authorizeRetryTimes < 3)
  3350. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3351. }
  3352. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3353. {
  3354. authorizeRetryTimes = 0;
  3355. SetOcppConnStatus(FALSE);
  3356. server_sign = FALSE;
  3357. }
  3358. 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))
  3359. {
  3360. sendAuthorizeRequest(0);
  3361. }
  3362. //==============================================
  3363. // Charger start transaction
  3364. //==============================================
  3365. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3366. {
  3367. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3368. sendStartTransactionRequest(gun_index);
  3369. clientTime.StartTransaction = time((time_t*)NULL);
  3370. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3371. storeTempStopTransaction(gun_index);
  3372. }
  3373. //==============================================
  3374. // Charger stop transaction
  3375. //==============================================
  3376. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3377. {
  3378. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3379. sendStopTransactionRequest(gun_index);
  3380. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA && (gunType[gun_index] != GUN_TYPE_AC) )sendTTIAInfo(gun_index);
  3381. clientTime.StopTransaction = time((time_t*)NULL);
  3382. }
  3383. //==============================================
  3384. // Charger status report
  3385. //==============================================
  3386. //--- Check Mode Change ---//
  3387. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3388. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3389. {
  3390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3391. {
  3392. tempIndex = ((gun_index==2) ? 1: 0);
  3393. }
  3394. else
  3395. {
  3396. tempIndex = gun_index;
  3397. }
  3398. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3399. {
  3400. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3401. {
  3402. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3403. {
  3404. // Sent unplug message for California pricing logic
  3405. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3406. {
  3407. uint8_t ts[20];
  3408. getNowDatetime(ts);
  3409. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3410. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3411. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3412. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3413. }
  3414. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3415. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3416. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3417. }
  3418. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3419. {
  3420. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3421. if((access(filenmae,F_OK))!=-1)
  3422. {
  3423. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3424. sprintf(str,"rm -f %s",filenmae);
  3425. system(str);
  3426. }
  3427. }
  3428. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3429. #if 1 // for TempStopTransaction
  3430. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3431. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3432. {
  3433. checkTempStopTransaction(gun_index);
  3434. }
  3435. #endif
  3436. }
  3437. }
  3438. }
  3439. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3440. {
  3441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3442. {
  3443. tempIndex = ((gun_index==2) ? 1: 0);
  3444. }
  3445. else
  3446. {
  3447. tempIndex = gun_index;
  3448. }
  3449. for (int index = 0; index < CCS_QUANTITY; index++)
  3450. {
  3451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3452. {
  3453. 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]*/ )
  3454. {
  3455. // Sent unplug message for California pricing logic
  3456. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3457. {
  3458. uint8_t ts[20];
  3459. getNowDatetime(ts);
  3460. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3461. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3462. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3463. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3464. }
  3465. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3466. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3467. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3468. }
  3469. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3470. {
  3471. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3472. if((access(filenmae,F_OK))!=-1)
  3473. {
  3474. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3475. sprintf(str,"rm -f %s",filenmae);
  3476. system(str);
  3477. }
  3478. }
  3479. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3480. #if 1 // for TempStopTransaction
  3481. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3482. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3483. {
  3484. checkTempStopTransaction(gun_index);
  3485. }
  3486. #endif
  3487. }
  3488. }
  3489. }
  3490. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3491. {
  3492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3493. {
  3494. tempIndex = ((gun_index==2) ? 1: 0);
  3495. }
  3496. else
  3497. {
  3498. tempIndex = gun_index;
  3499. }
  3500. for (int index = 0; index < GB_QUANTITY; index++)
  3501. {
  3502. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3503. {
  3504. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3505. {
  3506. // Sent unplug message for California pricing logic
  3507. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3508. {
  3509. uint8_t ts[20];
  3510. getNowDatetime(ts);
  3511. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3512. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3513. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3514. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3515. }
  3516. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3517. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3518. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3519. }
  3520. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3521. {
  3522. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3523. if((access(filenmae,F_OK))!=-1)
  3524. {
  3525. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3526. sprintf(str,"rm -f %s",filenmae);
  3527. system(str);
  3528. }
  3529. }
  3530. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3531. #if 1 // for TempStopTransaction
  3532. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3533. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3534. {
  3535. checkTempStopTransaction(gun_index);
  3536. }
  3537. #endif
  3538. }
  3539. }
  3540. }
  3541. else if(gunType[gun_index] == GUN_TYPE_DO)
  3542. {
  3543. tempIndex = gun_index;
  3544. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3545. {
  3546. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3547. {
  3548. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3549. {
  3550. // Sent unplug message for California pricing logic
  3551. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3552. {
  3553. uint8_t ts[20];
  3554. getNowDatetime(ts);
  3555. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3556. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3557. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3558. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3559. }
  3560. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3561. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3562. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3563. }
  3564. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  3565. {
  3566. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3567. if((access(filenmae,F_OK))!=-1)
  3568. {
  3569. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3570. sprintf(str,"rm -f %s",filenmae);
  3571. system(str);
  3572. }
  3573. }
  3574. 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);
  3575. #if 1 // for TempStopTransaction
  3576. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3577. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3578. {
  3579. checkTempStopTransaction(gun_index);
  3580. }
  3581. #endif
  3582. }
  3583. }
  3584. }
  3585. else
  3586. {
  3587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3588. {
  3589. tempIndex = 2;
  3590. }
  3591. else
  3592. {
  3593. tempIndex = gun_index;
  3594. }
  3595. for (int index = 0; index < AC_QUANTITY; index++)
  3596. {
  3597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3598. {
  3599. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3600. {
  3601. // Sent unplug message for California pricing logic
  3602. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3603. {
  3604. uint8_t ts[20];
  3605. getNowDatetime(ts);
  3606. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].VendorId, "org.openchargealliance.costmsg");
  3607. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3608. sprintf((char*)ShmOCPP16Data->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId, ts);
  3609. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 1;
  3610. }
  3611. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3612. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3613. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3614. }
  3615. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3616. {
  3617. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  3618. if((access(filenmae,F_OK))!=-1)
  3619. {
  3620. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3621. sprintf(str,"rm -f %s",filenmae);
  3622. system(str);
  3623. }
  3624. }
  3625. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3626. #if 1 // for TempStopTransaction
  3627. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3628. (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3629. {
  3630. checkTempStopTransaction(gun_index);
  3631. }
  3632. #endif
  3633. }
  3634. }// END
  3635. }
  3636. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3637. (
  3638. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3639. )
  3640. )
  3641. {
  3642. if(SystemInitial > 0)
  3643. SystemInitial -= 1;
  3644. sendStatusNotificationRequest(gun_index);
  3645. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3646. }
  3647. //==============================================
  3648. // CSU Trigger Smart Charging Profilw
  3649. //==============================================
  3650. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3651. {
  3652. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index], TRUE);
  3653. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3654. }
  3655. //==============================================
  3656. // Meter report
  3657. //==============================================
  3658. // Trigger MeterValue
  3659. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3660. {
  3661. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3662. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3663. }
  3664. // ClockAlign MeterValue
  3665. 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))
  3666. {
  3667. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3668. {
  3669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3670. {
  3671. tempIndex = ((gun_index==2) ? 1: 0);
  3672. }
  3673. else
  3674. {
  3675. tempIndex = gun_index;
  3676. }
  3677. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3678. {
  3679. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3680. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3681. {
  3682. reqClockAlignMeter[gun_index] = 1;
  3683. }
  3684. }// End for CHAdeMO
  3685. }
  3686. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3687. {
  3688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3689. {
  3690. tempIndex = ((gun_index==2) ? 1: 0);
  3691. }
  3692. else
  3693. {
  3694. tempIndex = gun_index;
  3695. }
  3696. for (int index = 0; index < CCS_QUANTITY; index++)
  3697. {
  3698. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3699. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3700. {
  3701. reqClockAlignMeter[gun_index] = 1;
  3702. }
  3703. } // End for CCS
  3704. }
  3705. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3706. {
  3707. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3708. {
  3709. tempIndex = ((gun_index==2) ? 1: 0);
  3710. }
  3711. else
  3712. {
  3713. tempIndex = gun_index;
  3714. }
  3715. for (int index = 0; index < GB_QUANTITY; index++)
  3716. {
  3717. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3718. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3719. {
  3720. reqClockAlignMeter[gun_index] = 1;
  3721. }
  3722. }// End for GB
  3723. }
  3724. else if(gunType[gun_index] == GUN_TYPE_DO)
  3725. {
  3726. tempIndex = gun_index;
  3727. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3728. {
  3729. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3730. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3731. {
  3732. reqClockAlignMeter[gun_index] = 1;
  3733. }
  3734. }
  3735. }
  3736. else
  3737. {
  3738. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3739. {
  3740. tempIndex = 2;
  3741. }
  3742. else
  3743. {
  3744. tempIndex = gun_index;
  3745. }
  3746. for (int index = 0; index < AC_QUANTITY; index++)
  3747. {
  3748. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3749. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3750. {
  3751. reqClockAlignMeter[gun_index] = 1;
  3752. }
  3753. }//End for AC
  3754. }
  3755. if(reqClockAlignMeter[gun_index] == 1)
  3756. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3757. }
  3758. // Sample period MeterValue
  3759. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3760. {
  3761. //check Transaction active
  3762. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3763. {
  3764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3765. {
  3766. tempIndex = ((gun_index==2) ? 1: 0);
  3767. }
  3768. else
  3769. {
  3770. tempIndex = gun_index;
  3771. }
  3772. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3773. {
  3774. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3775. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3776. {
  3777. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3778. {
  3779. reqSampleMeter[gun_index] = 1;
  3780. }
  3781. }
  3782. }// End for CHAdeMO
  3783. }
  3784. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3785. {
  3786. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3787. {
  3788. tempIndex = ((gun_index==2) ? 1: 0);
  3789. }
  3790. else
  3791. {
  3792. tempIndex = gun_index;
  3793. }
  3794. for (int index = 0; index < CCS_QUANTITY; index++)
  3795. {
  3796. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3797. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3798. {
  3799. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3800. {
  3801. reqSampleMeter[gun_index] = 1;
  3802. }
  3803. }
  3804. } // End for CCS
  3805. }
  3806. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3807. {
  3808. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3809. {
  3810. tempIndex = ((gun_index==2) ? 1: 0);
  3811. }
  3812. else
  3813. {
  3814. tempIndex = gun_index;
  3815. }
  3816. for (int index = 0; index < GB_QUANTITY; index++)
  3817. {
  3818. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3819. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3820. {
  3821. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3822. {
  3823. reqSampleMeter[gun_index] = 1;
  3824. }
  3825. }
  3826. }// End for GB
  3827. }
  3828. else if(gunType[gun_index] == GUN_TYPE_DO)
  3829. {
  3830. tempIndex = gun_index;
  3831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3832. {
  3833. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3834. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3835. {
  3836. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3837. {
  3838. reqSampleMeter[gun_index] = 1;
  3839. }
  3840. }
  3841. }
  3842. }
  3843. else
  3844. {
  3845. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3846. {
  3847. tempIndex = 2;
  3848. }
  3849. else
  3850. {
  3851. tempIndex = gun_index;
  3852. }
  3853. for (int index = 0; index < AC_QUANTITY; index++)
  3854. {
  3855. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3856. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3857. {
  3858. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3859. {
  3860. reqSampleMeter[gun_index] = 1;
  3861. }
  3862. }
  3863. }//End for AC
  3864. }
  3865. if(reqSampleMeter[gun_index] == 1)
  3866. {
  3867. if(atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3868. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3869. storeTempStopTransaction(gun_index);
  3870. }
  3871. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3872. }
  3873. //==============================================
  3874. // Check Connector reserved
  3875. //==============================================
  3876. //===============================
  3877. // Check if Reserve is expired
  3878. //===============================
  3879. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3880. {
  3881. double diff_t;
  3882. struct tm tp;
  3883. // current time
  3884. time_t t = time(NULL);
  3885. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3886. tp.tm_isdst = -1;
  3887. time_t utc = mktime(&tp);
  3888. diff_t = difftime(utc, t);
  3889. if(diff_t <= 0)
  3890. {
  3891. DEBUG_INFO("reserve expired.\n");
  3892. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  3893. }
  3894. }//END OF Check if Reserve is expired
  3895. //==========================================
  3896. // csu trigger FirmwareStatusNotificationReq
  3897. //==========================================
  3898. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3899. {
  3900. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  3901. }
  3902. //==========================================
  3903. // csu trigger DiagnosticsStatusNotificationReq
  3904. //==========================================
  3905. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3906. {
  3907. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status);
  3908. }
  3909. //==========================================
  3910. // csu trigger CancelReservationConf
  3911. //==========================================
  3912. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3913. {
  3914. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  3915. ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3916. }
  3917. //==========================================
  3918. // csu trigger ChangeAvailabilityConf
  3919. //==========================================
  3920. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3921. {
  3922. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  3923. }
  3924. //==========================================
  3925. // csu trigger UnlockConnectorConf
  3926. //==========================================
  3927. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3928. {
  3929. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  3930. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3931. }
  3932. //==========================================
  3933. // csu trigger ReserveNowConf
  3934. //==========================================
  3935. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3936. {
  3937. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  3938. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3939. }
  3940. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP/certCP.csr",F_OK) != -1))
  3941. {
  3942. sendSignCertificateRequest();
  3943. }
  3944. }
  3945. }
  3946. //==========================================
  3947. // send request routine
  3948. //==========================================
  3949. int sendAuthorizeRequest(int gun_index)
  3950. {
  3951. mtrace();
  3952. int result = FAIL;
  3953. char message[100]={0};
  3954. char guid[37];
  3955. char tempdata[65]={0};
  3956. DEBUG_INFO("sendAuthorizeRequest...\n");
  3957. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3958. //Local Authorize
  3959. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  3960. {
  3961. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3962. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3963. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3964. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3965. result = PASS;
  3966. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  3967. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3968. authorizeRetryTimes = 0;
  3969. return result;
  3970. }
  3971. 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))||
  3972. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3973. {
  3974. // Query from cache
  3975. DEBUG_INFO("Authorize from cache.\n");
  3976. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3977. // Query from list
  3978. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3979. {
  3980. DEBUG_INFO("Authorize from list.\n");
  3981. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3982. }
  3983. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3984. {
  3985. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3986. {
  3987. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3988. }
  3989. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3990. {
  3991. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3992. }
  3993. if(!GetOcppConnStatus())
  3994. {
  3995. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3996. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3997. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3998. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3999. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4000. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4001. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4002. authorizeRetryTimes = 0;
  4003. return result;
  4004. }
  4005. }
  4006. else
  4007. {
  4008. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  4009. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  4010. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  4011. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  4012. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  4013. else
  4014. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  4015. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  4016. result = PASS;
  4017. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4018. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  4019. authorizeRetryTimes = 0;
  4020. return result;
  4021. }
  4022. }
  4023. //initialize struct Authorize
  4024. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  4025. //get data from shared memory
  4026. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4027. random_uuid(guid);
  4028. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  4029. LWS_Send(message);
  4030. sprintf(tempdata, "Authorize,%d", gun_index);
  4031. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4032. {
  4033. result = PASS;
  4034. DEBUG_INFO("Authorize mapItem pass\n");
  4035. }
  4036. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  4037. return result;
  4038. }
  4039. int sendBootNotificationRequest(void)
  4040. {
  4041. mtrace();
  4042. int result = FAIL;
  4043. char message[500]={0}, payload[700]={0};
  4044. char guid[37]={0};
  4045. char tempdata[65]={0};
  4046. // Fill BootNotification fields
  4047. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  4048. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  4049. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  4050. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4051. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  4052. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  4053. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  4054. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  4055. ShmOCPP16Data->ChargeBoxId
  4056. ,ShmSysConfigAndInfo->SysConfig.ModelName
  4057. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  4058. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  4059. ,ShmOCPP16Data->BootNotification.CpFwVersion
  4060. ,ShmOCPP16Data->BootNotification.CpIccid
  4061. ,ShmOCPP16Data->BootNotification.CpImsi);
  4062. random_uuid(guid);
  4063. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  4064. LWS_Send(message);
  4065. sprintf(tempdata, "BootNotification,0");
  4066. 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*/)
  4067. {
  4068. result = PASS;
  4069. }
  4070. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4071. strcpy(queuedata,message);
  4072. return result;
  4073. }
  4074. int sendDataTransferRequest(int gun_index)
  4075. {
  4076. mtrace();
  4077. char message[1000]={0};
  4078. char guid[37]={0};
  4079. char tempdata[65]={0};
  4080. int result = FAIL;
  4081. random_uuid(guid);
  4082. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  4083. MESSAGE_TYPE_CALL,
  4084. guid,
  4085. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  4086. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  4087. ShmOCPP16Data->DataTransfer[gun_index].Data);
  4088. LWS_Send(message);
  4089. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  4090. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4091. {
  4092. result = PASS;
  4093. DEBUG_INFO("DataTransfer mapItem pass\n");
  4094. }
  4095. return result;
  4096. }
  4097. int sendDiagnosticsStatusNotificationRequest(char *status)
  4098. {
  4099. mtrace();
  4100. int result = FAIL;
  4101. char message[110]={0};
  4102. char guid[37]={0};
  4103. char tempdata[65]={0};
  4104. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  4105. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  4106. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  4107. random_uuid(guid);
  4108. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  4109. LWS_SendNow(message);
  4110. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  4111. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4112. {
  4113. result = PASS;
  4114. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  4115. }
  4116. //#ifdef SystemLogMessage
  4117. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  4118. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4119. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  4120. //#endif
  4121. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  4122. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  4123. //record status
  4124. if(strcmp(status,"Idle")==0)
  4125. {
  4126. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  4127. }
  4128. else if(strcmp(status,"Uploaded")==0)
  4129. {
  4130. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  4131. }
  4132. else if(strcmp(status,"UploadFailed")==0)
  4133. {
  4134. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  4135. }
  4136. else if(strcmp(status,"Uploading")==0)
  4137. {
  4138. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4139. }
  4140. return result;
  4141. }
  4142. int sendFirmwareStatusNotificationRequest(char *status)
  4143. {
  4144. mtrace();
  4145. int result = FAIL;
  4146. char message[110]={0};
  4147. char guid[37]={0};
  4148. char tempdata[65]={0};
  4149. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4150. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4151. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4152. random_uuid(guid);
  4153. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4154. LWS_SendNow(message);
  4155. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4156. 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*/)
  4157. {
  4158. result = PASS;
  4159. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4160. }
  4161. //#ifdef SystemLogMessage
  4162. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4163. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4164. //#endif
  4165. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4166. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4167. //record status
  4168. if(strcmp(status,"Downloaded")==0)
  4169. {
  4170. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4171. }
  4172. else if(strcmp(status,"DownloadFailed")==0)
  4173. {
  4174. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4175. }
  4176. else if(strcmp(status,"Downloading")==0)
  4177. {
  4178. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4179. }
  4180. else if(strcmp(status,"Idle")==0)
  4181. {
  4182. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4183. }
  4184. else if(strcmp(status,"InstallationFailed")==0)
  4185. {
  4186. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4187. }
  4188. else if(strcmp(status,"Installing")==0)
  4189. {
  4190. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4191. }
  4192. else if(strcmp(status,"Installed")==0)
  4193. {
  4194. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4195. }
  4196. return result;
  4197. }
  4198. int sendHeartbeatRequest(int gun_index)
  4199. {
  4200. mtrace();
  4201. int result = FAIL;
  4202. char message[80]={0};
  4203. char guid[37]={0};
  4204. char tempdata[65]={0};
  4205. random_uuid(guid);
  4206. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4207. , MESSAGE_TYPE_CALL
  4208. , guid );
  4209. LWS_Send(message);
  4210. sprintf(tempdata, "Heartbeat,%d", 0);
  4211. 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*/)
  4212. {
  4213. result = PASS;
  4214. }
  4215. return result;
  4216. }
  4217. int sendStartTransactionRequest(int gun_index)
  4218. {
  4219. mtrace();
  4220. int result = FAIL;
  4221. char message[250]={0};
  4222. char guid[37]={0};
  4223. struct timeval tmnow;
  4224. struct tm *tm;
  4225. char buf[28];//, usec_buf[6];
  4226. char tempdata[65]={0};
  4227. int tempIndex = 0;
  4228. DEBUG_INFO("sendStartTransactionRequest...\n");
  4229. gettimeofday(&tmnow, NULL);
  4230. time_t t;
  4231. t = time(NULL);
  4232. /*UTC time and date*/
  4233. tm = gmtime(&t);
  4234. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4235. #if 0 // remove temporally
  4236. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4237. strcat(buf,".");
  4238. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4239. strcat(buf,usec_buf);
  4240. #endif
  4241. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4242. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  4243. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4244. // clear StartTransaction Response
  4245. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4246. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4247. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4248. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  4249. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4250. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4251. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4252. {
  4253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4254. {
  4255. tempIndex = ((gun_index==2) ? 1: 0);
  4256. }
  4257. else
  4258. {
  4259. tempIndex = gun_index;
  4260. }
  4261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4262. {
  4263. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4264. {
  4265. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4266. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4267. }
  4268. }
  4269. }
  4270. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4271. {
  4272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4273. {
  4274. tempIndex = ((gun_index==2) ? 1: 0);
  4275. }
  4276. else
  4277. {
  4278. tempIndex = gun_index;
  4279. }
  4280. for (int index = 0; index < CCS_QUANTITY; index++)
  4281. {
  4282. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4283. {
  4284. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4285. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4286. }
  4287. }
  4288. }
  4289. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4290. {
  4291. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4292. {
  4293. tempIndex = ((gun_index==2) ? 1: 0);
  4294. }
  4295. else
  4296. {
  4297. tempIndex = gun_index;
  4298. }
  4299. for (int index = 0; index < GB_QUANTITY; index++)
  4300. {
  4301. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4302. {
  4303. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4304. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4305. }
  4306. }
  4307. }
  4308. else if(gunType[gun_index] == GUN_TYPE_DO)
  4309. {
  4310. tempIndex = gun_index;
  4311. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4312. {
  4313. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4314. {
  4315. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4316. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4317. }
  4318. }
  4319. }
  4320. else
  4321. {
  4322. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4323. {
  4324. tempIndex = 2;
  4325. }
  4326. else
  4327. {
  4328. tempIndex = gun_index;
  4329. }
  4330. for (int index = 0; index < AC_QUANTITY; index++)
  4331. {
  4332. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4333. {
  4334. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4335. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4336. }
  4337. }
  4338. }
  4339. random_uuid(guid);
  4340. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4341. {
  4342. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4343. , gun_index +1
  4344. , MESSAGE_TYPE_CALL
  4345. , guid
  4346. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4347. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4348. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4349. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4350. }
  4351. else
  4352. {
  4353. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4354. , gun_index +1
  4355. , MESSAGE_TYPE_CALL
  4356. , guid
  4357. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  4358. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  4359. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  4360. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  4361. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  4362. }
  4363. #if 1
  4364. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4365. 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*/)
  4366. {
  4367. result = PASS;
  4368. }
  4369. #endif
  4370. strcpy(queuedata, message);
  4371. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4372. OCPP_insert_transaction_msg(YES, queuedata);
  4373. return result;
  4374. }
  4375. int sendStatusNotificationRequest(int gun_index)
  4376. {
  4377. mtrace();
  4378. int result = FAIL;
  4379. char message[600]={0};
  4380. char guid[37];
  4381. int currentStatus = 0;
  4382. struct timeval tmnow;
  4383. struct tm *tm;
  4384. char buf[28];//, usec_buf[6];
  4385. char tempdata[65]={0};
  4386. int tempIndex = 0;
  4387. uint8_t isStateChanged = TRUE;
  4388. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4389. gettimeofday(&tmnow, NULL);
  4390. time_t t;
  4391. t = time(NULL);
  4392. /*UTC time and date*/
  4393. tm = gmtime(&t);
  4394. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4395. #if 0 // remove temporally
  4396. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4397. strcat(buf,".");
  4398. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4399. strcat(buf,usec_buf);
  4400. #endif
  4401. //printf("%s",buf);
  4402. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4403. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4404. // it's option
  4405. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  4406. /*
  4407. enum _SYSTEM_STATUS
  4408. {
  4409. S_BOOTING = 0,
  4410. S_IDLE, = 1
  4411. S_AUTHORIZING, =2
  4412. S_REASSIGN_CHECK, =3
  4413. S_REASSIGN, =4
  4414. S_PRECHARGE, =5
  4415. S_PREPARING_FOR_EV, =6
  4416. S_PREPARING_FOR_EVSE, =7
  4417. S_CHARGING, =8
  4418. S_TERMINATING, =9
  4419. S_COMPLETE, =10
  4420. S_ALARM, =11
  4421. S_FAULT =12
  4422. }
  4423. */
  4424. //check Transaction active
  4425. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4426. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4427. {
  4428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4429. {
  4430. tempIndex = ((gun_index==2) ? 1: 0);
  4431. }
  4432. else
  4433. {
  4434. tempIndex = gun_index;
  4435. }
  4436. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4437. {
  4438. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4439. {
  4440. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4441. {
  4442. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4443. {
  4444. currentStatus = Preparing; //OCPP Status: Preparing
  4445. }
  4446. else
  4447. {
  4448. currentStatus = Available; //OCPP Status: Available
  4449. }
  4450. }
  4451. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4452. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4453. ) //S_PRECHARGE
  4454. {
  4455. currentStatus = Preparing; //OCPP Status: Preparing
  4456. }
  4457. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4458. {
  4459. currentStatus = Charging; //OCPP Status: Charging
  4460. }
  4461. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4462. {
  4463. currentStatus = Finishing; //OCPP Status: Finishing
  4464. }
  4465. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4466. {
  4467. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4468. }
  4469. 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
  4470. {
  4471. currentStatus = Unavailable; //OCPP Status: Unavailable
  4472. }
  4473. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4474. {
  4475. currentStatus = Faulted; //OCPP Status: Faulted
  4476. }
  4477. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4478. {
  4479. currentStatus = Reserved; //OCPP Status: Reserved
  4480. }
  4481. } //end of the same index
  4482. }//end of for CHAdeMO_QUANTITY
  4483. }
  4484. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4485. {
  4486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4487. {
  4488. tempIndex = ((gun_index==2) ? 1: 0);
  4489. }
  4490. else
  4491. {
  4492. tempIndex = gun_index;
  4493. }
  4494. for (int index = 0; index < CCS_QUANTITY; index++)
  4495. {
  4496. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4497. {
  4498. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4499. {
  4500. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4501. {
  4502. currentStatus = Preparing; //OCPP Status: Preparing
  4503. }
  4504. else
  4505. {
  4506. currentStatus = Available; //OCPP Status: Available
  4507. }
  4508. }
  4509. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4510. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4511. ) //S_PRECHARGE
  4512. {
  4513. currentStatus = Preparing; //OCPP Status: Preparing
  4514. }
  4515. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4516. {
  4517. currentStatus = Charging; //OCPP Status: Charging
  4518. }
  4519. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4520. {
  4521. currentStatus = Finishing; //OCPP Status: Finishing
  4522. }
  4523. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4524. {
  4525. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4526. }
  4527. 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
  4528. {
  4529. currentStatus = Unavailable; //OCPP Status : Unavailable
  4530. }
  4531. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4532. {
  4533. currentStatus = Faulted; //OCPP Status: Faulted
  4534. }
  4535. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4536. {
  4537. currentStatus = Reserved; //OCPP Status: Reserved
  4538. }
  4539. } //end of the same index
  4540. } // end of for CCS_QUANTITY
  4541. }
  4542. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4543. {
  4544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4545. {
  4546. tempIndex = ((gun_index==2) ? 1: 0);
  4547. }
  4548. else
  4549. {
  4550. tempIndex = gun_index;
  4551. }
  4552. for (int index = 0; index < GB_QUANTITY; index++)
  4553. {
  4554. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4555. {
  4556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4557. {
  4558. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4559. {
  4560. currentStatus = Preparing; //OCPP Status: Preparing
  4561. }
  4562. else
  4563. {
  4564. currentStatus = Available; //OCPP Status: Available
  4565. }
  4566. }
  4567. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4568. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4569. ) //S_PRECHARGE
  4570. {
  4571. currentStatus = Preparing; //OCPP Status: Preparing
  4572. }
  4573. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4574. {
  4575. currentStatus = Charging; //OCPP Status: Charging
  4576. }
  4577. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4578. {
  4579. currentStatus = Finishing; //OCPP Status: Finishing
  4580. }
  4581. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4582. {
  4583. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4584. }
  4585. 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
  4586. {
  4587. currentStatus = Unavailable; //OCPP Status: Unavailable
  4588. }
  4589. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4590. {
  4591. currentStatus = Faulted; //OCPP Status: Faulted
  4592. }
  4593. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4594. {
  4595. currentStatus = Reserved; //OCPP Status: Reserved
  4596. }
  4597. } //end of the same index
  4598. } // end of for GB_QUANTITY
  4599. }
  4600. else if(gunType[gun_index] == GUN_TYPE_DO)
  4601. {
  4602. tempIndex = gun_index;
  4603. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4604. {
  4605. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4606. {
  4607. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4608. {
  4609. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4610. {
  4611. currentStatus = Preparing; //OCPP Status: Preparing
  4612. }
  4613. else
  4614. {
  4615. currentStatus = Available; //OCPP Status: Available
  4616. }
  4617. }
  4618. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4619. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4620. ) //S_PRECHARGE
  4621. {
  4622. currentStatus = Preparing; //OCPP Status: Preparing
  4623. }
  4624. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4625. {
  4626. currentStatus = Charging; //OCPP Status: Charging
  4627. }
  4628. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4629. {
  4630. currentStatus = Finishing; //OCPP Status: Finishing
  4631. }
  4632. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4633. {
  4634. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4635. }
  4636. 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
  4637. {
  4638. currentStatus = Unavailable; //OCPP Status: Unavailable
  4639. }
  4640. 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
  4641. {
  4642. currentStatus = Faulted; //OCPP Status: Faulted
  4643. }
  4644. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4645. {
  4646. currentStatus = Reserved; //OCPP Status: Reserved
  4647. }
  4648. } //end of the same index
  4649. }
  4650. }
  4651. else
  4652. {
  4653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4654. {
  4655. tempIndex = 2;
  4656. }
  4657. else
  4658. {
  4659. tempIndex = gun_index;
  4660. }
  4661. for (int index = 0; index < AC_QUANTITY; index++)
  4662. {
  4663. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4664. {
  4665. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4666. {
  4667. 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))
  4668. {
  4669. currentStatus = Preparing; //OCPP Status: Preparing
  4670. }
  4671. else
  4672. {
  4673. currentStatus = Available; //OCPP Status: Available
  4674. }
  4675. }
  4676. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4677. {
  4678. currentStatus = Preparing; //OCPP Status: Preparing
  4679. }
  4680. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4681. {
  4682. currentStatus = Charging; //OCPP Status: Charging
  4683. }
  4684. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4685. {
  4686. currentStatus = Finishing; //OCPP Status: Finishing
  4687. }
  4688. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4689. {
  4690. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4691. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4692. else
  4693. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4694. }
  4695. 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
  4696. {
  4697. currentStatus = Unavailable; //OCPP Status: Unavailable
  4698. }
  4699. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4700. {
  4701. currentStatus = Faulted; //OCPP Status: Faulted
  4702. }
  4703. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4704. {
  4705. currentStatus = Reserved; //OCPP Status: Reserved
  4706. }
  4707. }//end of the same index
  4708. }//end of for AC_QUANTITY
  4709. }
  4710. //it's option
  4711. if(((strstr((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16Data->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4712. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4713. {
  4714. isStateChanged = FALSE;
  4715. }
  4716. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4717. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  4718. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4719. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4720. random_uuid(guid);
  4721. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4722. , MESSAGE_TYPE_CALL
  4723. , guid
  4724. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  4725. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  4726. , ShmOCPP16Data->StatusNotification[gun_index].Info
  4727. , ShmOCPP16Data->StatusNotification[gun_index].Status
  4728. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  4729. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  4730. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  4731. if((server_sign == TRUE) && isStateChanged)
  4732. {
  4733. LWS_Send(message);
  4734. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4735. 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*/)
  4736. {
  4737. //DEBUG_ERROR("statusNotification mapitem pass");
  4738. result = PASS;
  4739. }
  4740. }
  4741. else
  4742. {
  4743. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4744. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4745. result = PASS;
  4746. }
  4747. return result;
  4748. }
  4749. int sendStopTransactionRequest(int gun_index)
  4750. {
  4751. mtrace();
  4752. int result = FAIL;
  4753. //char message[1500]={0};
  4754. char guid[37]={0};
  4755. char tempdata[65]={0};
  4756. int tempIndex = 0;
  4757. char TempStopTransaction[256];
  4758. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  4759. //int idx_sample=0;
  4760. DEBUG_INFO("sendStopTransactionRequest \n");
  4761. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4762. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  4763. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4764. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4765. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4766. {
  4767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4768. {
  4769. tempIndex = ((gun_index==2) ? 1: 0);
  4770. }
  4771. else
  4772. {
  4773. tempIndex = gun_index;
  4774. }
  4775. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4776. {
  4777. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4778. {
  4779. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4780. }
  4781. }// END OF CHAdeMO_QUANTITY
  4782. }
  4783. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4784. {
  4785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4786. {
  4787. tempIndex = ((gun_index==2) ? 1: 0);
  4788. }
  4789. else
  4790. {
  4791. tempIndex = gun_index;
  4792. }
  4793. for (int index = 0; index < CCS_QUANTITY; index++)
  4794. {
  4795. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4796. {
  4797. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4798. }
  4799. }// END OF CCS_QUANTITY
  4800. }
  4801. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4802. {
  4803. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4804. {
  4805. tempIndex = ((gun_index==2) ? 1: 0);
  4806. }
  4807. else
  4808. {
  4809. tempIndex = gun_index;
  4810. }
  4811. for (int index = 0; index < GB_QUANTITY; index++)
  4812. {
  4813. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4814. {
  4815. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4816. }
  4817. }// END OF GB_QUANTITY
  4818. }
  4819. else if(gunType[gun_index] == GUN_TYPE_DO)
  4820. {
  4821. tempIndex = gun_index;
  4822. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4823. {
  4824. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4825. {
  4826. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4827. }
  4828. }// END OF GB_QUANTITY
  4829. }
  4830. else
  4831. {
  4832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4833. {
  4834. tempIndex = 2;
  4835. }
  4836. else
  4837. {
  4838. tempIndex = gun_index;
  4839. }
  4840. for (int index = 0; index < AC_QUANTITY; index++)
  4841. {
  4842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4843. {
  4844. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4845. }
  4846. }// END OF AC_QUANTITY
  4847. }
  4848. //====================================== Stop Transaction Time =====================================================
  4849. struct timeval tmnow;
  4850. struct tm *tm;
  4851. char buf[28];//, usec_buf[6];
  4852. gettimeofday(&tmnow, NULL);
  4853. time_t t;
  4854. t = time(NULL);
  4855. /*UTC time and date*/
  4856. tm = gmtime(&t);
  4857. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  4859. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4860. random_uuid(guid);
  4861. /***********************************transactionData******************************************************/
  4862. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4863. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4864. //=================================
  4865. // Transaction_Begin
  4866. //=================================
  4867. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4868. {
  4869. //============================================ Energy.Active.Import.Interval ================================
  4870. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4873. 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*/]);
  4874. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4875. 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))
  4876. {
  4877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4878. }
  4879. else
  4880. {
  4881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4882. }
  4883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4884. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4885. }
  4886. //=================================
  4887. // Transaction_End
  4888. //=================================
  4889. // ================================= Current.Import L1 ===============================================
  4890. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4891. {
  4892. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4894. {
  4895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4896. {
  4897. tempIndex = ((gun_index==2) ? 1: 0);
  4898. }
  4899. else
  4900. {
  4901. tempIndex = gun_index;
  4902. }
  4903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4904. {
  4905. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4906. {
  4907. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4908. }
  4909. }// End of for CHAdeMO_QUANTITY
  4910. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4911. }
  4912. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4913. {
  4914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4915. {
  4916. tempIndex = ((gun_index==2) ? 1: 0);
  4917. }
  4918. else
  4919. {
  4920. tempIndex = gun_index;
  4921. }
  4922. for (int index = 0; index < CCS_QUANTITY; index++)
  4923. {
  4924. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4925. {
  4926. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4927. }
  4928. }// End of for CCS_QUANTITY
  4929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4930. }
  4931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4932. {
  4933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4934. {
  4935. tempIndex = ((gun_index==2) ? 1: 0);
  4936. }
  4937. else
  4938. {
  4939. tempIndex = gun_index;
  4940. }
  4941. for (int index = 0; index < GB_QUANTITY; index++)
  4942. {
  4943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4944. {
  4945. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4946. }
  4947. }// End of for GB_QUANTITY
  4948. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4949. }
  4950. else if(gunType[gun_index] == GUN_TYPE_DO)
  4951. {
  4952. tempIndex = gun_index;
  4953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4954. {
  4955. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4956. {
  4957. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4958. }
  4959. }
  4960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4961. }
  4962. else
  4963. {
  4964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4965. {
  4966. tempIndex = 2;
  4967. }
  4968. else
  4969. {
  4970. tempIndex = gun_index;
  4971. }
  4972. for (int index = 0; index < AC_QUANTITY; index++)
  4973. {
  4974. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4975. {
  4976. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4977. }
  4978. }// End of for AC_QUANTITY
  4979. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4980. }
  4981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4986. }
  4987. // ================================= Energy.Active.Import.Interval ==============================================
  4988. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4989. {
  4990. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4991. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4992. {
  4993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4994. {
  4995. tempIndex = ((gun_index==2) ? 1: 0);
  4996. }
  4997. else
  4998. {
  4999. tempIndex = gun_index;
  5000. }
  5001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5002. {
  5003. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5004. {
  5005. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5006. }
  5007. }// END OF CHAdeMO_QUANTITY
  5008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5009. }
  5010. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5011. {
  5012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5013. {
  5014. tempIndex = ((gun_index==2) ? 1: 0);
  5015. }
  5016. else
  5017. {
  5018. tempIndex = gun_index;
  5019. }
  5020. for (int index = 0; index < CCS_QUANTITY; index++)
  5021. {
  5022. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5023. {
  5024. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5025. }
  5026. }// END OF CCS_QUANTITY
  5027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5028. }
  5029. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5030. {
  5031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5032. {
  5033. tempIndex = ((gun_index==2) ? 1: 0);
  5034. }
  5035. else
  5036. {
  5037. tempIndex = gun_index;
  5038. }
  5039. for (int index = 0; index < GB_QUANTITY; index++)
  5040. {
  5041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5042. {
  5043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5044. }
  5045. }// END OF GB_QUANTITY
  5046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5047. }
  5048. else if(gunType[gun_index] == GUN_TYPE_DO)
  5049. {
  5050. tempIndex = gun_index;
  5051. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5052. {
  5053. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5054. {
  5055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5056. }
  5057. }
  5058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  5059. }
  5060. else
  5061. {
  5062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5063. {
  5064. tempIndex = 2;
  5065. }
  5066. else
  5067. {
  5068. tempIndex = gun_index;
  5069. }
  5070. for (int index = 0; index < AC_QUANTITY; index++)
  5071. {
  5072. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5073. {
  5074. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  5075. }
  5076. }// END OF AC_QUANTITY
  5077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  5078. }
  5079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  5081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  5082. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  5083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5084. }
  5085. //=================================== Power.Active.Import ==================================================
  5086. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  5087. {
  5088. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5089. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5090. {
  5091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5092. {
  5093. tempIndex = ((gun_index==2) ? 1: 0);
  5094. }
  5095. else
  5096. {
  5097. tempIndex = gun_index;
  5098. }
  5099. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5100. {
  5101. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5102. {
  5103. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5104. }
  5105. } // End for CHAdeMO_QUANTITY
  5106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5107. }
  5108. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5109. {
  5110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5111. {
  5112. tempIndex = ((gun_index==2) ? 1: 0);
  5113. }
  5114. else
  5115. {
  5116. tempIndex = gun_index;
  5117. }
  5118. for (int index = 0; index < CCS_QUANTITY; index++)
  5119. {
  5120. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5121. {
  5122. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5123. }
  5124. } // END for CCS_QUANTITY
  5125. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5126. }
  5127. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5128. {
  5129. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5130. {
  5131. tempIndex = ((gun_index==2) ? 1: 0);
  5132. }
  5133. else
  5134. {
  5135. tempIndex = gun_index;
  5136. }
  5137. for (int index = 0; index < GB_QUANTITY; index++)
  5138. {
  5139. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5140. {
  5141. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5142. }
  5143. }// END for GB_QUANTITY
  5144. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5145. }
  5146. else if(gunType[gun_index] == GUN_TYPE_DO)
  5147. {
  5148. tempIndex = gun_index;
  5149. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5150. {
  5151. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5152. {
  5153. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5154. }
  5155. }
  5156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5157. }
  5158. else
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5161. {
  5162. tempIndex = 2;
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < AC_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5173. }
  5174. } // END for AC_QUANTITY
  5175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5176. }
  5177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5181. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5182. }
  5183. //============================ Voltage L1 ====================================
  5184. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5185. {
  5186. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5187. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5188. {
  5189. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5190. {
  5191. tempIndex = ((gun_index==2) ? 1: 0);
  5192. }
  5193. else
  5194. {
  5195. tempIndex = gun_index;
  5196. }
  5197. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5198. {
  5199. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5200. {
  5201. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5202. }
  5203. } // END OF FOR CHAdeMO_QUANTITY
  5204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5205. }
  5206. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5207. {
  5208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5209. {
  5210. tempIndex = ((gun_index==2) ? 1: 0);
  5211. }
  5212. else
  5213. {
  5214. tempIndex = gun_index;
  5215. }
  5216. for (int index = 0; index < CCS_QUANTITY; index++)
  5217. {
  5218. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5219. {
  5220. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5221. }
  5222. } // END OF FOR CCS_QUANTITY
  5223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5224. }
  5225. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5226. {
  5227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5228. {
  5229. tempIndex = ((gun_index==2) ? 1: 0);
  5230. }
  5231. else
  5232. {
  5233. tempIndex = gun_index;
  5234. }
  5235. for (int index = 0; index < GB_QUANTITY; index++)
  5236. {
  5237. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5238. {
  5239. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5240. }
  5241. } // END OF FOR GB_QUANTITY
  5242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5243. }
  5244. else if(gunType[gun_index] == GUN_TYPE_DO)
  5245. {
  5246. tempIndex = gun_index;
  5247. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5248. {
  5249. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5250. {
  5251. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5252. }
  5253. }
  5254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5255. }
  5256. else
  5257. {
  5258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5259. {
  5260. tempIndex = 2;
  5261. }
  5262. else
  5263. {
  5264. tempIndex = gun_index;
  5265. }
  5266. for (int index = 0; index < AC_QUANTITY; index++)
  5267. {
  5268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5269. {
  5270. 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
  5271. }
  5272. } // END OF FOR AC_QUANTITY
  5273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5274. }
  5275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5276. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5280. }
  5281. //====================== End SoC ================================
  5282. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5283. {
  5284. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5285. 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))
  5286. {
  5287. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5288. {
  5289. tempIndex = ((gun_index==2) ? 1: 0);
  5290. }
  5291. else
  5292. {
  5293. tempIndex = gun_index;
  5294. }
  5295. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5296. {
  5297. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5298. {
  5299. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5300. {
  5301. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5302. }
  5303. }
  5304. }
  5305. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5306. {
  5307. for (int index = 0; index < CCS_QUANTITY; index++)
  5308. {
  5309. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5310. {
  5311. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5312. }
  5313. }
  5314. }
  5315. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5316. {
  5317. for (int index = 0; index < GB_QUANTITY; index++)
  5318. {
  5319. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5320. {
  5321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5322. }
  5323. }
  5324. }
  5325. else if(gunType[gun_index] == GUN_TYPE_DO)
  5326. {
  5327. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5328. {
  5329. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5330. {
  5331. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5332. }
  5333. }
  5334. }
  5335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5341. } // END FOR DC CASE
  5342. }
  5343. // ================================= Current.Import L2 ===============================================
  5344. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5345. {
  5346. // AC 3 phse L2 current
  5347. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5348. {
  5349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5350. {
  5351. tempIndex = 2;
  5352. }
  5353. else
  5354. {
  5355. tempIndex = gun_index;
  5356. }
  5357. for (int index = 0; index < AC_QUANTITY; index++)
  5358. {
  5359. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5360. {
  5361. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5362. }
  5363. }// End of for AC_QUANTITY
  5364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5365. }
  5366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5371. }
  5372. // ================================= Current.Import L3 ===============================================
  5373. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5374. {
  5375. // AC 3 phse L3 current
  5376. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5377. {
  5378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5379. {
  5380. tempIndex = 2;
  5381. }
  5382. else
  5383. {
  5384. tempIndex = gun_index;
  5385. }
  5386. for (int index = 0; index < AC_QUANTITY; index++)
  5387. {
  5388. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5389. {
  5390. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5391. }
  5392. }// End of for AC_QUANTITY
  5393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5394. }
  5395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5400. }
  5401. //============================ Voltage L2 ====================================
  5402. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5403. {
  5404. // AC 3 phse L2 voltage
  5405. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5406. {
  5407. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5408. {
  5409. tempIndex = 2;
  5410. }
  5411. else
  5412. {
  5413. tempIndex = gun_index;
  5414. }
  5415. for (int index = 0; index < AC_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5418. {
  5419. 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
  5420. }
  5421. } // END OF FOR AC_QUANTITY
  5422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5423. }
  5424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5429. }
  5430. //============================ Voltage L3 ====================================
  5431. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5432. {
  5433. // AC 3 phse L3 voltage
  5434. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5435. {
  5436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5437. {
  5438. tempIndex = 2;
  5439. }
  5440. else
  5441. {
  5442. tempIndex = gun_index;
  5443. }
  5444. for (int index = 0; index < AC_QUANTITY; index++)
  5445. {
  5446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5447. {
  5448. 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
  5449. }
  5450. } // END OF FOR AC_QUANTITY
  5451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5452. }
  5453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5458. }
  5459. //====================== Start SoC ================================
  5460. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5461. {
  5462. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5463. 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))
  5464. {
  5465. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5466. {
  5467. tempIndex = ((gun_index==2) ? 1: 0);
  5468. }
  5469. else
  5470. {
  5471. tempIndex = gun_index;
  5472. }
  5473. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5474. {
  5475. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5476. {
  5477. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5478. {
  5479. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5480. }
  5481. }
  5482. }
  5483. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5484. {
  5485. for (int index = 0; index < CCS_QUANTITY; index++)
  5486. {
  5487. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5488. {
  5489. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5490. }
  5491. }
  5492. }
  5493. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5494. {
  5495. for (int index = 0; index < GB_QUANTITY; index++)
  5496. {
  5497. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5498. {
  5499. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5500. }
  5501. }
  5502. }
  5503. else if(gunType[gun_index] == GUN_TYPE_DO)
  5504. {
  5505. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5506. {
  5507. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5508. {
  5509. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5510. }
  5511. }
  5512. }
  5513. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5514. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5519. } // END FOR DC CASE
  5520. }
  5521. //================================================ Message create ====================================================
  5522. json_object *StopTransaction = json_object_new_object();
  5523. json_object *transactionDatas = json_object_new_array();
  5524. json_object *sampledValues = json_object_new_array();
  5525. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  5526. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  5527. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  5528. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  5529. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  5530. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  5531. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  5532. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  5533. {
  5534. json_object *transactionData = json_object_new_object();
  5535. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5536. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5537. {
  5538. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5539. {
  5540. json_object *sampledValue = json_object_new_object();
  5541. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5542. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5543. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5544. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5545. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5546. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5547. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5548. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5549. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5550. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5551. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5552. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5553. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5554. json_object_array_add(sampledValues, sampledValue);
  5555. }
  5556. }
  5557. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5558. json_object_array_add(transactionDatas, transactionData);
  5559. }
  5560. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5561. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5562. ,MESSAGE_TYPE_CALL
  5563. ,guid
  5564. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5565. json_object_put(StopTransaction);
  5566. #if 1 // for TempStopTransaction
  5567. //Delete TempStopTransaction
  5568. if((access(TempStopTransaction,F_OK))!=-1)
  5569. {
  5570. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5571. }
  5572. #endif
  5573. #if 1
  5574. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5575. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5576. {
  5577. result = PASS;
  5578. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5579. }
  5580. #endif
  5581. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5582. OCPP_insert_transaction_msg(NO, queuedata);
  5583. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5584. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  5585. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  5586. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5587. {
  5588. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  5589. }
  5590. //for test
  5591. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5592. return result;
  5593. }
  5594. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5595. {
  5596. mtrace();
  5597. int result = FAIL;
  5598. char guid[37]={0};
  5599. char tempdata[65]={0};
  5600. int tempIndex = 0;
  5601. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5602. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5603. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5604. //set value
  5605. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5606. ShmOCPP16Data->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5607. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId :
  5608. -1);
  5609. random_uuid(guid);
  5610. //UTC Date time
  5611. struct timeval tmnow;
  5612. struct tm *tm;
  5613. char buf[28];//, usec_buf[6];
  5614. gettimeofday(&tmnow, NULL);
  5615. time_t t;
  5616. t = time(NULL);
  5617. /*UTC time and date*/
  5618. tm = gmtime(&t);
  5619. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5620. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5621. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5622. //********************************(1)Current.Import L1************************************************/
  5623. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5624. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5625. (dataType == ReadingContext_Trigger))
  5626. {
  5627. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5628. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5629. {
  5630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5631. {
  5632. tempIndex = ((gun_index==2) ? 1: 0);
  5633. }
  5634. else
  5635. {
  5636. tempIndex = gun_index;
  5637. }
  5638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5639. {
  5640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5641. {
  5642. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5643. }
  5644. }
  5645. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5646. }
  5647. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5648. {
  5649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5650. {
  5651. tempIndex = ((gun_index==2) ? 1: 0);
  5652. }
  5653. else
  5654. {
  5655. tempIndex = gun_index;
  5656. }
  5657. for (int index = 0; index < CCS_QUANTITY; index++)
  5658. {
  5659. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5660. {
  5661. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5662. }
  5663. }
  5664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5665. }
  5666. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5667. {
  5668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5669. {
  5670. tempIndex = ((gun_index==2) ? 1: 0);
  5671. }
  5672. else
  5673. {
  5674. tempIndex = gun_index;
  5675. }
  5676. for (int index = 0; index < GB_QUANTITY; index++)
  5677. {
  5678. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5679. {
  5680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5681. }
  5682. }
  5683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5684. }
  5685. else if(gunType[gun_index] == GUN_TYPE_DO)
  5686. {
  5687. tempIndex = gun_index;
  5688. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5689. {
  5690. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5691. {
  5692. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5693. }
  5694. }
  5695. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5696. }
  5697. else
  5698. {
  5699. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5700. {
  5701. tempIndex = 2;
  5702. }
  5703. else
  5704. {
  5705. tempIndex = gun_index;
  5706. }
  5707. for (int index = 0; index < AC_QUANTITY; index++)
  5708. {
  5709. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5710. {
  5711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5712. }
  5713. }
  5714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5715. }
  5716. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5717. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5718. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5719. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5720. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5721. }
  5722. //********************************(2)Energy.Active.Import.Register ************************************************/
  5723. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5724. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5725. (dataType == ReadingContext_Trigger))
  5726. {
  5727. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5728. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5729. {
  5730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5731. {
  5732. tempIndex = ((gun_index==2) ? 1: 0);
  5733. }
  5734. else
  5735. {
  5736. tempIndex = gun_index;
  5737. }
  5738. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5739. {
  5740. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5741. {
  5742. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5743. }
  5744. }
  5745. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5746. }
  5747. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5748. {
  5749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5750. {
  5751. tempIndex = ((gun_index==2) ? 1: 0);
  5752. }
  5753. else
  5754. {
  5755. tempIndex = gun_index;
  5756. }
  5757. for (int index = 0; index < CCS_QUANTITY; index++)
  5758. {
  5759. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5760. {
  5761. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5762. }
  5763. }
  5764. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5765. }
  5766. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5767. {
  5768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5769. {
  5770. tempIndex = ((gun_index==2) ? 1: 0);
  5771. }
  5772. else
  5773. {
  5774. tempIndex = gun_index;
  5775. }
  5776. for (int index = 0; index < GB_QUANTITY; index++)
  5777. {
  5778. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5779. {
  5780. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5781. }
  5782. }
  5783. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5784. }
  5785. else if(gunType[gun_index] == GUN_TYPE_DO)
  5786. {
  5787. tempIndex = gun_index;
  5788. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5789. {
  5790. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5791. {
  5792. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5793. }
  5794. }
  5795. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5796. }
  5797. else
  5798. {
  5799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5800. {
  5801. tempIndex = 2;
  5802. }
  5803. else
  5804. {
  5805. tempIndex = gun_index;
  5806. }
  5807. for (int index = 0; index < AC_QUANTITY; index++)
  5808. {
  5809. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5810. {
  5811. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5812. }
  5813. }
  5814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5815. }
  5816. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5818. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5819. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5821. }
  5822. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5823. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5824. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5825. (dataType == ReadingContext_Trigger))
  5826. {
  5827. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5828. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5829. {
  5830. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5831. {
  5832. tempIndex = ((gun_index==2) ? 1: 0);
  5833. }
  5834. else
  5835. {
  5836. tempIndex = gun_index;
  5837. }
  5838. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5839. {
  5840. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5841. {
  5842. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5843. }
  5844. } // END OF FOR CHAdeMO_QUANTITY
  5845. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5846. }
  5847. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5848. {
  5849. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5850. {
  5851. tempIndex = ((gun_index==2) ? 1: 0);
  5852. }
  5853. else
  5854. {
  5855. tempIndex = gun_index;
  5856. }
  5857. for (int index = 0; index < CCS_QUANTITY; index++)
  5858. {
  5859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5860. {
  5861. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5862. }
  5863. } // END OF CCS_QUANTITY
  5864. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5865. }
  5866. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5867. {
  5868. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5869. {
  5870. tempIndex = ((gun_index==2) ? 1: 0);
  5871. }
  5872. else
  5873. {
  5874. tempIndex = gun_index;
  5875. }
  5876. for (int index = 0; index < GB_QUANTITY; index++)
  5877. {
  5878. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5879. {
  5880. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5881. }
  5882. } // END OF GB_QUANTITY
  5883. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5884. }
  5885. else if(gunType[gun_index] == GUN_TYPE_DO)
  5886. {
  5887. tempIndex = gun_index;
  5888. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5889. {
  5890. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5891. {
  5892. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5893. }
  5894. }
  5895. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5896. }
  5897. else
  5898. {
  5899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5900. {
  5901. tempIndex = 2;
  5902. }
  5903. else
  5904. {
  5905. tempIndex = gun_index;
  5906. }
  5907. for (int index = 0; index < AC_QUANTITY; index++)
  5908. {
  5909. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5910. {
  5911. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5912. }
  5913. }
  5914. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5915. }
  5916. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5917. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5918. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5920. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5921. }
  5922. //********************************(4)Power.Active.Import************************************************/
  5923. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5924. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5925. (dataType == ReadingContext_Trigger))
  5926. {
  5927. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5928. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5929. {
  5930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5931. {
  5932. tempIndex = ((gun_index==2) ? 1: 0);
  5933. }
  5934. else
  5935. {
  5936. tempIndex = gun_index;
  5937. }
  5938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5939. {
  5940. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5941. {
  5942. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5943. }
  5944. } // END OF FOR
  5945. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5946. }
  5947. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5948. {
  5949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5950. {
  5951. tempIndex = ((gun_index==2) ? 1: 0);
  5952. }
  5953. else
  5954. {
  5955. tempIndex = gun_index;
  5956. }
  5957. for (int index = 0; index < CCS_QUANTITY; index++)
  5958. {
  5959. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5960. {
  5961. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5962. }
  5963. }
  5964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5965. }
  5966. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5967. {
  5968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5969. {
  5970. tempIndex = ((gun_index==2) ? 1: 0);
  5971. }
  5972. else
  5973. {
  5974. tempIndex = gun_index;
  5975. }
  5976. for (int index = 0; index < GB_QUANTITY; index++)
  5977. {
  5978. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5979. {
  5980. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5981. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5982. }
  5983. }
  5984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5985. }
  5986. else if(gunType[gun_index] == GUN_TYPE_DO)
  5987. {
  5988. tempIndex = gun_index;
  5989. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5990. {
  5991. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5992. {
  5993. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5994. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5995. }
  5996. }
  5997. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5998. }
  5999. else
  6000. {
  6001. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6002. {
  6003. tempIndex = 2;
  6004. }
  6005. else
  6006. {
  6007. tempIndex = gun_index;
  6008. }
  6009. for (int index = 0; index < AC_QUANTITY; index++)
  6010. {
  6011. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6012. {
  6013. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  6014. }
  6015. }
  6016. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  6017. }
  6018. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  6019. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  6020. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  6021. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  6022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  6023. }
  6024. //***********************************************(5)VOLTAGE L1******************************************************/
  6025. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6026. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6027. (dataType == ReadingContext_Trigger))
  6028. {
  6029. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6030. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6031. {
  6032. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6033. {
  6034. tempIndex = ((gun_index==2) ? 1: 0);
  6035. }
  6036. else
  6037. {
  6038. tempIndex = gun_index;
  6039. }
  6040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  6045. }
  6046. }
  6047. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6048. }
  6049. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6050. {
  6051. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6052. {
  6053. tempIndex = ((gun_index==2) ? 1: 0);
  6054. }
  6055. else
  6056. {
  6057. tempIndex = gun_index;
  6058. }
  6059. for (int index = 0; index < CCS_QUANTITY; index++)
  6060. {
  6061. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6062. {
  6063. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  6064. }
  6065. }
  6066. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6067. }
  6068. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6069. {
  6070. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6071. {
  6072. tempIndex = ((gun_index==2) ? 1: 0);
  6073. }
  6074. else
  6075. {
  6076. tempIndex = gun_index;
  6077. }
  6078. for (int index = 0; index < GB_QUANTITY; index++)
  6079. {
  6080. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6081. {
  6082. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  6083. }
  6084. }
  6085. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6086. }
  6087. else if(gunType[gun_index] == GUN_TYPE_DO)
  6088. {
  6089. tempIndex = gun_index;
  6090. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6091. {
  6092. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6093. {
  6094. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  6095. }
  6096. }
  6097. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  6098. }
  6099. else
  6100. {
  6101. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6102. {
  6103. tempIndex = 2;
  6104. }
  6105. else
  6106. {
  6107. tempIndex = gun_index;
  6108. }
  6109. for (int index = 0; index < AC_QUANTITY; index++)
  6110. {
  6111. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6112. {
  6113. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  6114. }
  6115. }
  6116. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  6117. }
  6118. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  6119. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  6120. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  6121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  6122. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6123. }
  6124. //***********************************************(6)SOC******************************************************/
  6125. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6126. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  6127. (dataType == ReadingContext_Trigger))
  6128. {
  6129. 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))
  6130. {
  6131. //idx_sample=5;
  6132. //sampledValue = NULL;
  6133. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6134. {
  6135. tempIndex = ((gun_index==2) ? 1: 0);
  6136. }
  6137. else
  6138. {
  6139. tempIndex = gun_index;
  6140. }
  6141. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6142. {
  6143. //tempIndex = ((gun_index==2) ? 1: 0);
  6144. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6145. {
  6146. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6147. {
  6148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6149. }
  6150. }
  6151. }
  6152. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6153. {
  6154. //tempIndex = ((gun_index==2) ? 1: 0);
  6155. for (int index = 0; index < CCS_QUANTITY; index++)
  6156. {
  6157. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6158. {
  6159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6160. }
  6161. }
  6162. }
  6163. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6164. {
  6165. //tempIndex = ((gun_index==2) ? 1: 0);
  6166. for (int index = 0; index < GB_QUANTITY; index++)
  6167. {
  6168. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6169. {
  6170. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6171. }
  6172. }
  6173. }
  6174. else if(gunType[gun_index] == GUN_TYPE_DO)
  6175. {
  6176. //tempIndex = ((gun_index==2) ? 1: 0);
  6177. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6178. {
  6179. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6180. {
  6181. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6182. }
  6183. }
  6184. }
  6185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6190. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6191. }
  6192. }
  6193. //********************************(7)Current.Import L2************************************************/
  6194. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6195. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6196. (dataType == ReadingContext_Trigger))
  6197. {
  6198. // Only for AC 3 phase
  6199. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6200. {
  6201. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6202. {
  6203. tempIndex = 2;
  6204. }
  6205. else
  6206. {
  6207. tempIndex = gun_index;
  6208. }
  6209. for (int index = 0; index < AC_QUANTITY; index++)
  6210. {
  6211. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6212. {
  6213. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6214. }
  6215. }
  6216. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6217. }
  6218. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6223. }
  6224. //********************************(8)Current.Import L3************************************************/
  6225. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6226. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6227. (dataType == ReadingContext_Trigger))
  6228. {
  6229. // Only for AC 3 phase
  6230. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6231. {
  6232. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6233. {
  6234. tempIndex = 2;
  6235. }
  6236. else
  6237. {
  6238. tempIndex = gun_index;
  6239. }
  6240. for (int index = 0; index < AC_QUANTITY; index++)
  6241. {
  6242. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6243. {
  6244. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6245. }
  6246. }
  6247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6248. }
  6249. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6252. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6253. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6254. }
  6255. //***********************************************(9)VOLTAGE L2******************************************************/
  6256. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6257. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6258. (dataType == ReadingContext_Trigger))
  6259. {
  6260. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6261. {
  6262. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6263. {
  6264. tempIndex = 2;
  6265. }
  6266. else
  6267. {
  6268. tempIndex = gun_index;
  6269. }
  6270. for (int index = 0; index < AC_QUANTITY; index++)
  6271. {
  6272. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6273. {
  6274. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6275. }
  6276. }
  6277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6278. }
  6279. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6281. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6283. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6284. }
  6285. //***********************************************(10)VOLTAGE L3******************************************************/
  6286. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6287. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6288. (dataType == ReadingContext_Trigger))
  6289. {
  6290. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6291. {
  6292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6293. {
  6294. tempIndex = 2;
  6295. }
  6296. else
  6297. {
  6298. tempIndex = gun_index;
  6299. }
  6300. for (int index = 0; index < AC_QUANTITY; index++)
  6301. {
  6302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6303. {
  6304. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6305. }
  6306. }
  6307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6308. }
  6309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6314. }
  6315. //***********************************************(11)Current.Offered******************************************************/
  6316. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6317. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6318. (dataType == ReadingContext_Trigger))
  6319. {
  6320. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6321. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6322. {
  6323. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6324. {
  6325. tempIndex = ((gun_index==2) ? 1: 0);
  6326. }
  6327. else
  6328. {
  6329. tempIndex = gun_index;
  6330. }
  6331. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6332. {
  6333. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6334. {
  6335. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6336. }
  6337. } // END OF FOR CHAdeMO_QUANTITY
  6338. }
  6339. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6340. {
  6341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6342. {
  6343. tempIndex = ((gun_index==2) ? 1: 0);
  6344. }
  6345. else
  6346. {
  6347. tempIndex = gun_index;
  6348. }
  6349. for (int index = 0; index < CCS_QUANTITY; index++)
  6350. {
  6351. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6352. {
  6353. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6354. }
  6355. } // END OF CCS_QUANTITY
  6356. }
  6357. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6358. {
  6359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6360. {
  6361. tempIndex = ((gun_index==2) ? 1: 0);
  6362. }
  6363. else
  6364. {
  6365. tempIndex = gun_index;
  6366. }
  6367. for (int index = 0; index < GB_QUANTITY; index++)
  6368. {
  6369. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6370. {
  6371. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6372. }
  6373. } // END OF GB_QUANTITY
  6374. }
  6375. else if(gunType[gun_index] == GUN_TYPE_DO)
  6376. {
  6377. tempIndex = gun_index;
  6378. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6379. {
  6380. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6381. {
  6382. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6383. }
  6384. }
  6385. }
  6386. else
  6387. {
  6388. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6389. {
  6390. tempIndex = 2;
  6391. }
  6392. else
  6393. {
  6394. tempIndex = gun_index;
  6395. }
  6396. for (int index = 0; index < AC_QUANTITY; index++)
  6397. {
  6398. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6399. {
  6400. uint16_t currentOffer;
  6401. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6402. {
  6403. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6404. }
  6405. else
  6406. {
  6407. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6408. }
  6409. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6410. }
  6411. }
  6412. }
  6413. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6414. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6415. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6418. }
  6419. //***********************************************(12)Power.Offered******************************************************/
  6420. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6421. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6422. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6423. {
  6424. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6425. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6426. {
  6427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6428. {
  6429. tempIndex = ((gun_index==2) ? 1: 0);
  6430. }
  6431. else
  6432. {
  6433. tempIndex = gun_index;
  6434. }
  6435. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6436. {
  6437. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6438. {
  6439. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*10));
  6440. }
  6441. } // END OF FOR CHAdeMO_QUANTITY
  6442. }
  6443. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6444. {
  6445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6446. {
  6447. tempIndex = ((gun_index==2) ? 1: 0);
  6448. }
  6449. else
  6450. {
  6451. tempIndex = gun_index;
  6452. }
  6453. for (int index = 0; index < CCS_QUANTITY; index++)
  6454. {
  6455. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6456. {
  6457. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*10));
  6458. }
  6459. } // END OF CCS_QUANTITY
  6460. }
  6461. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6462. {
  6463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6464. {
  6465. tempIndex = ((gun_index==2) ? 1: 0);
  6466. }
  6467. else
  6468. {
  6469. tempIndex = gun_index;
  6470. }
  6471. for (int index = 0; index < GB_QUANTITY; index++)
  6472. {
  6473. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6474. {
  6475. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*10));
  6476. }
  6477. } // END OF GB_QUANTITY
  6478. }
  6479. else if(gunType[gun_index] == GUN_TYPE_DO)
  6480. {
  6481. tempIndex = gun_index;
  6482. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6483. {
  6484. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6485. {
  6486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*10));
  6487. }
  6488. }
  6489. }
  6490. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6491. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6492. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Power_Offered]);
  6493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6494. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6495. }
  6496. // Message create ====================================================================================================
  6497. if(TRUE)
  6498. {
  6499. json_object *MeterValueReq = json_object_new_object();
  6500. json_object *MeterValues = json_object_new_array();
  6501. json_object *sampledValues = json_object_new_array();
  6502. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  6503. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  6504. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  6505. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  6506. {
  6507. json_object *MeterValue = json_object_new_object();
  6508. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6509. {
  6510. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6511. {
  6512. json_object *sampledValue = json_object_new_object();
  6513. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6514. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6515. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6516. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6517. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6518. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6519. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6520. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6521. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6522. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6523. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6524. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6525. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6526. json_object_array_add(sampledValues, sampledValue);
  6527. }
  6528. }
  6529. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6530. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6531. json_object_array_add(MeterValues, MeterValue);
  6532. }
  6533. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6534. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6535. ,gun_index + 1
  6536. ,MESSAGE_TYPE_CALL
  6537. ,guid
  6538. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6539. json_object_put(MeterValueReq);
  6540. }
  6541. // Put request guid to hash map
  6542. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6543. 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*/)
  6544. {
  6545. result = PASS;
  6546. //DEBUG_INFO("MeterValues mapitem pass\n");
  6547. }
  6548. if((dataType != ReadingContext_Trigger) &&
  6549. (dataType != ReadingContext_Sample_Clock) &&
  6550. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  6551. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6552. else
  6553. {
  6554. if(FirstHeartBeat)
  6555. LWS_Send(queuedata +2);
  6556. }
  6557. return result;
  6558. }
  6559. int sendLogStatusNotificationRequest(char *status)
  6560. {
  6561. mtrace();
  6562. int result = PASS;
  6563. char message[4096]={0};
  6564. char guid[37]={0};
  6565. char tempdata[128]={0};
  6566. json_object *LogStatusNotification = json_object_new_object();
  6567. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6568. ShmOCPP16Data->LogStatusNotification.requestId = ShmOCPP16Data->GetLog.requestId;
  6569. sprintf((char *)ShmOCPP16Data->LogStatusNotification.status,"%s",(const char *)status);
  6570. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->LogStatusNotification.status));
  6571. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->LogStatusNotification.requestId));
  6572. random_uuid(guid);
  6573. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6574. json_object_put(LogStatusNotification);
  6575. LWS_Send(message);
  6576. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6577. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6578. {
  6579. result = PASS;
  6580. }
  6581. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 0;
  6582. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 0;
  6583. return result;
  6584. }
  6585. int sendSecurityEventNotificationRequest()
  6586. {
  6587. mtrace();
  6588. int result = PASS;
  6589. char message[4096]={0};
  6590. char guid[37]={0};
  6591. char tempdata[128]={0};
  6592. json_object *SecurityEventNotification = json_object_new_object();
  6593. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6594. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.type));
  6595. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.timestamp));
  6596. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16Data->SecurityEventNotification.techInfo));
  6597. random_uuid(guid);
  6598. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6599. json_object_put(SecurityEventNotification);
  6600. LWS_Send(message);
  6601. sprintf(tempdata, "SecurityEventNotification,0");
  6602. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6603. {
  6604. result = PASS;
  6605. }
  6606. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationReq = 0;
  6607. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 0;
  6608. return result;
  6609. }
  6610. int sendSignCertificateRequest()
  6611. {
  6612. mtrace();
  6613. int result = PASS;
  6614. char message[4096]={0};
  6615. char guid[37]={0};
  6616. char tempdata[128]={0};
  6617. json_object *SignCertificate = json_object_new_object();
  6618. DEBUG_INFO("sendSignCertificateRequest...\n");
  6619. // Read csr file content
  6620. memset(ShmOCPP16Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16Data->SignCertificate.csr));
  6621. FILE *fp=fopen("/Storage/OCPP/certCP.csr","r");
  6622. char *line = NULL;
  6623. size_t len = 0;
  6624. while(getline(&line, &len, fp) != -1)
  6625. {
  6626. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6627. {
  6628. memcpy(&ShmOCPP16Data->SignCertificate.csr[strlen((char*)ShmOCPP16Data->SignCertificate.csr)], line, (strlen(line)-1));
  6629. }
  6630. }
  6631. fclose(fp);
  6632. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16Data->SignCertificate.csr));
  6633. random_uuid(guid);
  6634. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6635. json_object_put(SignCertificate);
  6636. LWS_Send(message);
  6637. sprintf(tempdata, "SignCertificate,0");
  6638. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6639. {
  6640. result = PASS;
  6641. }
  6642. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 0;
  6643. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 0;
  6644. return result;
  6645. }
  6646. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6647. {
  6648. mtrace();
  6649. int result = PASS;
  6650. char message[110]={0};
  6651. char guid[37]={0};
  6652. char tempdata[65]={0};
  6653. json_object *FirmwareStatusNotification = json_object_new_object();
  6654. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6655. sprintf((char *)ShmOCPP16Data->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6656. ShmOCPP16Data->SignedFirmwareStatusNotification.requestId = ShmOCPP16Data->SignedUpdateFirmware.requestId;
  6657. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16Data->SignedFirmwareStatusNotification.status));
  6658. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16Data->SignedFirmwareStatusNotification.requestId));
  6659. random_uuid(guid);
  6660. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6661. json_object_put(FirmwareStatusNotification);
  6662. LWS_Send(message);
  6663. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6664. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6665. {
  6666. result = PASS;
  6667. }
  6668. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6669. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6670. return result;
  6671. }
  6672. //==========================================
  6673. // send confirm routine
  6674. //==========================================
  6675. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6676. {
  6677. mtrace();
  6678. int result = FAIL;
  6679. char message[100]={0};
  6680. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6681. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6682. LWS_Send(message);
  6683. result = TRUE;
  6684. return result;
  6685. }
  6686. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6687. {
  6688. mtrace();
  6689. int result = FAIL;
  6690. char message[100]={0};
  6691. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6692. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6693. LWS_Send(message);
  6694. result = TRUE;
  6695. return result;
  6696. }
  6697. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6698. {
  6699. mtrace();
  6700. int result = FAIL;
  6701. char message[100]={0};
  6702. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6703. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6704. LWS_Send(message);
  6705. result = TRUE;
  6706. return result;
  6707. }
  6708. int sendClearCacheConfirmation(char *uuid,char *payload)
  6709. {
  6710. mtrace();
  6711. int result = FAIL;
  6712. char message[500]={0};
  6713. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6714. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6715. LWS_Send(message);
  6716. return result;
  6717. }
  6718. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6719. {
  6720. mtrace();
  6721. int result = FAIL;
  6722. char message[500]={0};
  6723. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6724. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6725. LWS_Send(message);
  6726. return result;
  6727. }
  6728. int sendDataTransferConfirmation(char *uuid,char *payload)
  6729. {
  6730. mtrace();
  6731. char statusStr[20]={0};
  6732. char dataStr[10]={0};
  6733. char sstr[20]={0};
  6734. int c = 0;
  6735. char *loc;
  6736. int result = FAIL;
  6737. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6738. /**********************status**************************/
  6739. loc = strstr(payload, "status");
  6740. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6741. c = 0;
  6742. while (loc[3+strlen("status")+c] != '\"')
  6743. {
  6744. sstr[c] = loc[3+strlen("status")+c];
  6745. c++;
  6746. }
  6747. sstr[c] = '\0';
  6748. strcpy(statusStr, sstr);
  6749. /**********************data**************************/
  6750. loc = strstr(payload, "data");
  6751. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6752. c = 0;
  6753. while (loc[3+strlen("data")+c] != '\"')
  6754. {
  6755. sstr[c] = loc[3+strlen("data")+c];
  6756. c++;
  6757. }
  6758. sstr[c] = '\0';
  6759. strcpy(dataStr, sstr);
  6760. return result;
  6761. }
  6762. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6763. {
  6764. mtrace();
  6765. int result = FAIL;
  6766. char message[1000]={0};
  6767. int CompositeScheduleIndex = 0;
  6768. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6769. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6770. if(nPeriod == 0)
  6771. {
  6772. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6773. {
  6774. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6775. ,MESSAGE_TYPE_CALLRESULT
  6776. ,uuid
  6777. ,payload
  6778. ,connectorIdInt);
  6779. }
  6780. else
  6781. {
  6782. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6783. ,MESSAGE_TYPE_CALLRESULT
  6784. ,uuid
  6785. ,payload
  6786. ,connectorIdInt
  6787. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6788. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6789. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6790. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6791. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6792. }
  6793. }
  6794. else
  6795. {
  6796. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6797. ,MESSAGE_TYPE_CALLRESULT
  6798. ,uuid
  6799. ,payload
  6800. ,connectorIdInt
  6801. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6802. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6803. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6804. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6805. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6806. {
  6807. if (idx_sample == 0)
  6808. {
  6809. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6810. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6811. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6812. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6813. }
  6814. else
  6815. {
  6816. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6817. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6818. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6819. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6820. }
  6821. }
  6822. sprintf(message + strlen(message), "]}}]");
  6823. }
  6824. LWS_Send(message);
  6825. result = TRUE;
  6826. return result;
  6827. }
  6828. int sendGetConfigurationConfirmation(char *uuid)
  6829. {
  6830. mtrace();
  6831. int result = FAIL;
  6832. int MaxKeySupported = 0;
  6833. int sentConfigurationNumber= 0;
  6834. int sentunConfigurationNumber= 0;
  6835. char message[4000]={0};
  6836. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6837. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6838. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6839. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6840. ,MESSAGE_TYPE_CALLRESULT
  6841. ,uuid );
  6842. //configuration key
  6843. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6844. {
  6845. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6846. {
  6847. if (sentConfigurationNumber == 0)
  6848. {
  6849. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6850. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6851. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6852. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6853. }
  6854. else
  6855. {
  6856. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6857. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6858. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6859. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6860. }
  6861. sentConfigurationNumber = sentConfigurationNumber + 1;
  6862. }
  6863. }
  6864. sprintf(message + strlen(message), "]");
  6865. if(UnknownKeynum != 0)
  6866. {
  6867. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6868. //unkown key
  6869. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6870. {
  6871. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6872. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6873. if(sentunConfigurationNumber == 0)
  6874. {
  6875. sprintf(message + strlen(message), "\"%s\""
  6876. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6877. }
  6878. else
  6879. {
  6880. sprintf(message + strlen(message), ",\"%s\""
  6881. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6882. }
  6883. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6884. }
  6885. sprintf(message + strlen(message), "]");
  6886. }
  6887. sprintf(message + strlen(message), "}]");
  6888. LWS_Send(message);
  6889. return result;
  6890. }
  6891. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6892. {
  6893. mtrace();
  6894. int result = FAIL;
  6895. char message[400]={0};
  6896. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6897. if(strcmp(payload,"")==0)
  6898. {
  6899. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6900. }
  6901. else
  6902. {
  6903. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6904. }
  6905. LWS_Send(message);
  6906. result = TRUE;
  6907. return result;
  6908. }
  6909. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6910. {
  6911. mtrace();
  6912. int result = FAIL;
  6913. char message[80]={0};
  6914. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6915. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  6916. LWS_Send(message);
  6917. result = TRUE;
  6918. return result;
  6919. }
  6920. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6921. {
  6922. mtrace();
  6923. int result = FAIL;
  6924. char message[80]={0};
  6925. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6926. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6927. LWS_Send(message);
  6928. result = TRUE;
  6929. return result;
  6930. }
  6931. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6932. {
  6933. mtrace();
  6934. int result = FAIL;
  6935. char message[80]={0};
  6936. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6937. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6938. LWS_Send(message);
  6939. result = TRUE;
  6940. return result;
  6941. }
  6942. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6943. {
  6944. mtrace();
  6945. int result = FAIL;
  6946. char message[80]={0};
  6947. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6948. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6949. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6950. LWS_Send(message);
  6951. result = TRUE;
  6952. return result;
  6953. }
  6954. int sendResetConfirmation(char *uuid,char *payload)
  6955. {
  6956. mtrace();
  6957. int result = FAIL;
  6958. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6959. char message[80]={0};
  6960. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  6961. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6962. LWS_Send(message);
  6963. result = TRUE;
  6964. return result;
  6965. }
  6966. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6967. {
  6968. mtrace();
  6969. int result = FAIL;
  6970. char message[500]={0};
  6971. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6972. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6973. LWS_Send(message);
  6974. result = TRUE;
  6975. return result;
  6976. }
  6977. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6978. {
  6979. mtrace();
  6980. int result = FAIL;
  6981. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6982. char message[80]={0};
  6983. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6984. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6985. LWS_Send(message);
  6986. result = TRUE;
  6987. return result;
  6988. }
  6989. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6990. {
  6991. mtrace();
  6992. int result = FAIL;
  6993. char message[80]={0};
  6994. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6995. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6996. LWS_Send(message);
  6997. result = TRUE;
  6998. return result;
  6999. }
  7000. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  7001. {
  7002. mtrace();
  7003. int result = FAIL;
  7004. char message[80]={0};
  7005. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7006. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  7007. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  7008. LWS_Send(message);
  7009. result = TRUE;
  7010. return result;
  7011. }
  7012. int sendUpdateFirmwareConfirmation(char *uuid)
  7013. {
  7014. mtrace();
  7015. int result = FAIL;
  7016. char message[60]={0};
  7017. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  7018. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  7019. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  7020. LWS_Send(message);
  7021. result = TRUE;
  7022. return result;
  7023. }
  7024. int sendCertificateSignedConfirmation(char *uuid)
  7025. {
  7026. mtrace();
  7027. int result = PASS;
  7028. char message[4096]={0};
  7029. json_object *CertificateSigned = json_object_new_object();
  7030. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  7031. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16Data->CertificateSigned.Response_status));
  7032. sprintf(message,"[%d,\"%s\",%s]"
  7033. ,MESSAGE_TYPE_CALLRESULT
  7034. ,uuid
  7035. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  7036. json_object_put(CertificateSigned);
  7037. LWS_Send(message);
  7038. return result;
  7039. }
  7040. int sendDeleteCertificateConfirmation(char *uuid)
  7041. {
  7042. mtrace();
  7043. int result = PASS;
  7044. char message[4096]={0};
  7045. json_object *DeleteCertificate = json_object_new_object();
  7046. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  7047. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->DeleteCertificate.Response_status));
  7048. sprintf(message,"[%d,\"%s\",%s]"
  7049. ,MESSAGE_TYPE_CALLRESULT
  7050. ,uuid
  7051. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  7052. json_object_put(DeleteCertificate);
  7053. LWS_Send(message);
  7054. return result;
  7055. }
  7056. int sendExtendedTriggerMessageConfirmation(char *uuid)
  7057. {
  7058. mtrace();
  7059. int result = PASS;
  7060. char message[4096]={0};
  7061. json_object *ExtendedTriggerMessage = json_object_new_object();
  7062. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  7063. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status));
  7064. sprintf(message,"[%d,\"%s\",%s]"
  7065. ,MESSAGE_TYPE_CALLRESULT
  7066. ,uuid
  7067. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  7068. json_object_put(ExtendedTriggerMessage);
  7069. LWS_Send(message);
  7070. return result;
  7071. }
  7072. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  7073. {
  7074. mtrace();
  7075. int result = PASS;
  7076. char message[4096]={0};
  7077. json_object *GetInstalledCertificateIds = json_object_new_object();
  7078. json_object *certificateHashDataDatas = json_object_new_array();
  7079. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  7080. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status));
  7081. if(strlen((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  7082. {
  7083. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  7084. {
  7085. json_object *certificateHashData = json_object_new_object();
  7086. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  7087. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  7088. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  7089. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  7090. json_object_array_add(certificateHashDataDatas, certificateHashData);
  7091. }
  7092. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  7093. }
  7094. else
  7095. {
  7096. json_object_put(certificateHashDataDatas);
  7097. }
  7098. sprintf(message,"[%d,\"%s\",%s]"
  7099. ,MESSAGE_TYPE_CALLRESULT
  7100. ,uuid
  7101. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  7102. json_object_put(GetInstalledCertificateIds);
  7103. LWS_Send(message);
  7104. return result;
  7105. }
  7106. int sendGetLogConfirmation(char *uuid)
  7107. {
  7108. mtrace();
  7109. int result = PASS;
  7110. char message[4096]={0};
  7111. json_object *GetLog = json_object_new_object();
  7112. DEBUG_INFO("sendGetLogConfirmation...\n");
  7113. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_status));
  7114. if(strlen((char*)ShmOCPP16Data->GetLog.Response_filename) > 0)
  7115. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16Data->GetLog.Response_filename));
  7116. sprintf(message,"[%d,\"%s\",%s]"
  7117. ,MESSAGE_TYPE_CALLRESULT
  7118. ,uuid
  7119. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  7120. json_object_put(GetLog);
  7121. LWS_Send(message);
  7122. return result;
  7123. }
  7124. int sendInstallCertificateConfirmation(char *uuid)
  7125. {
  7126. mtrace();
  7127. int result = PASS;
  7128. char message[4096]={0};
  7129. json_object *InstallCertificate = json_object_new_object();
  7130. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  7131. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16Data->InstallCertificate.Response_status));
  7132. sprintf(message,"[%d,\"%s\",%s]"
  7133. ,MESSAGE_TYPE_CALLRESULT
  7134. ,uuid
  7135. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  7136. json_object_put(InstallCertificate);
  7137. LWS_Send(message);
  7138. return result;
  7139. }
  7140. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7141. {
  7142. mtrace();
  7143. int result = PASS;
  7144. char message[4096]={0};
  7145. json_object *SignedUpdateFirmware = json_object_new_object();
  7146. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7147. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status));
  7148. sprintf(message,"[%d,\"%s\",%s]"
  7149. ,MESSAGE_TYPE_CALLRESULT
  7150. ,uuid
  7151. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7152. json_object_put(SignedUpdateFirmware);
  7153. LWS_Send(message);
  7154. return result;
  7155. }
  7156. int sendUnknownConfirmation(char *uuid)
  7157. {
  7158. mtrace();
  7159. int result = PASS;
  7160. char message[256]={0};
  7161. DEBUG_INFO("sendUnknownConfirmation...\n");
  7162. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7163. LWS_Send(message);
  7164. return result;
  7165. }
  7166. //==========================================
  7167. // Handle server request routine Start
  7168. //==========================================
  7169. int handleCancelReservationRequest(char *uuid, char *payload)
  7170. {
  7171. mtrace();
  7172. int result = FAIL;
  7173. int gunNO = 0;
  7174. int reservationIdInt = -1;
  7175. char comfirmstr[20];
  7176. DEBUG_INFO("handleCancelReservationRequest...\n");
  7177. json_object *CancelReservation;
  7178. CancelReservation = json_tokener_parse(payload);
  7179. if(!is_error(CancelReservation))
  7180. {
  7181. // Required data
  7182. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7183. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7184. }
  7185. json_object_put(CancelReservation);
  7186. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7187. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7188. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7189. if(reservationIdInt != -1)
  7190. {
  7191. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7192. //check Transaction active
  7193. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7194. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7195. {
  7196. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7197. {
  7198. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7199. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7200. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7201. {
  7202. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7203. }
  7204. else
  7205. {
  7206. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7207. }
  7208. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7209. goto end;
  7210. }
  7211. }
  7212. for (int index = 0; index < CCS_QUANTITY; index++)
  7213. {
  7214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7215. {
  7216. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7217. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7218. if(gunType[2] == GUN_TYPE_CCS)
  7219. {
  7220. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7221. }
  7222. else
  7223. {
  7224. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7225. }
  7226. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7227. goto end;
  7228. }
  7229. }
  7230. for (int index = 0; index < GB_QUANTITY; index++)
  7231. {
  7232. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7233. {
  7234. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7235. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7236. if(gunType[2] == GUN_TYPE_GBT)
  7237. {
  7238. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7239. }
  7240. else
  7241. {
  7242. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7243. }
  7244. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7245. goto end;
  7246. }
  7247. }
  7248. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7249. {
  7250. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7251. {
  7252. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7253. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7254. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7255. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7256. goto end;
  7257. }
  7258. }
  7259. for (int index = 0; index < AC_QUANTITY; index++)
  7260. {
  7261. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7262. {
  7263. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7264. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7266. {
  7267. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7268. }
  7269. else
  7270. {
  7271. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7272. }
  7273. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7274. goto end;
  7275. }
  7276. }
  7277. }
  7278. //The reservationId does NOT match the reservationId
  7279. sendCancelReservationConfirmation(uuid, comfirmstr);
  7280. end:
  7281. // Fill in ocpp packet uuid
  7282. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  7283. return result;
  7284. }
  7285. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7286. {
  7287. mtrace();
  7288. int result = FAIL;
  7289. int gunIndex = 0;
  7290. char typeStr[16]={0};
  7291. char comfirmstr[20];
  7292. int specificId = FALSE;
  7293. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7294. json_object *ChangeAvailability;
  7295. ChangeAvailability = json_tokener_parse(payload);
  7296. if(!is_error(ChangeAvailability))
  7297. {
  7298. // Required data
  7299. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7300. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7301. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7302. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7303. }
  7304. json_object_put(ChangeAvailability);
  7305. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7306. {
  7307. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7308. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7309. }
  7310. else if(gunIndex == 0)
  7311. {
  7312. for(int i=0; i < gunTotalNumber; i++)
  7313. {
  7314. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  7315. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  7316. }
  7317. }
  7318. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7320. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7321. {
  7322. specificId = TRUE;
  7323. }
  7324. if(specificId == FALSE)
  7325. goto end;
  7326. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7327. {
  7328. //----------------------gunIndex is 0 ------------------------------------------------//
  7329. if(gunIndex == 0)
  7330. {
  7331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7332. {
  7333. for(int i=0; i < gunTotalNumber; i++)
  7334. {
  7335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7336. {
  7337. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7338. {
  7339. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7340. {
  7341. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7342. goto end;
  7343. }
  7344. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7345. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7346. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7347. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7348. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7349. {
  7350. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7351. goto end;
  7352. }
  7353. }
  7354. }//END FOR CHAdeMO_QUANTITY
  7355. for (int index = 0; index < CCS_QUANTITY; index++)
  7356. {
  7357. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7358. {
  7359. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7360. {
  7361. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7362. goto end;
  7363. }
  7364. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7365. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7366. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7367. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7368. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7369. {
  7370. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7371. goto end;
  7372. }
  7373. }
  7374. }//END FOR CCS_QUANTITY
  7375. for (int index = 0; index < GB_QUANTITY; index++)
  7376. {
  7377. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7378. {
  7379. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7380. {
  7381. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7382. goto end;
  7383. }
  7384. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7385. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7386. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7387. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7388. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7389. {
  7390. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7391. goto end;
  7392. }
  7393. }
  7394. }// END FOR GB_QUANTITY
  7395. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7396. {
  7397. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7398. {
  7399. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7400. {
  7401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7402. goto end;
  7403. }
  7404. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7405. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7406. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7407. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7408. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7409. {
  7410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7411. goto end;
  7412. }
  7413. }
  7414. }// END FOR GENERAL_GUN_QUANTITY
  7415. for (int index = 0; index < AC_QUANTITY; index++)
  7416. {
  7417. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7418. {
  7419. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7420. {
  7421. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7422. goto end;
  7423. }
  7424. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7425. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7426. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7427. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7428. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7429. {
  7430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7431. goto end;
  7432. }
  7433. }
  7434. }//END FOR AC_QUANTITY
  7435. }// END FOR gunTotalNumber
  7436. }
  7437. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7438. {
  7439. for(int i=0; i < gunTotalNumber; i++)
  7440. {
  7441. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7442. {
  7443. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7444. goto end;
  7445. }
  7446. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7447. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7448. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7449. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7450. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7451. {
  7452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7453. goto end;
  7454. }
  7455. }
  7456. }
  7457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7458. goto end;
  7459. }
  7460. //----------------------gunIndex is not 0 ------------------------------------------------//
  7461. //check Transaction active
  7462. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7463. {
  7464. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7465. {
  7466. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7467. {
  7468. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7469. goto end;
  7470. }
  7471. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7472. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7473. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7474. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7475. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7476. {
  7477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7478. goto end;
  7479. }
  7480. else
  7481. {
  7482. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7483. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7484. goto end;
  7485. }
  7486. }
  7487. }//END FOR CHAdeMO_QUANTITY
  7488. for (int index = 0; index < CCS_QUANTITY; index++)
  7489. {
  7490. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7491. {
  7492. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7493. {
  7494. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7495. goto end;
  7496. }
  7497. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7498. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7499. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7500. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7501. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7502. {
  7503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7504. goto end;
  7505. }
  7506. else
  7507. {
  7508. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7509. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7510. goto end;
  7511. }
  7512. }
  7513. }//END FOR CCS_QUANTITY
  7514. for (int index = 0; index < GB_QUANTITY; index++)
  7515. {
  7516. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7517. {
  7518. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7519. {
  7520. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7521. goto end;
  7522. }
  7523. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7524. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7525. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7526. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7527. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7528. {
  7529. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7530. goto end;
  7531. }
  7532. else
  7533. {
  7534. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7535. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7536. goto end;
  7537. }
  7538. }
  7539. }// END FOR GB_QUANTITY
  7540. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7541. {
  7542. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7543. {
  7544. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7545. {
  7546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7547. goto end;
  7548. }
  7549. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7550. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7551. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7552. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7553. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7554. {
  7555. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7556. goto end;
  7557. }
  7558. else
  7559. {
  7560. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7561. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7562. goto end;
  7563. }
  7564. }
  7565. }// END FOR GENERAL_GUN_QUANTITY
  7566. for (int index = 0; index < AC_QUANTITY; index++)
  7567. {
  7568. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7569. {
  7570. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7571. {
  7572. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7573. goto end;
  7574. }
  7575. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7576. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7577. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7578. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7579. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7580. {
  7581. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7582. goto end;
  7583. }
  7584. else
  7585. {
  7586. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7587. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7588. goto end;
  7589. }
  7590. }
  7591. }//END FOR AC_QUANTITY
  7592. }//END FOR AvailabilityTypeStr[Inoperative]
  7593. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7594. {
  7595. //----------------------gunIndex is 0 ------------------------------------------------//
  7596. if(gunIndex == 0)
  7597. {
  7598. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7599. {
  7600. for(int i=0; i < gunTotalNumber; i++)
  7601. {
  7602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7603. {
  7604. 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
  7605. {
  7606. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7607. goto end;
  7608. }
  7609. }//END FOR CHAdeMO_QUANTITY
  7610. for (int index = 0; index < CCS_QUANTITY; index++)
  7611. {
  7612. 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
  7613. {
  7614. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7615. goto end;
  7616. }
  7617. }//END FOR CCS_QUANTITY
  7618. for (int index = 0; index < GB_QUANTITY; index++)
  7619. {
  7620. 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
  7621. {
  7622. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7623. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7624. goto end;
  7625. }
  7626. }// END FOR GB_QUANTITY
  7627. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7628. {
  7629. 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
  7630. {
  7631. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7633. goto end;
  7634. }
  7635. }// END FOR GENERAL_GUN_QUANTITY
  7636. for (int index = 0; index < AC_QUANTITY; index++)
  7637. {
  7638. 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
  7639. {
  7640. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7641. goto end;
  7642. }
  7643. }//END FOR CHAdeMO_QUANTITY
  7644. }// END FOR gunTotalNumber
  7645. }
  7646. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7647. {
  7648. for(int i=0; i < gunTotalNumber; i++)
  7649. {
  7650. for (int index = 0; index < AC_QUANTITY; index++)
  7651. {
  7652. 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
  7653. {
  7654. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7655. goto end;
  7656. }
  7657. }//END FOR CHAdeMO_QUANTITY
  7658. } // END FOR gunTotalNumber
  7659. }
  7660. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7661. goto end;
  7662. }
  7663. //----------------------gunIndex is not 0 ------------------------------------------------//
  7664. //check Transaction active
  7665. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7666. {
  7667. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7668. {
  7669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7670. goto end;
  7671. }
  7672. }//END FOR CHAdeMO_QUANTITY
  7673. for (int index = 0; index < CCS_QUANTITY; index++)
  7674. {
  7675. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7676. {
  7677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7678. goto end;
  7679. }
  7680. }//END FOR CCS_QUANTITY
  7681. for (int index = 0; index < GB_QUANTITY; index++)
  7682. {
  7683. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7684. {
  7685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7686. goto end;
  7687. }
  7688. }// END FOR GB_QUANTITY
  7689. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7690. {
  7691. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7692. {
  7693. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7694. goto end;
  7695. }
  7696. }// END FOR GENERAL_GUN_QUANTITY
  7697. for (int index = 0; index < AC_QUANTITY; index++)
  7698. {
  7699. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7700. {
  7701. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7702. goto end;
  7703. }
  7704. }//END FOR AC_QUANTITY
  7705. }//END FOR AvailabilityTypeStr[Operative]
  7706. end:
  7707. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7708. {
  7709. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7710. }
  7711. else
  7712. {
  7713. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7714. }
  7715. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7716. {
  7717. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7718. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7719. }
  7720. else if(gunIndex == 0)
  7721. {
  7722. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7723. {
  7724. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7725. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7726. }
  7727. }
  7728. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7729. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7730. return result;
  7731. }
  7732. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7733. {
  7734. mtrace();
  7735. int result = FAIL;
  7736. char keystr[40]={0};
  7737. char valuestr[256]={0};
  7738. char comfirmstr[20]={0};
  7739. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7740. json_object *ChangeConfiguration;
  7741. ChangeConfiguration = json_tokener_parse(payload);
  7742. if(!is_error(ChangeConfiguration))
  7743. {
  7744. // Required data
  7745. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7746. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7747. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7748. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7749. }
  7750. json_object_put(ChangeConfiguration);
  7751. if((uuid==NULL) || (payload ==NULL) )
  7752. {
  7753. DEBUG_ERROR("Payload is null\n");
  7754. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7755. }
  7756. else
  7757. {
  7758. int status = setKeyValue(keystr, valuestr);
  7759. switch(status)
  7760. {
  7761. case ConfigurationStatus_Accepted:
  7762. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7763. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  7764. StoreConfigurationTable();
  7765. break;
  7766. case RebootRequired:
  7767. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7768. StoreConfigurationTable();
  7769. break;
  7770. case NotSupported:
  7771. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7772. break;
  7773. case ConfigurationStatus_Rejected:
  7774. default:
  7775. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7776. break;
  7777. }
  7778. }
  7779. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7780. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  7781. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7782. {
  7783. ChageWebSocketPingInterval(atoi(valuestr));
  7784. }
  7785. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7786. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7787. {
  7788. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7789. SetOcppConnStatus(FALSE);
  7790. }
  7791. return result;
  7792. }
  7793. int handleClearCacheRequest(char *uuid, char *payload)
  7794. {
  7795. mtrace();
  7796. int result = FAIL;
  7797. char comfirmstr[20];
  7798. char rmFileCmd[100]={0};
  7799. struct stat stats;
  7800. DEBUG_INFO("handleClearCacheRequest...\n");
  7801. stat("/Storage/OCPP", &stats);
  7802. // Check for directory existence
  7803. if (S_ISDIR(stats.st_mode) == 1)
  7804. {}
  7805. else
  7806. {
  7807. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7808. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  7809. system(rmFileCmd);
  7810. }
  7811. if(OCPP_cleanLocalCache())
  7812. {
  7813. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7814. }
  7815. else
  7816. {
  7817. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7818. }
  7819. sendClearCacheConfirmation(uuid, comfirmstr);
  7820. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7821. return result;
  7822. }
  7823. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7824. {
  7825. mtrace();
  7826. int result = FAIL;
  7827. int resultRename;
  7828. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7829. char chargingProfilePurposeStr[26]={0};
  7830. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7831. char tempchargingProfilePurposeStr[26]={0};
  7832. char str[100]={0};
  7833. char fname[200]={0};
  7834. char comfirmstr[20]={0};
  7835. char word[1600]={0};
  7836. int clearflag = FALSE;
  7837. int chargingProfileIdIsNULL = FALSE;
  7838. int connectorIsNULL = FALSE;
  7839. int chargingProfilePurposeIsNULL = FALSE;
  7840. int stackLevelIsNULL = FALSE;
  7841. //int GotoEnd = FALSE;
  7842. FILE *fptr1, *fptr2;
  7843. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  7844. int n_chargingProfile=0;
  7845. int isEmptyFile = FALSE;
  7846. char sLineWord[1600]={0};
  7847. char chargingProfiles[10][100]={0};
  7848. int ChargeProfileCount = 0;
  7849. int ch;
  7850. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7851. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7852. json_object *ClearChargingProfile;
  7853. ClearChargingProfile = json_tokener_parse(payload);
  7854. if(!is_error(ClearChargingProfile))
  7855. {
  7856. // Optional data
  7857. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7858. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7859. else
  7860. chargingProfileIdIsNULL = TRUE;
  7861. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7862. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7863. else
  7864. connectorIsNULL = TRUE;
  7865. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7866. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7867. else
  7868. chargingProfilePurposeIsNULL = TRUE;
  7869. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7870. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7871. else
  7872. stackLevelIsNULL = TRUE;
  7873. }
  7874. json_object_put(ClearChargingProfile);
  7875. if(connectorIsNULL == FALSE)
  7876. {
  7877. switch(connectorIdInt)
  7878. {
  7879. case 0:
  7880. if(chargingProfilePurposeIsNULL == TRUE)
  7881. {
  7882. int l = 0;
  7883. strcpy(fname, ChargePointMaxProfile_JSON);
  7884. if((access(fname,F_OK))!=-1)
  7885. {
  7886. strcpy(chargingProfiles[l], fname);
  7887. l = l + 1;
  7888. }
  7889. strcpy(fname, TxDefaultProfile_0_JSON);
  7890. if((access(fname,F_OK))!=-1)
  7891. {
  7892. strcpy(chargingProfiles[l], fname);
  7893. l = l + 1;
  7894. }
  7895. ChargeProfileCount = l;
  7896. }
  7897. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7898. {
  7899. strcpy(fname, ChargePointMaxProfile_JSON);
  7900. if((access(fname,F_OK))!=-1)
  7901. {
  7902. strcpy(chargingProfiles[0], fname);
  7903. ChargeProfileCount = 1;
  7904. }
  7905. }
  7906. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7907. {
  7908. strcpy(fname, TxDefaultProfile_0_JSON);
  7909. if((access(fname,F_OK))!=-1)
  7910. {
  7911. strcpy(chargingProfiles[0], fname);
  7912. ChargeProfileCount = 1;
  7913. }
  7914. }
  7915. break;
  7916. default:
  7917. if(chargingProfilePurposeIsNULL == TRUE)
  7918. {
  7919. int m = 0;
  7920. memset(fname, 0, ARRAY_SIZE(fname));
  7921. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7922. if((access(fname,F_OK))!=-1)
  7923. {
  7924. strcpy(chargingProfiles[m], fname);
  7925. m = m + 1;
  7926. }
  7927. memset(fname, 0, ARRAY_SIZE(fname));
  7928. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7929. if((access(fname,F_OK))!=-1)
  7930. {
  7931. strcpy(chargingProfiles[m], fname);
  7932. m = m + 1;
  7933. }
  7934. ChargeProfileCount = m;
  7935. }
  7936. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7937. {
  7938. //strcpy(fname, TxDefaultProfile_1_JSON);
  7939. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  7940. if((access(fname,F_OK))!=-1)
  7941. {
  7942. strcpy(chargingProfiles[0], fname);
  7943. ChargeProfileCount = 1;
  7944. }
  7945. }
  7946. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7947. {
  7948. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7949. if((access(fname,F_OK))!=-1)
  7950. {
  7951. strcpy(chargingProfiles[0], fname);
  7952. ChargeProfileCount = 1;
  7953. }
  7954. //strcpy(fname, TxProfile_1_JSON);
  7955. }
  7956. //strcpy(fname, ChargePointMaxProfile_JSON );
  7957. break;
  7958. }
  7959. }
  7960. else // Check all Charging Profiles
  7961. {
  7962. int i = 0;
  7963. char fnametemp[200]={0};
  7964. ChargeProfileCount = 0;
  7965. //Check ChargePointMaxProfile.json exit
  7966. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  7967. {
  7968. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  7969. i = i + 1;
  7970. }
  7971. //Check TxDefaultProfile_0.json exit
  7972. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  7973. {
  7974. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  7975. i = i + 1;
  7976. }
  7977. //Check TxDefaultProfile_%d.json
  7978. for(int j=1; j <= gunTotalNumber; j++)
  7979. {
  7980. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7981. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  7982. if((access(fnametemp,F_OK))!=-1)
  7983. {
  7984. strcpy(chargingProfiles[i], fnametemp);
  7985. i = i + 1;
  7986. }
  7987. }
  7988. //Check TxProfile_%d.json
  7989. for(int j=1; j <= gunTotalNumber; j++)
  7990. {
  7991. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7992. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  7993. if((access(fnametemp,F_OK))!=-1)
  7994. {
  7995. strcpy(chargingProfiles[i], fnametemp);
  7996. i = i + 1;
  7997. }
  7998. }
  7999. ChargeProfileCount = i;
  8000. }// End connectorIsNULL is TRUE
  8001. if(ChargeProfileCount == 0)
  8002. {
  8003. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8004. goto end;
  8005. }
  8006. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  8007. {
  8008. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8009. goto end;
  8010. }
  8011. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  8012. {
  8013. memset(str, 0, ARRAY_SIZE(str));
  8014. // clear temp file
  8015. sprintf(str,"rm -f %s",temp);
  8016. system(str);
  8017. for(int k=0; k < ChargeProfileCount; k++)
  8018. {
  8019. memset(str, 0, ARRAY_SIZE(str));
  8020. //clear file in C
  8021. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8022. system(str);
  8023. }
  8024. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8025. goto end;
  8026. }
  8027. else if(connectorIsNULL == TRUE)
  8028. {
  8029. for(int k=0; k < ChargeProfileCount; k++)
  8030. {
  8031. fptr1 = fopen(chargingProfiles[k], "r");
  8032. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  8033. //Check Charging Profile Count
  8034. while(fscanf(fptr1, "%s", word) != EOF)
  8035. {
  8036. //DEBUG_INFO("word=%s\n",word);
  8037. if(strstr(word, "chargingProfileId")!= NULL)
  8038. {
  8039. //DEBUG_INFO("test chargingProfileId \n");
  8040. n_chargingProfile = n_chargingProfile + 1;
  8041. //DEBUG_INFO("chargingProfileId Found\n");
  8042. }
  8043. }
  8044. rewind(fptr1);
  8045. //search Charging Profile Element
  8046. //int i= 0;
  8047. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8048. {
  8049. json_object *tmpProfilee;
  8050. tmpProfilee = json_tokener_parse(sLineWord);
  8051. if(!is_error(tmpProfilee))
  8052. {
  8053. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8054. {
  8055. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8056. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8057. }
  8058. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8059. {
  8060. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8061. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8062. }
  8063. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8064. {
  8065. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8066. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8067. }
  8068. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8069. {
  8070. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8071. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8072. }
  8073. }
  8074. json_object_put(tmpProfilee);
  8075. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8076. {
  8077. //------- not write to fptr2-------//
  8078. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8079. //clearflag = TRUE;
  8080. }
  8081. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8082. {
  8083. //------- not write to fptr2-------//
  8084. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8085. }
  8086. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8087. {
  8088. //------- not write to fptr2-------//
  8089. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8090. }
  8091. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  8092. {
  8093. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8094. }
  8095. else
  8096. {
  8097. fprintf(fptr2, sLineWord);//writing data into file
  8098. }
  8099. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8100. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8101. if(clearflag == TRUE)
  8102. {
  8103. fclose(fptr1);
  8104. fclose(fptr2);
  8105. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8106. system(str);
  8107. // clear temp file
  8108. sprintf(str,"rm -f %s",temp);
  8109. system(str);
  8110. }
  8111. else
  8112. {
  8113. fclose(fptr1);
  8114. fclose(fptr2);
  8115. memset(str, 0, ARRAY_SIZE(str));
  8116. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8117. system(str);
  8118. resultRename = rename(temp, chargingProfiles[k]);
  8119. if(resultRename == 0)
  8120. {
  8121. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  8122. }
  8123. else
  8124. {
  8125. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  8126. }
  8127. if(comfirmstr[0]== 0)
  8128. {
  8129. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8130. }
  8131. //Check chargingProfile is empty file
  8132. /*------ Read the file ----------------*/
  8133. fptr1=fopen(chargingProfiles[k],"r");
  8134. ch=fgetc(fptr1);
  8135. rewind(fptr1);
  8136. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8137. if(ch!=EOF)
  8138. {
  8139. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8140. {
  8141. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8142. if(sLineWord[0]=='\0')
  8143. {
  8144. isEmptyFile = TRUE;
  8145. break;
  8146. }
  8147. else
  8148. {
  8149. isEmptyFile = FALSE;
  8150. break;
  8151. }
  8152. }
  8153. }
  8154. else
  8155. isEmptyFile = TRUE;
  8156. fclose(fptr1);
  8157. if(isEmptyFile == TRUE)
  8158. {
  8159. memset(str, 0, ARRAY_SIZE(str));
  8160. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8161. system(str);
  8162. }
  8163. }
  8164. }// End of while(int k=0; k < ChargePointCount; k++)
  8165. }
  8166. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8167. {
  8168. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8169. for(int k=0; k < ChargeProfileCount; k++)
  8170. {
  8171. fptr1 = fopen(chargingProfiles[k], "r");
  8172. fptr2 = fopen(temp, "w+");
  8173. //Check Charging Profile Count
  8174. while(fscanf(fptr1, "%s", word) != EOF)
  8175. {
  8176. //DEBUG_INFO("word=%s\n",word);
  8177. if(strstr(word, "chargingProfileId")!= NULL)
  8178. {
  8179. n_chargingProfile = n_chargingProfile + 1;
  8180. }
  8181. }
  8182. rewind(fptr1);
  8183. //search Charging Profile Element
  8184. //int i= 0;
  8185. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8186. {
  8187. json_object *tmpProfilee;
  8188. tmpProfilee = json_tokener_parse(sLineWord);
  8189. if(!is_error(tmpProfilee))
  8190. {
  8191. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8192. {
  8193. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8194. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8195. }
  8196. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8197. {
  8198. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8199. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8200. }
  8201. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8202. {
  8203. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8204. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8205. }
  8206. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8207. {
  8208. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8209. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8210. }
  8211. }
  8212. json_object_put(tmpProfilee);
  8213. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8214. {
  8215. //------- not write to fptr2-------//
  8216. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8217. //clearflag = TRUE;
  8218. }
  8219. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8220. {
  8221. //------- not write to fptr2-------//
  8222. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8223. }
  8224. else if(stackLevelIsNULL == TRUE)
  8225. {
  8226. //Clear Whole File
  8227. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8228. clearflag = TRUE;
  8229. break;
  8230. }
  8231. else
  8232. {
  8233. fprintf(fptr2, sLineWord);//writing data into file
  8234. }
  8235. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8236. }
  8237. if(clearflag == TRUE)
  8238. {
  8239. fclose(fptr1);
  8240. fclose(fptr2);
  8241. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8242. system(str);
  8243. // clear temp file
  8244. sprintf(str,"rm -f %s",temp);
  8245. system(str);
  8246. }
  8247. else
  8248. {
  8249. fclose(fptr1);
  8250. fclose(fptr2);
  8251. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8252. system(str);
  8253. resultRename = rename(temp, chargingProfiles[k]);
  8254. if(resultRename == 0)
  8255. {
  8256. DEBUG_INFO("File ChargingProfile renamed successfully");
  8257. }
  8258. else
  8259. {
  8260. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8261. }
  8262. if(comfirmstr[0]== 0)
  8263. {
  8264. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8265. }
  8266. //Check chargingProfile is empty file
  8267. /*------ Read the file ----------------*/
  8268. fptr1=fopen(chargingProfiles[k],"r");
  8269. ch=fgetc(fptr1);
  8270. rewind(fptr1);
  8271. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8272. if(ch!=EOF)
  8273. {
  8274. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8275. {
  8276. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8277. if(sLineWord[0]=='\0')
  8278. {
  8279. isEmptyFile = TRUE;
  8280. break;
  8281. }
  8282. else
  8283. {
  8284. isEmptyFile = FALSE;
  8285. break;
  8286. }
  8287. }
  8288. }
  8289. else
  8290. isEmptyFile = TRUE;
  8291. fclose(fptr1);
  8292. if(isEmptyFile == TRUE)
  8293. {
  8294. memset(str, 0, ARRAY_SIZE(str));
  8295. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8296. system(str);
  8297. }
  8298. /*------- End of reading ---------------*/
  8299. }
  8300. } // while(int k=0; k < ChargeProfileCount; k++)
  8301. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8302. end:
  8303. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8304. {
  8305. if(connectorIdInt == 0)
  8306. {
  8307. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8308. {
  8309. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  8310. }
  8311. }
  8312. else
  8313. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  8314. }
  8315. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8316. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8317. return result;
  8318. }
  8319. void createFirmwareVersionByDataTransfer(void)
  8320. {
  8321. json_object *FirmwareDataTransfer = json_object_new_object();
  8322. // AC & DC model
  8323. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8324. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8325. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8326. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8327. // DC model
  8328. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8329. {
  8330. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8331. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8332. (gunType[3] != GUN_TYPE_UNKNOWN))
  8333. {
  8334. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8335. }
  8336. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8337. {
  8338. // DS DM DW
  8339. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8340. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8341. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8342. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8343. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8344. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8345. }
  8346. else
  8347. {
  8348. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8349. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8350. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8351. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8352. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8353. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8354. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8355. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8356. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8357. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8358. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8359. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8360. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8361. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8362. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8363. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8364. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8365. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8366. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8367. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8368. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8369. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8370. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8371. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8372. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8373. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8374. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8375. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8376. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8377. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8378. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8379. }
  8380. }
  8381. // 4G model
  8382. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8383. {
  8384. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8385. }
  8386. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8387. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8388. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8389. json_object_put(FirmwareDataTransfer);
  8390. }
  8391. int handleDataTransferRequest(char *uuid, char *payload)
  8392. {
  8393. mtrace();
  8394. json_object *response = json_object_new_object();
  8395. int result = FAIL;
  8396. char tempvendorId[255]={0};
  8397. char tempmessageId[50]={0};
  8398. char tempdata[512]={0};
  8399. char message[2048]={0};
  8400. DEBUG_INFO("handleDataTransferRequest...\n");
  8401. if((uuid != NULL) && (payload != NULL))
  8402. {
  8403. json_object *DataTransfer;
  8404. DataTransfer = json_tokener_parse(payload);
  8405. if(!is_error(DataTransfer))
  8406. {
  8407. // Required data
  8408. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8409. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8410. // Optional data
  8411. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8412. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8413. if(json_object_object_get(DataTransfer, "data") != NULL)
  8414. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8415. result = PASS;
  8416. }
  8417. json_object_put(DataTransfer);
  8418. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8419. {
  8420. // Send all moudle firmware version on EVSE
  8421. createFirmwareVersionByDataTransfer();
  8422. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8423. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  8424. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8425. json_object_put(response);
  8426. }
  8427. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8428. {
  8429. system("/usr/bin/run_tmate_restart.sh &");
  8430. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8431. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8432. json_object_put(response);
  8433. }
  8434. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8435. {
  8436. json_object *data;
  8437. data = json_tokener_parse(tempdata);
  8438. if(!is_error(data))
  8439. {
  8440. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8441. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8442. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8443. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8444. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8445. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8446. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8447. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8448. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8449. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8450. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8451. }
  8452. else
  8453. {
  8454. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8455. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8456. }
  8457. json_object_put(data);
  8458. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8459. json_object_put(response);
  8460. }
  8461. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8462. {
  8463. json_object *data;
  8464. data = json_tokener_parse(tempdata);
  8465. if(!is_error(data))
  8466. {
  8467. memset(&ShmOCPP16Data->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8468. if(json_object_object_get(data, "idToken") != NULL)
  8469. {
  8470. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8471. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8472. }
  8473. if(json_object_object_get(data, "price") != NULL)
  8474. {
  8475. sprintf((char*)ShmOCPP16Data->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8476. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8477. }
  8478. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8479. }
  8480. else
  8481. {
  8482. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8483. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8484. }
  8485. json_object_put(data);
  8486. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8487. json_object_put(response);
  8488. }
  8489. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8490. {
  8491. json_object *data;
  8492. data = json_tokener_parse(tempdata);
  8493. if(!is_error(data))
  8494. {
  8495. if(json_object_object_get(data, "txId") != NULL)
  8496. {
  8497. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8498. for(int idx = 0;idx<gunTotalNumber;idx++)
  8499. {
  8500. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8501. {
  8502. memset(&ShmOCPP16Data->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8503. ShmOCPP16Data->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8504. if(json_object_object_get(data, "description") != NULL)
  8505. {
  8506. // California pricing V1.0
  8507. DEBUG_INFO("California pricing V1.0\n");
  8508. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8509. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8510. }
  8511. else
  8512. {
  8513. // California pricing V1.1
  8514. DEBUG_INFO("California pricing V1.1\n");
  8515. if(json_object_object_get(data, "timestamp") != NULL)
  8516. {
  8517. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8518. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8519. }
  8520. if(json_object_object_get(data, "meterValue") != NULL)
  8521. {
  8522. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8523. ShmOCPP16Data->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8524. }
  8525. if(json_object_object_get(data, "cost") != NULL)
  8526. {
  8527. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8528. ShmOCPP16Data->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8529. }
  8530. if(json_object_object_get(data, "state") != NULL)
  8531. {
  8532. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8533. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8534. }
  8535. if(json_object_object_get(data, "chargingPrice") != NULL)
  8536. {
  8537. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8538. {
  8539. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8540. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8541. }
  8542. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8543. {
  8544. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8545. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8546. }
  8547. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8548. {
  8549. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8550. ShmOCPP16Data->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8551. }
  8552. }
  8553. if(json_object_object_get(data, "idlePrice") != NULL)
  8554. {
  8555. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8556. {
  8557. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8558. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8559. }
  8560. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8561. {
  8562. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8563. ShmOCPP16Data->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8564. }
  8565. }
  8566. if(json_object_object_get(data, "nextPeriod") != NULL)
  8567. {
  8568. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8569. {
  8570. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8571. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8572. }
  8573. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8574. {
  8575. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8576. {
  8577. 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")));
  8578. 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"));
  8579. }
  8580. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8581. {
  8582. 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")));
  8583. 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"));
  8584. }
  8585. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8586. {
  8587. 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")));
  8588. 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"));
  8589. }
  8590. }
  8591. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8592. {
  8593. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8594. {
  8595. 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")));
  8596. 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"));
  8597. }
  8598. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8599. {
  8600. 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")));
  8601. 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"));
  8602. }
  8603. }
  8604. }
  8605. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8606. {
  8607. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8608. {
  8609. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8610. sprintf((char*)ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8611. }
  8612. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8613. {
  8614. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8615. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8616. }
  8617. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8618. {
  8619. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8620. ShmOCPP16Data->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8621. }
  8622. }
  8623. }
  8624. }
  8625. }
  8626. }
  8627. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8628. }
  8629. else
  8630. {
  8631. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8632. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8633. }
  8634. json_object_put(data);
  8635. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8636. json_object_put(response);
  8637. }
  8638. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8639. {
  8640. json_object *data;
  8641. data = json_tokener_parse(tempdata);
  8642. if(!is_error(data))
  8643. {
  8644. if(json_object_object_get(data, "txId") != NULL)
  8645. {
  8646. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8647. for(int idx = 0;idx<gunTotalNumber;idx++)
  8648. {
  8649. if(ShmOCPP16Data->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8650. {
  8651. memset(&ShmOCPP16Data->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8652. ShmOCPP16Data->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8653. if(json_object_object_get(data, "description") != NULL)
  8654. {
  8655. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8656. sprintf((char*)ShmOCPP16Data->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8657. }
  8658. }
  8659. }
  8660. }
  8661. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8662. }
  8663. else
  8664. {
  8665. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8666. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8667. }
  8668. json_object_put(data);
  8669. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8670. json_object_put(response);
  8671. }
  8672. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8673. {
  8674. json_object *data;
  8675. data = json_tokener_parse(tempdata);
  8676. if(!is_error(data))
  8677. {
  8678. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8679. if(json_object_object_get(data, "Content_Type") != NULL)
  8680. {
  8681. 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))
  8682. {
  8683. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8684. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8685. {
  8686. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8687. }
  8688. }
  8689. else
  8690. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8691. }
  8692. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8693. }
  8694. else
  8695. {
  8696. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8697. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8698. }
  8699. json_object_put(data);
  8700. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8701. json_object_put(response);
  8702. }
  8703. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8704. {
  8705. json_object *data;
  8706. data = json_tokener_parse(tempdata);
  8707. if(!is_error(data))
  8708. {
  8709. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8710. if(json_object_object_get(data, "Page_Index") != NULL)
  8711. {
  8712. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8713. }
  8714. if(json_object_object_get(data, "Duration") != NULL)
  8715. {
  8716. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8717. }
  8718. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8719. }
  8720. else
  8721. {
  8722. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8723. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8724. }
  8725. json_object_put(data);
  8726. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8727. json_object_put(response);
  8728. }
  8729. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8730. {
  8731. json_object *data;
  8732. data = json_tokener_parse(tempdata);
  8733. if(!is_error(data))
  8734. {
  8735. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8736. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8737. {
  8738. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8739. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8740. else
  8741. {
  8742. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8743. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8744. }
  8745. }
  8746. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8747. {
  8748. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8749. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8750. else
  8751. {
  8752. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8753. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8754. }
  8755. }
  8756. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8757. {
  8758. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8759. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8760. else
  8761. {
  8762. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8763. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8764. }
  8765. }
  8766. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8767. {
  8768. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8769. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8770. else
  8771. {
  8772. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8773. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8774. }
  8775. }
  8776. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8777. {
  8778. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8779. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8780. else
  8781. {
  8782. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8783. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8784. }
  8785. }
  8786. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8787. {
  8788. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8789. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8790. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8791. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8792. else
  8793. {
  8794. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8795. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8796. }
  8797. }
  8798. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8799. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8800. }
  8801. else
  8802. {
  8803. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8804. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8805. }
  8806. json_object_put(data);
  8807. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8808. json_object_put(response);
  8809. }
  8810. else
  8811. {
  8812. // Can not find valid message id
  8813. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8814. }
  8815. }
  8816. else
  8817. {
  8818. // Payload is null
  8819. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8820. }
  8821. LWS_Send(message);
  8822. return result;
  8823. }
  8824. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8825. {
  8826. mtrace();
  8827. int result = FAIL;
  8828. int connectorIdInt, durationInt;
  8829. char chargingRateUnitStr[4]={0};
  8830. char comfirmstr[20];
  8831. int confirmPeriods = 0;
  8832. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8833. json_object *GetCompositeSchedule;
  8834. GetCompositeSchedule = json_tokener_parse(payload);
  8835. if(!is_error(GetCompositeSchedule))
  8836. {
  8837. // Required data
  8838. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8839. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8840. else
  8841. connectorIdInt = -1;
  8842. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8843. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8844. else
  8845. durationInt = 86400;
  8846. // Optional data
  8847. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8848. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8849. }
  8850. json_object_put(GetCompositeSchedule);
  8851. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8852. if((connectorIdInt == 0) ||
  8853. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8854. {
  8855. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8856. struct StructChargingProfile tmpProfile[1];
  8857. if(strstr(chargingRateUnitStr, "W") != NULL)
  8858. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8859. else
  8860. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8861. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8862. {
  8863. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8864. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8865. }
  8866. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8867. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8868. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8869. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8870. {
  8871. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8872. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8873. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8874. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8875. (idx<(ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8876. {
  8877. confirmPeriods = idx;
  8878. break;
  8879. }
  8880. }
  8881. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8882. {
  8883. confirmPeriods += 1;
  8884. }
  8885. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8886. }
  8887. else
  8888. {
  8889. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8890. }
  8891. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8892. return result;
  8893. }
  8894. int handleGetConfigurationRequest(char *uuid, char *payload)
  8895. {
  8896. mtrace();
  8897. int result = FAIL;
  8898. int MaxKeySupported = 0;
  8899. int n_keys = 0;
  8900. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8901. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8902. json_object *GetConfiguration;
  8903. GetConfiguration = json_tokener_parse(payload);
  8904. if(!is_error(GetConfiguration))
  8905. {
  8906. // Optional data
  8907. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8908. {
  8909. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8910. {
  8911. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8912. n_keys = idx + 1;
  8913. }
  8914. }
  8915. }
  8916. json_object_put(GetConfiguration);
  8917. UnknownKeynum = 0;
  8918. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8919. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8920. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8921. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8922. if(n_keys != 0)
  8923. {
  8924. for(int i=0;i<n_keys;i++)
  8925. {
  8926. getKeyValue(requestKey[i]);
  8927. }
  8928. }
  8929. else
  8930. {
  8931. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8932. getKeyValue("");
  8933. }
  8934. processUnkownKey();
  8935. sendGetConfigurationConfirmation(uuid);
  8936. return result;
  8937. }
  8938. static char fnamePlusPath[100]={0};
  8939. static char fnamePWithNoPath[60]={0};
  8940. void checkUploadLog(void)
  8941. {
  8942. FILE *fp;
  8943. /* Open the command for reading. */
  8944. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8945. if (fp == NULL) {
  8946. DEBUG_WARN("Failed to run command\n" );
  8947. exit(1);
  8948. }
  8949. int ftppathlen = 0;
  8950. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8951. int i = 0;
  8952. /* Read the output a line at a time - output it. */
  8953. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8954. if(i==0)
  8955. {
  8956. ftppathlen = strlen(fnamePlusPath);
  8957. DEBUG_INFO("%s\n", fnamePlusPath);
  8958. fnamePlusPath[ftppathlen]='\0';
  8959. break;
  8960. }
  8961. i= i+1;
  8962. }
  8963. /* close */
  8964. pclose(fp);
  8965. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8966. {
  8967. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8968. {
  8969. fnamePlusPath[k]='\0';
  8970. }
  8971. }
  8972. i=1;
  8973. //char fname[60]={0};
  8974. while(i < ftppathlen)
  8975. {
  8976. int len=ftppathlen-i;
  8977. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8978. {
  8979. DEBUG_INFO("compare '/' all right\n");
  8980. break;
  8981. }
  8982. i=i+1;
  8983. }
  8984. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8985. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8986. fnamePWithNoPath[i+1] = '\0';
  8987. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8988. {
  8989. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8990. {
  8991. fnamePWithNoPath[j]='\0';
  8992. }
  8993. }
  8994. FILE* fp1 = fopen(fnamePlusPath, "r");
  8995. if (fp1)
  8996. {
  8997. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8998. // file exists
  8999. fclose(fp1);
  9000. }
  9001. else
  9002. {
  9003. // file doesn't exist
  9004. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  9005. }
  9006. }
  9007. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  9008. {
  9009. mtrace();
  9010. int result = FAIL;
  9011. time_t CurrentTime;
  9012. struct tm *tm;
  9013. pthread_t th_Status;
  9014. CurrentTime = time(NULL);
  9015. tm = localtime(&CurrentTime);
  9016. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  9017. 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);
  9018. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9019. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  9020. return result;
  9021. }
  9022. void* GetDiagnosticsProcess(void* data)
  9023. {
  9024. pthread_detach(pthread_self());
  9025. mtrace();
  9026. int retriesInt=0, retryIntervalInt=0;
  9027. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  9028. 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};
  9029. int port=0;
  9030. int isSuccess = FALSE;
  9031. char cmdBuf[2048];
  9032. struct tm *tmNow;
  9033. time_t CurrentTime;
  9034. struct tm tmStart;
  9035. struct tm tmStop;
  9036. CurrentTime = time(NULL);
  9037. tmNow=localtime(&CurrentTime);
  9038. uint16_t targetYear, targetMonth;
  9039. json_object *GetDiagnostics;
  9040. DEBUG_INFO("GetDiagnosticsProcess...\n");
  9041. GetDiagnostics = json_tokener_parse(data);
  9042. if(!is_error(GetDiagnostics))
  9043. {
  9044. // Required data
  9045. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  9046. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  9047. // Optional data
  9048. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  9049. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  9050. else
  9051. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  9052. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  9053. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  9054. else
  9055. retryIntervalInt = 30;
  9056. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  9057. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  9058. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  9059. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  9060. }
  9061. json_object_put(GetDiagnostics);
  9062. // Pack log to compress file
  9063. 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) &&
  9064. (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))
  9065. {
  9066. // Pack system log
  9067. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9068. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  9069. targetYear = tmStart.tm_year;
  9070. targetMonth = tmStart.tm_mon;
  9071. do
  9072. {
  9073. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9074. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  9075. if(targetMonth+1>=13)
  9076. {
  9077. targetYear += 1;
  9078. targetMonth = 1;
  9079. }
  9080. else
  9081. {
  9082. targetMonth += 1;
  9083. }
  9084. }while((targetYear < (tmNow->tm_year+1900)) ||
  9085. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9086. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  9087. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  9088. system(cmdBuf);
  9089. // Pack charging & event log
  9090. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  9091. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  9092. targetYear = tmStart.tm_year;
  9093. targetMonth = tmStart.tm_mon;
  9094. do
  9095. {
  9096. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  9097. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  9098. if(targetMonth+1>=13)
  9099. {
  9100. targetYear += 1;
  9101. targetMonth = 1;
  9102. }
  9103. else
  9104. {
  9105. targetMonth += 1;
  9106. }
  9107. }while((targetYear < (tmNow->tm_year+1900)) ||
  9108. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  9109. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  9110. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  9111. system(cmdBuf);
  9112. // Combine log file
  9113. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  9114. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  9115. }
  9116. else
  9117. {
  9118. system("exec /root/logPackTools 'log' 6");
  9119. }
  9120. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  9121. system(cmdBuf);
  9122. checkUploadLog();
  9123. //****************location*******************/
  9124. if(strcmp(locationstr,"")==0)
  9125. {
  9126. DEBUG_INFO("location is <Empty>!\n");
  9127. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9128. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9129. goto end;
  9130. }
  9131. memset(protocol, 0, ARRAY_SIZE(protocol));
  9132. memset(user, 0, ARRAY_SIZE(user) );
  9133. memset(password, 0, ARRAY_SIZE(password));
  9134. memset(host, 0, ARRAY_SIZE(host));
  9135. memset(path, 0, ARRAY_SIZE(path));
  9136. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9137. memset(host1, 0, ARRAY_SIZE(host1));
  9138. memset(path1, 0, ARRAY_SIZE(path1));
  9139. /*location: ftp://user:password@host:port/path*/
  9140. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9141. if((access(fnamePlusPath,F_OK))!=-1)
  9142. {
  9143. DEBUG_INFO("fnamePlusPath exist.\n");
  9144. }
  9145. else
  9146. {
  9147. DEBUG_INFO("fnamePlusPath not exist!\n");
  9148. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9149. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9150. goto end;
  9151. }
  9152. if(strchr(locationstr,'@')==NULL)
  9153. {
  9154. sscanf(locationstr,
  9155. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9156. protocol, host, &port, path);
  9157. strcpy(user,"anonymous");
  9158. strcpy(password,"");
  9159. }
  9160. else
  9161. {
  9162. //DEBUG_INFO("pch=%s\n", pch);
  9163. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9164. protocol, user, password, host, &port, path);
  9165. }
  9166. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9167. {
  9168. DEBUG_INFO("protocol is not ftp/http ! \n");
  9169. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9170. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9171. goto end;
  9172. }
  9173. if(strncmp(locationstr,"http", 4) == 0)
  9174. {
  9175. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9176. sprintf(ftppath,"/%s", path);
  9177. do
  9178. {
  9179. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9180. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9181. sleep(3);
  9182. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9183. if(!isSuccess)
  9184. {
  9185. DEBUG_INFO("Diagnostics fail.\n");
  9186. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9187. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9188. sleep(retryIntervalInt);
  9189. }
  9190. else
  9191. {
  9192. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9193. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9194. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9195. }
  9196. retriesInt--;
  9197. }while((isSuccess == 0)&&(retriesInt >= 0));
  9198. }
  9199. else
  9200. {
  9201. sscanf(host,"%[^/]%s",host1, path1);
  9202. if(strlen(path) > 0)
  9203. sprintf(ftppath,"/%s", path);
  9204. else
  9205. sprintf(ftppath,"/%s", path1);
  9206. int ftppathlen=strlen(ftppath);
  9207. int i=1;
  9208. char filenametemp[50];
  9209. while(i < ftppathlen)
  9210. {
  9211. int len=ftppathlen-i;
  9212. if(ftppath[len]== 47) // '/' ascll code: 47
  9213. {
  9214. DEBUG_INFO("find '/' all right\n");
  9215. break;
  9216. }
  9217. i=i+1;
  9218. }
  9219. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9220. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9221. filenametemp[i+1] = 0;
  9222. if(port == 0)
  9223. port = 21;
  9224. do
  9225. {
  9226. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9227. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9228. sleep(3);
  9229. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9230. if(!isSuccess)
  9231. {
  9232. DEBUG_INFO("Diagnostics fail.\n");
  9233. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9234. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9235. sleep(retryIntervalInt);
  9236. }
  9237. else
  9238. {
  9239. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9240. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9241. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9242. }
  9243. retriesInt--;
  9244. }while((!isSuccess)&&(retriesInt >= 0));
  9245. }
  9246. end:
  9247. system("rm -f /mnt/*");
  9248. sleep(5);
  9249. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9250. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9251. pthread_exit(NULL);
  9252. }
  9253. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9254. {
  9255. mtrace();
  9256. int result = FAIL;
  9257. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9258. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9259. {
  9260. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9261. locallistVersion = -1;
  9262. }
  9263. else
  9264. {
  9265. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9266. OCPP_getListVerion();
  9267. }
  9268. //from db.OCPP_getListVerion
  9269. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9270. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  9271. sendGetLocalListVersionConfirmation(uuid,"");
  9272. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  9273. return result;
  9274. }
  9275. int handleRemoteStartRequest(char *uuid, char *payload)
  9276. {
  9277. mtrace();
  9278. int result = FAIL;
  9279. int connectorIdInt=-1;
  9280. int tempIndex = 0;
  9281. int connectorIdIsNULL, chargingProfileIsNULL;
  9282. char comfirmstr[20]={0};
  9283. char cmdBuf[512];
  9284. json_object *RemoteStartTransaction;
  9285. FILE *fp;
  9286. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9287. if(server_pending == TRUE)
  9288. {
  9289. return 0;
  9290. }
  9291. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9292. RemoteStartTransaction = json_tokener_parse(payload);
  9293. if(!is_error(RemoteStartTransaction))
  9294. {
  9295. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9296. {
  9297. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9298. }
  9299. else
  9300. {
  9301. connectorIdIsNULL = TRUE;
  9302. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9303. {
  9304. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9305. {
  9306. connectorIdIsNULL = FALSE;
  9307. connectorIdInt = (gun_index+1);
  9308. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9309. break;
  9310. }
  9311. }
  9312. }
  9313. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9314. {
  9315. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9316. // Required data
  9317. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9318. // Optional data
  9319. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9320. {
  9321. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9322. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9323. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9324. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9325. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9326. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9327. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9328. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9329. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9330. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9331. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9332. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9333. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9334. {
  9335. 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")));
  9336. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9337. 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"));
  9338. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9339. 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"));
  9340. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9341. 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")));
  9342. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9343. {
  9344. 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++)
  9345. {
  9346. 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"));
  9347. 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"));
  9348. 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)
  9349. 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"));
  9350. }
  9351. }
  9352. }
  9353. }
  9354. else
  9355. {
  9356. chargingProfileIsNULL = TRUE;
  9357. }
  9358. }
  9359. }
  9360. else
  9361. {
  9362. connectorIdIsNULL = TRUE;
  9363. }
  9364. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9365. {
  9366. DEBUG_WARN("Connector id is NULL\n.");
  9367. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9368. goto end;
  9369. }
  9370. /*
  9371. enum _SYSTEM_STATUS
  9372. {
  9373. S_BOOTING = 0,
  9374. S_IDLE, = 1
  9375. S_AUTHORIZING, = 2
  9376. S_REASSIGN_CHECK, = 3
  9377. S_REASSIGN, = 4
  9378. S_PRECHARGE, = 5
  9379. S_PREPARING_FOR_EV, = 6
  9380. S_PREPARING_FOR_EVSE, = 7
  9381. S_CHARGING, = 8
  9382. S_TERMINATING, = 9
  9383. S_COMPLETE, = 10
  9384. S_ALARM, = 11
  9385. S_FAULT = 12
  9386. }
  9387. */
  9388. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9389. {
  9390. //check Transaction active
  9391. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9392. {
  9393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9394. {
  9395. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9396. }
  9397. else
  9398. {
  9399. tempIndex = connectorIdInt -1;
  9400. }
  9401. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9402. {
  9403. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9404. {
  9405. 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))
  9406. {
  9407. //Reserved
  9408. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9409. }
  9410. 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))
  9411. {
  9412. //Reserved
  9413. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9414. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9415. goto end;
  9416. }
  9417. else
  9418. {
  9419. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9420. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9421. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9422. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9423. {
  9424. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9425. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9426. goto end;
  9427. }
  9428. }//END FOR ELSE
  9429. }
  9430. }// END FOR CHAdeMO_QUANTITY
  9431. }
  9432. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9433. {
  9434. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9435. {
  9436. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9437. }
  9438. else
  9439. {
  9440. tempIndex = connectorIdInt -1;
  9441. }
  9442. for (int index = 0; index < CCS_QUANTITY; index++)
  9443. {
  9444. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9445. {
  9446. 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))
  9447. {
  9448. //Reserved
  9449. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9450. }
  9451. 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))
  9452. {
  9453. //Reserved
  9454. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9455. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9456. goto end;
  9457. }
  9458. else
  9459. {
  9460. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9461. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9462. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9463. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9464. {
  9465. DEBUG_WARN("CCS connector not allow start\n.");
  9466. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9467. goto end;
  9468. }
  9469. }// END FOR ELSE
  9470. }
  9471. }// END FOR CCS_QUANTITY
  9472. }
  9473. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9474. {
  9475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9476. {
  9477. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9478. }
  9479. else
  9480. {
  9481. tempIndex = connectorIdInt -1;
  9482. }
  9483. for (int index = 0; index < GB_QUANTITY; index++)
  9484. {
  9485. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9486. {
  9487. 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))
  9488. {
  9489. //Reserved
  9490. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9491. }
  9492. 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))
  9493. {
  9494. //Reserved
  9495. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9496. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9497. goto end;
  9498. }
  9499. else
  9500. {
  9501. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9502. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9503. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9504. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9505. {
  9506. DEBUG_WARN("GB connector not allow start\n.");
  9507. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9508. goto end;
  9509. }
  9510. }// END FOR ELSE
  9511. }
  9512. } // END FOR GB_QUANTITY
  9513. }
  9514. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9515. {
  9516. tempIndex = connectorIdInt -1;
  9517. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9518. {
  9519. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9520. {
  9521. 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))
  9522. {
  9523. //Reserved
  9524. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9525. }
  9526. 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))
  9527. {
  9528. //Reserved
  9529. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9530. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9531. goto end;
  9532. }
  9533. else
  9534. {
  9535. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9536. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9537. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9538. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9539. {
  9540. DEBUG_WARN("GB connector not allow start\n.");
  9541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9542. goto end;
  9543. }
  9544. }// END FOR ELSE
  9545. }
  9546. } // END FOR GB_QUANTITY
  9547. }
  9548. else
  9549. {
  9550. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9551. {
  9552. tempIndex = 2;
  9553. }
  9554. else
  9555. {
  9556. tempIndex = connectorIdInt -1;
  9557. }
  9558. for (int index = 0; index < AC_QUANTITY; index++)
  9559. {
  9560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9561. {
  9562. 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))
  9563. {
  9564. //Reserved
  9565. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9566. }
  9567. 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))
  9568. {
  9569. //Reserved
  9570. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9572. goto end;
  9573. }
  9574. else
  9575. {
  9576. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9577. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9578. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9579. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9580. {
  9581. DEBUG_WARN("AC connector not allow start\n.");
  9582. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9583. goto end;
  9584. }
  9585. }//END FOR ELSE
  9586. }
  9587. }// END FOR AC_QUANTITY
  9588. }
  9589. if(chargingProfileIsNULL == FALSE)
  9590. {
  9591. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9592. {
  9593. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9594. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9595. //memset idTag
  9596. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9597. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9598. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9599. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9600. // Save profile to file
  9601. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9602. system(cmdBuf);
  9603. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9604. fp = fopen(cmdBuf, "w");
  9605. 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));
  9606. fclose(fp);
  9607. }
  9608. else
  9609. {
  9610. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9611. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9612. }
  9613. }
  9614. else
  9615. {
  9616. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9617. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9618. //memset idTag
  9619. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9620. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9621. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9622. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9623. }
  9624. }
  9625. else
  9626. {
  9627. DEBUG_WARN("Connector id over\n.");
  9628. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9629. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9630. }
  9631. end:
  9632. json_object_put(RemoteStartTransaction);
  9633. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9634. {
  9635. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9636. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9637. }
  9638. //OCPP send RemoteStartConfirmation by first.
  9639. sendRemoteStartConfirmation(uuid, comfirmstr);
  9640. return result;
  9641. }
  9642. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9643. {
  9644. mtrace();
  9645. int result = FAIL;
  9646. int match = FALSE;
  9647. int GunNO = 0;
  9648. int tempIndex = 0;
  9649. int transactionIdInt=0;
  9650. int transactionIdIsNULL= TRUE;
  9651. char comfirmstr[20];
  9652. json_object *RemoteStopTransaction;
  9653. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9654. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9655. if(server_pending == TRUE)
  9656. {
  9657. return 0;
  9658. }
  9659. RemoteStopTransaction = json_tokener_parse(payload);
  9660. if(!is_error(RemoteStopTransaction))
  9661. {
  9662. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9663. {
  9664. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9665. transactionIdIsNULL = FALSE;
  9666. }
  9667. }
  9668. json_object_put(RemoteStopTransaction);
  9669. if(transactionIdIsNULL == FALSE)
  9670. {
  9671. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9672. {
  9673. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9674. {
  9675. //check Transaction active
  9676. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9677. {
  9678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9679. {
  9680. tempIndex = ((gun_index==2) ? 1: 0);
  9681. }
  9682. else
  9683. {
  9684. tempIndex = gun_index;
  9685. }
  9686. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9687. {
  9688. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9689. {
  9690. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9691. {
  9692. match = TRUE;
  9693. GunNO = gun_index;
  9694. }
  9695. }
  9696. }// END FOR CHAdeMO_QUANTITY
  9697. }
  9698. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9699. {
  9700. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9701. {
  9702. tempIndex = ((gun_index==2) ? 1: 0);
  9703. }
  9704. else
  9705. {
  9706. tempIndex = gun_index;
  9707. }
  9708. for (int index = 0; index < CCS_QUANTITY; index++)
  9709. {
  9710. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9711. {
  9712. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9713. {
  9714. match = TRUE;
  9715. GunNO = gun_index;
  9716. }
  9717. }
  9718. }// END FOR CCS_QUANTITY
  9719. }
  9720. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9721. {
  9722. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9723. {
  9724. tempIndex = ((gun_index==2) ? 1: 0);
  9725. }
  9726. else
  9727. {
  9728. tempIndex = gun_index;
  9729. }
  9730. for (int index = 0; index < GB_QUANTITY; index++)
  9731. {
  9732. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9733. {
  9734. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9735. {
  9736. match = TRUE;
  9737. GunNO = gun_index;
  9738. }
  9739. }
  9740. }// END FOR GB_QUANTITY
  9741. }
  9742. else if(gunType[gun_index] == GUN_TYPE_DO)
  9743. {
  9744. tempIndex = gun_index;
  9745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9746. {
  9747. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9748. {
  9749. 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
  9750. {
  9751. match = TRUE;
  9752. GunNO = gun_index;
  9753. }
  9754. }
  9755. }// END FOR GB_QUANTITY
  9756. }
  9757. else
  9758. {
  9759. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9760. {
  9761. tempIndex = 2;
  9762. }
  9763. else
  9764. {
  9765. tempIndex = gun_index;
  9766. }
  9767. for (int index = 0; index < AC_QUANTITY; index++)
  9768. {
  9769. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9770. {
  9771. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9772. {
  9773. match = TRUE;
  9774. GunNO = gun_index;
  9775. }
  9776. }
  9777. }// END FOR CHAdeMO_QUANTITY
  9778. } // END FOR AC ELSE
  9779. }// CHECK IF ResponseTransactionId == transactionIdInt
  9780. }//END FOR
  9781. if( match == TRUE)
  9782. {
  9783. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9784. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9785. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9786. }
  9787. else
  9788. {
  9789. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9790. }
  9791. }
  9792. else
  9793. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9794. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9795. return result;
  9796. }
  9797. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9798. {
  9799. mtrace();
  9800. int result = FAIL;
  9801. int connectorIdInt=0, reservationIdInt=0;
  9802. int tempIndex = 0;
  9803. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9804. char comfirmstr[20]={0};
  9805. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9806. int c = 0;
  9807. char *loc;
  9808. //char *ptr;
  9809. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9810. strcpy(sstrtemp, stringtrimspace(payload));
  9811. //***(1)connectorId ****/
  9812. c=0;
  9813. loc = strstr(sstrtemp, "connectorId");
  9814. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9815. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9816. {
  9817. sstr[c] = loc[strlen("connectorId")+2+c];
  9818. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9819. c++;
  9820. }
  9821. sstr[c] = '\0';
  9822. connectorIdInt = atoi(sstr);
  9823. //***(2)expiryDate ****/
  9824. loc = strstr(sstrtemp, "expiryDate");
  9825. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9826. c = 0;
  9827. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9828. {
  9829. sstr[c] = loc[3+strlen("expiryDate")+c];
  9830. c++;
  9831. }
  9832. sstr[c] = '\0';
  9833. strcpy(expiryDatestr, sstr);
  9834. //***(3)idTag ****/
  9835. loc = strstr(sstrtemp, "idTag");
  9836. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9837. c = 0;
  9838. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9839. {
  9840. sstr[c] = loc[3+strlen("idTag")+c];
  9841. c++;
  9842. }
  9843. sstr[c] = '\0';
  9844. strcpy(idTagstr, sstr);
  9845. //***(4)parentIdTag ****/
  9846. loc = strstr(sstrtemp, "parentIdTag");
  9847. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9848. c = 0;
  9849. if(loc == NULL)
  9850. {
  9851. strcpy(parentIdTagstr, "");
  9852. }
  9853. else
  9854. {
  9855. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9856. {
  9857. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9858. c++;
  9859. }
  9860. sstr[c] = '\0';
  9861. strcpy(parentIdTagstr, sstr);
  9862. }
  9863. //***(5)reservationId ****/
  9864. c=0;
  9865. loc = strstr(sstrtemp, "reservationId");
  9866. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9867. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9868. {
  9869. sstr[c] = loc[strlen("reservationId")+2+c];
  9870. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9871. c++;
  9872. }
  9873. sstr[c] = '\0';
  9874. reservationIdInt = atoi(sstr);
  9875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9876. /*
  9877. enum SYSTEM_STATUS
  9878. {
  9879. SYS_MODE_BOOTING = 0,
  9880. SYS_MODE_IDLE = 1,
  9881. SYS_MODE_AUTHORIZING = 2,
  9882. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9883. SYS_MODE_REASSIGN = 4,
  9884. SYS_MODE_PREPARING = 5,
  9885. SYS_MODE_PREPARE_FOR_EV = 6,
  9886. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9887. SYS_MODE_CHARGING = 8,
  9888. SYS_MODE_TERMINATING = 9,
  9889. SYS_MODE_COMPLETE = 10,
  9890. SYS_MODE_ALARM = 11,
  9891. SYS_MODE_FAULT = 12,
  9892. SYS_MODE_RESERVATION = 13,
  9893. SYS_MODE_BOOKING = 14,
  9894. SYS_MODE_MAINTAIN = 15,
  9895. SYS_MODE_DEBUG = 16,
  9896. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9897. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9898. SYS_MODE_UPDATE = 19
  9899. };
  9900. */
  9901. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9902. {
  9903. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9904. goto end;
  9905. }
  9906. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9907. {
  9908. //check Transaction active
  9909. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9910. {
  9911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9912. {
  9913. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9914. }
  9915. else
  9916. {
  9917. tempIndex = connectorIdInt -1;
  9918. }
  9919. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9920. {
  9921. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9922. {
  9923. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9924. {
  9925. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9926. {
  9927. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9928. {
  9929. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9931. }
  9932. 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'))
  9933. {
  9934. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9935. }
  9936. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9937. {
  9938. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9939. }
  9940. else
  9941. {
  9942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9943. }
  9944. }
  9945. 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
  9946. {
  9947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9948. }
  9949. }
  9950. else
  9951. {
  9952. //replace reservation
  9953. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9954. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9955. }
  9956. }
  9957. } // END FOR CHAdeMO_QUANTITY
  9958. }
  9959. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9960. {
  9961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9962. {
  9963. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9964. }
  9965. else
  9966. {
  9967. tempIndex = connectorIdInt -1;
  9968. }
  9969. for (int index = 0; index < CCS_QUANTITY; index++)
  9970. {
  9971. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9972. {
  9973. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9974. {
  9975. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9976. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9977. {
  9978. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9979. {
  9980. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9982. }
  9983. 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'))
  9984. {
  9985. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9986. }
  9987. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9988. {
  9989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9990. }
  9991. else
  9992. {
  9993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9994. }
  9995. }
  9996. 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
  9997. {
  9998. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9999. }
  10000. }
  10001. else
  10002. {
  10003. //replace reservation
  10004. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10006. }
  10007. }
  10008. } // END FOR CCS_QUANTITY
  10009. }
  10010. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10011. {
  10012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10013. {
  10014. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10015. }
  10016. else
  10017. {
  10018. tempIndex = connectorIdInt -1;
  10019. }
  10020. for (int index = 0; index < GB_QUANTITY; index++)
  10021. {
  10022. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10023. {
  10024. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10025. {
  10026. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10027. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10028. {
  10029. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10030. {
  10031. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10032. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10033. }
  10034. 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'))
  10035. {
  10036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10037. }
  10038. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10039. {
  10040. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10041. }
  10042. else
  10043. {
  10044. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10045. }
  10046. }
  10047. 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
  10048. {
  10049. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10050. }
  10051. }
  10052. else
  10053. {
  10054. //replace reservation
  10055. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10057. }
  10058. }
  10059. }// END FOR GB_QUANTITY
  10060. }
  10061. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10062. {
  10063. tempIndex = connectorIdInt -1;
  10064. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10065. {
  10066. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10067. {
  10068. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  10069. {
  10070. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10071. 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
  10072. {
  10073. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10074. {
  10075. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10077. }
  10078. 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'))
  10079. {
  10080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10081. }
  10082. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10083. {
  10084. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10085. }
  10086. else
  10087. {
  10088. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10089. }
  10090. }
  10091. 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
  10092. {
  10093. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10094. }
  10095. }
  10096. else
  10097. {
  10098. //replace reservation
  10099. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10101. }
  10102. }
  10103. }// END FOR GB_QUANTITY
  10104. }
  10105. else
  10106. {
  10107. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10108. {
  10109. tempIndex = 2;
  10110. }
  10111. else
  10112. {
  10113. tempIndex = (connectorIdInt -1);
  10114. }
  10115. for (int index = 0; index < AC_QUANTITY; index++)
  10116. {
  10117. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10118. {
  10119. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10120. {
  10121. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10122. {
  10123. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10124. {
  10125. 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))
  10126. {
  10127. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10128. }
  10129. else
  10130. {
  10131. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10132. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10133. }
  10134. }
  10135. 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'))
  10136. {
  10137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10138. }
  10139. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10140. {
  10141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10142. }
  10143. else
  10144. {
  10145. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10146. }
  10147. }
  10148. 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
  10149. {
  10150. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10151. }
  10152. }
  10153. else
  10154. {
  10155. //replace reservation
  10156. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10157. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10158. }
  10159. }
  10160. } // END FOR AC_QUANTITY
  10161. }
  10162. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10163. }
  10164. else if(connectorIdInt == 0)
  10165. {
  10166. //check Transaction active
  10167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10168. {
  10169. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10170. {
  10171. 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'))
  10172. {
  10173. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10174. goto end;
  10175. }
  10176. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10177. {
  10178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10179. goto end;
  10180. }
  10181. 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
  10182. {
  10183. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10184. goto end;
  10185. }
  10186. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10187. {
  10188. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10189. goto end;
  10190. }
  10191. }
  10192. }// END FOR CHAdeMO_QUANTITY
  10193. for (int index = 0; index < CCS_QUANTITY; index++)
  10194. {
  10195. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10196. {
  10197. 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'))
  10198. {
  10199. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10200. goto end;
  10201. }
  10202. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10203. {
  10204. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10205. goto end;
  10206. }
  10207. 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
  10208. {
  10209. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10210. goto end;
  10211. }
  10212. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10213. {
  10214. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10215. goto end;
  10216. }
  10217. }
  10218. } // END FOR CCS_QUANTITY
  10219. for (int index = 0; index < GB_QUANTITY; index++)
  10220. {
  10221. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10222. {
  10223. 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'))
  10224. {
  10225. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10226. goto end;
  10227. }
  10228. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10229. {
  10230. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10231. goto end;
  10232. }
  10233. 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
  10234. {
  10235. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10236. goto end;
  10237. }
  10238. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10239. {
  10240. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10241. goto end;
  10242. }
  10243. }
  10244. } // END FOR GB_QUANTITY
  10245. for (int index = 0; index < AC_QUANTITY; index++)
  10246. {
  10247. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10248. {
  10249. 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'))
  10250. {
  10251. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10252. goto end;
  10253. }
  10254. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10255. {
  10256. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10257. goto end;
  10258. }
  10259. 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
  10260. {
  10261. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10262. goto end;
  10263. }
  10264. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10265. {
  10266. 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))
  10267. {
  10268. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10269. goto end;
  10270. }
  10271. }
  10272. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10273. {
  10274. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10275. goto end;
  10276. }
  10277. }
  10278. }// END FOR AC_QUANTITY
  10279. //The connectorId is 0
  10280. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  10281. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10282. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10283. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  10284. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10285. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  10286. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10287. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  10288. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  10289. result = TRUE;
  10290. return result;
  10291. }
  10292. else
  10293. {
  10294. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10295. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10296. }
  10297. if(strcmp(comfirmstr,"Accepted") == 0)
  10298. {
  10299. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10300. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10301. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10302. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10303. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10304. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  10305. result = TRUE;
  10306. return result;
  10307. }
  10308. end:
  10309. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10310. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10311. return result;
  10312. }
  10313. int handleResetRequest(char *uuid, char *payload)
  10314. {
  10315. mtrace();
  10316. int result = FAIL;
  10317. char sstr[10]={0},sstrtemp[30]={ 0 };
  10318. char typestr[10]={0};
  10319. char comfirmstr[20]={0};
  10320. int c = 0;
  10321. char *loc;
  10322. DEBUG_INFO("handleResetRequest...\n");
  10323. strcpy(sstrtemp, stringtrimspace(payload));
  10324. loc = strstr(sstrtemp, "type");
  10325. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10326. c = 0;
  10327. while (loc[3+strlen("type")+c] != '\"')
  10328. {
  10329. sstr[c] = loc[3+strlen("type")+c];
  10330. c++;
  10331. }
  10332. sstr[c] = '\0';
  10333. strcpy(typestr,sstr);
  10334. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  10335. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10336. {
  10337. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  10338. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  10339. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10340. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10341. }
  10342. else
  10343. {
  10344. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10345. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  10346. result = PASS;
  10347. }
  10348. sendResetConfirmation(uuid, comfirmstr);
  10349. return result;
  10350. }
  10351. int handleSendLocalListRequest(char *uuid, char *payload)
  10352. {
  10353. mtrace();
  10354. int result = FAIL;
  10355. char comfirmstr[20];
  10356. int checkState_Faulted = FALSE;
  10357. json_object *SendLocalList;
  10358. DEBUG_INFO("handleSendLocalListRequest...\n");
  10359. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10360. {
  10361. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10362. goto end;
  10363. }
  10364. //check Charge Point state
  10365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10366. {
  10367. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10368. {
  10369. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10370. }
  10371. }
  10372. for (int index = 0; index < CCS_QUANTITY; index++)
  10373. {
  10374. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10375. {
  10376. checkState_Faulted = TRUE; //OCPP Status
  10377. }
  10378. }
  10379. for (int index = 0; index < GB_QUANTITY; index++)
  10380. {
  10381. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10382. {
  10383. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10384. }
  10385. }
  10386. //check Charge Point state
  10387. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10388. {
  10389. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10390. {
  10391. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10392. }
  10393. }
  10394. //check Charge Point state
  10395. for (int index = 0; index < AC_QUANTITY; index++)
  10396. {
  10397. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10398. {
  10399. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10400. }
  10401. }
  10402. if(checkState_Faulted == TRUE)
  10403. {
  10404. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10405. goto end;
  10406. }
  10407. // Parsing payload
  10408. SendLocalList = json_tokener_parse(payload);
  10409. if(!is_error(SendLocalList))
  10410. {
  10411. // Required data
  10412. ShmOCPP16Data->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10413. sprintf((char*)ShmOCPP16Data->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10414. // Optional data
  10415. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10416. {
  10417. //Check UpdateType
  10418. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10419. {
  10420. //Local list full update
  10421. DEBUG_INFO("Local list full update.\n");
  10422. OCPP_getListVerion();
  10423. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10424. {
  10425. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10426. goto end;
  10427. }
  10428. OCPP_cleanLocalList();
  10429. }
  10430. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10431. {
  10432. //Local list different update
  10433. DEBUG_INFO("Local list different update.\n");
  10434. OCPP_getListVerion();
  10435. if(ShmOCPP16Data->SendLocalList.ListVersion < locallistVersion)
  10436. {
  10437. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10438. goto end;
  10439. }
  10440. }
  10441. else
  10442. {
  10443. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10444. goto end;
  10445. }
  10446. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  10447. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10448. {
  10449. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10450. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10451. {
  10452. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].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")));
  10453. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10454. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].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")));
  10455. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10456. sprintf((char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].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")));
  10457. }
  10458. // Add to db
  10459. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10460. {
  10461. //Local list full update
  10462. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10463. idx,
  10464. ShmOCPP16Data->SendLocalList.ListVersion,
  10465. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10466. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10467. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10468. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10469. // update list
  10470. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10471. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10472. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10473. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10474. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10475. }
  10476. else if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10477. {
  10478. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10479. idx,
  10480. ShmOCPP16Data->SendLocalList.ListVersion,
  10481. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10482. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10483. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10484. ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10485. OCPP_addLocalList(ShmOCPP16Data->SendLocalList.ListVersion,
  10486. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10487. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10488. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10489. (char*)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10490. }
  10491. }
  10492. }
  10493. else
  10494. {
  10495. //Check UpdateType
  10496. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10497. {
  10498. //Local list full update
  10499. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10500. OCPP_cleanLocalList();
  10501. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10502. goto end;
  10503. }
  10504. if(strcmp((char*)ShmOCPP16Data->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10505. {
  10506. //Local list different update
  10507. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10508. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10509. goto end;
  10510. }
  10511. }
  10512. result = PASS;
  10513. }
  10514. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10515. end:
  10516. json_object_put(SendLocalList);
  10517. sendSendLocalListConfirmation(uuid, comfirmstr);
  10518. return result;
  10519. }
  10520. #define MAX 200
  10521. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10522. {
  10523. mtrace();
  10524. int result = FAIL;
  10525. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10526. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10527. char chargingProfilePurposeStr[30]={0};
  10528. char chargingProfileKindStr[16]={0};
  10529. char recurrencyKindStr[10]={0};
  10530. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10531. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10532. int chargingSchedulePeriodCount = 0;
  10533. char comfirmstr[20]={0};
  10534. int meet= FALSE;
  10535. FILE *fptr1;
  10536. char filename[MAX]={0};
  10537. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10538. char rmFileCmd[50]={0};
  10539. char tempchargingProfilePurposeStr[30]={0};
  10540. char word[1600]={0};
  10541. int n_chargingProfile = 0;
  10542. json_object *SetChargingProfile;
  10543. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10544. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10545. SetChargingProfile = json_tokener_parse(payload);
  10546. if(!is_error(SetChargingProfile))
  10547. {
  10548. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10549. {
  10550. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10551. if(connectorIdInt == 0)
  10552. {
  10553. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10554. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10555. }
  10556. else
  10557. {
  10558. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10559. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10560. }
  10561. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10562. }
  10563. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10564. {
  10565. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10566. {
  10567. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10568. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10569. {
  10570. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10571. }
  10572. else
  10573. {
  10574. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10575. }
  10576. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10577. }
  10578. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10579. {
  10580. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10581. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10582. {
  10583. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10584. }
  10585. else
  10586. {
  10587. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10588. }
  10589. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10590. }
  10591. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10592. {
  10593. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10594. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10595. {
  10596. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10597. }
  10598. else
  10599. {
  10600. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10601. }
  10602. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10603. }
  10604. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10605. {
  10606. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10607. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10608. {
  10609. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10610. }
  10611. else
  10612. {
  10613. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10614. }
  10615. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10616. }
  10617. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10618. {
  10619. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10620. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10621. {
  10622. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10623. }
  10624. else
  10625. {
  10626. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10627. }
  10628. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10629. }
  10630. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10631. {
  10632. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10633. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10634. {
  10635. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10636. }
  10637. else
  10638. {
  10639. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10640. }
  10641. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10642. }
  10643. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10644. {
  10645. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10646. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10647. {
  10648. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10649. }
  10650. else
  10651. {
  10652. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10653. }
  10654. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10655. }
  10656. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10657. {
  10658. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10659. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10660. {
  10661. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10662. }
  10663. else
  10664. {
  10665. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10666. }
  10667. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10668. }
  10669. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10670. {
  10671. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10672. {
  10673. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10674. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10675. {
  10676. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10677. }
  10678. else
  10679. {
  10680. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10681. }
  10682. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10683. }
  10684. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10685. {
  10686. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10687. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10688. {
  10689. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10690. }
  10691. else
  10692. {
  10693. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10694. }
  10695. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10696. }
  10697. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10698. {
  10699. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10700. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10701. {
  10702. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10703. }
  10704. else
  10705. {
  10706. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10707. }
  10708. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10709. }
  10710. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10711. {
  10712. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10713. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10714. {
  10715. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10716. }
  10717. else
  10718. {
  10719. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10720. }
  10721. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10722. }
  10723. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10724. {
  10725. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10726. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10727. if(chargingSchedulePeriodCount <= 10)
  10728. {
  10729. 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++)
  10730. {
  10731. 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)
  10732. {
  10733. startPeriodInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10734. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10735. {
  10736. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10737. }
  10738. else
  10739. {
  10740. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10741. }
  10742. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10743. }
  10744. 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)
  10745. {
  10746. limitflaot[idxPeriod] = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10747. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10748. {
  10749. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10750. }
  10751. else
  10752. {
  10753. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10754. }
  10755. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10756. }
  10757. 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)
  10758. {
  10759. numberPhasesInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10760. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10761. {
  10762. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10763. }
  10764. else
  10765. {
  10766. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10767. }
  10768. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10769. }
  10770. }
  10771. }
  10772. }
  10773. }
  10774. }
  10775. }
  10776. json_object_put(SetChargingProfile);
  10777. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10778. {
  10779. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10780. goto end;
  10781. }
  10782. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10783. {
  10784. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10785. if(connectorIdInt != 0)
  10786. {
  10787. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10788. goto end;
  10789. }
  10790. strcpy(filename, ChargePointMaxProfile_JSON );
  10791. fptr1 = fopen(filename, "r");
  10792. if (!fptr1)
  10793. {
  10794. //file not exist
  10795. DEBUG_INFO("Unable to open the input file!!\n");
  10796. fptr1 = fopen(filename, "w+");
  10797. }
  10798. else
  10799. {
  10800. //Check Charging Profile Count
  10801. while(fscanf(fptr1, "%s", word) != EOF)
  10802. {
  10803. //DEBUG_INFO("word=%s\n",word);
  10804. if(strstr(word, "chargingProfileId")!= NULL)
  10805. {
  10806. //DEBUG_INFO("test chargingProfileId \n");
  10807. n_chargingProfile = n_chargingProfile + 1;
  10808. //DEBUG_INFO("chargingProfileId Found\n");
  10809. }
  10810. }
  10811. }
  10812. fclose(fptr1);
  10813. }
  10814. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10815. {
  10816. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10817. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10818. {
  10819. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10820. goto end;
  10821. }
  10822. memset(filename, 0, ARRAY_SIZE(filename));
  10823. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10824. fptr1 = fopen(filename, "r");
  10825. if (!fptr1)
  10826. {
  10827. //file not exist
  10828. //DEBUG_INFO("Unable to open the input file!!\n");
  10829. fptr1 = fopen(filename, "w+");
  10830. }
  10831. else
  10832. {
  10833. //Check Charging Profile Count
  10834. while(fscanf(fptr1, "%s", word) != EOF)
  10835. {
  10836. //DEBUG_INFO("word=%s\n",word);
  10837. if(strstr(word, "chargingProfileId")!= NULL)
  10838. {
  10839. //DEBUG_INFO("test chargingProfileId \n");
  10840. n_chargingProfile = n_chargingProfile + 1;
  10841. //DEBUG_INFO("chargingProfileId Found\n");
  10842. }
  10843. }
  10844. }
  10845. fclose(fptr1);
  10846. }
  10847. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10848. {
  10849. //printf("set chargingProfile 1-4\n");
  10850. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10851. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10852. if(connectorIdInt == 0)
  10853. {
  10854. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10855. goto end;
  10856. }
  10857. int tempIndex = 0;
  10858. //check Transaction active
  10859. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10860. {
  10861. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10862. {
  10863. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10864. }
  10865. else
  10866. {
  10867. tempIndex = connectorIdInt -1;
  10868. }
  10869. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10870. {
  10871. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10872. {
  10873. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10874. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10875. {
  10876. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10877. {
  10878. meet = TRUE;
  10879. break;
  10880. }
  10881. }
  10882. }
  10883. }
  10884. }
  10885. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10886. {
  10887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10888. {
  10889. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10890. }
  10891. else
  10892. {
  10893. tempIndex = connectorIdInt -1;
  10894. }
  10895. for (int index = 0; index < CCS_QUANTITY; index++)
  10896. {
  10897. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10898. {
  10899. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10900. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10901. {
  10902. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10903. {
  10904. meet = TRUE;
  10905. break;
  10906. }
  10907. }
  10908. }
  10909. }
  10910. }
  10911. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10912. {
  10913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10914. {
  10915. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10916. }
  10917. else
  10918. {
  10919. tempIndex = connectorIdInt -1;
  10920. }
  10921. for (int index = 0; index < GB_QUANTITY; index++)
  10922. {
  10923. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10924. {
  10925. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10926. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10927. {
  10928. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10929. {
  10930. meet = TRUE;
  10931. break;
  10932. }
  10933. }
  10934. }
  10935. }
  10936. }
  10937. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10938. {
  10939. tempIndex = connectorIdInt -1;
  10940. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10941. {
  10942. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10943. {
  10944. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10945. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10946. {
  10947. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10948. {
  10949. meet = TRUE;
  10950. break;
  10951. }
  10952. }
  10953. }
  10954. }
  10955. }
  10956. else
  10957. {
  10958. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10959. {
  10960. tempIndex = 2;
  10961. }
  10962. else
  10963. {
  10964. tempIndex = (connectorIdInt -1);
  10965. }
  10966. for (int index = 0; index < AC_QUANTITY; index++)
  10967. {
  10968. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10969. {
  10970. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10971. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10972. {
  10973. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10974. {
  10975. meet = TRUE;
  10976. break;
  10977. }
  10978. }
  10979. }
  10980. }
  10981. }
  10982. //check Transaction active
  10983. if(meet == FALSE)
  10984. {
  10985. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10986. goto end;
  10987. }
  10988. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10989. {
  10990. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10991. goto end;
  10992. }
  10993. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10994. fptr1 = fopen(filename, "r");
  10995. if (!fptr1)
  10996. {
  10997. //file not exist
  10998. DEBUG_INFO("Unable to open the input file!!\n");
  10999. fptr1 = fopen(filename, "w+");
  11000. }
  11001. else
  11002. {
  11003. //Check Charging Profile Count
  11004. while(fscanf(fptr1, "%s", word) != EOF)
  11005. {
  11006. //DEBUG_INFO("word=%s\n",word);
  11007. if(strstr(word, "chargingProfileId")!= NULL)
  11008. {
  11009. //DEBUG_INFO("test chargingProfileId \n");
  11010. n_chargingProfile = n_chargingProfile + 1;
  11011. //DEBUG_INFO("chargingProfileId Found\n");
  11012. }
  11013. }
  11014. }
  11015. fclose(fptr1);
  11016. }
  11017. // Check ChargeProfileMaxStackLevel
  11018. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  11019. {
  11020. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11021. goto end;
  11022. }
  11023. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11024. {
  11025. int i = 0;
  11026. char fnametemp[200]={0};
  11027. n_chargingProfile = 0;
  11028. //Check ChargePointMaxProfile.json exit
  11029. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11030. {
  11031. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  11032. //Check Charging Profile Count
  11033. while(fscanf(fptr1, "%s", word) != EOF)
  11034. {
  11035. //DEBUG_INFO("word=%s\n",word);
  11036. if(strstr(word, "chargingProfileId")!= NULL)
  11037. {
  11038. //DEBUG_INFO("test chargingProfileId \n");
  11039. n_chargingProfile = n_chargingProfile + 1;
  11040. i = i + 1;
  11041. //DEBUG_INFO("chargingProfileId Found\n");
  11042. }
  11043. memset(word, 0, ARRAY_SIZE(word));
  11044. }
  11045. fclose(fptr1);
  11046. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  11047. }
  11048. //Check TxDefaultProfile_0.json exit
  11049. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  11050. {
  11051. i = 0;
  11052. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  11053. //Check Charging Profile Count
  11054. while(fscanf(fptr1, "%s", word) != EOF)
  11055. {
  11056. //DEBUG_INFO("word=%s\n",word);
  11057. if(strstr(word, "chargingProfileId")!= NULL)
  11058. {
  11059. //DEBUG_INFO("test chargingProfileId \n");
  11060. n_chargingProfile = n_chargingProfile + 1;
  11061. i = i + 1;
  11062. //DEBUG_INFO("chargingProfileId Found\n");
  11063. }
  11064. memset(word, 0, ARRAY_SIZE(word));
  11065. }
  11066. fclose(fptr1);
  11067. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  11068. }
  11069. //Check TxDefaultProfile_%d.json
  11070. for(int j=1; j <= gunTotalNumber; j++)
  11071. {
  11072. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11073. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  11074. if((access(fnametemp,F_OK))!=-1)
  11075. {
  11076. i = 0;
  11077. fptr1 = fopen(fnametemp, "r");
  11078. //Check Charging Profile Count
  11079. while(fscanf(fptr1, "%s", word) != EOF)
  11080. {
  11081. //DEBUG_INFO("word=%s\n",word);
  11082. if(strstr(word, "chargingProfileId")!= NULL)
  11083. {
  11084. //DEBUG_INFO("test chargingProfileId \n");
  11085. n_chargingProfile = n_chargingProfile + 1;
  11086. i = i + 1;
  11087. //DEBUG_INFO("chargingProfileId Found\n");
  11088. }
  11089. memset(word, 0, ARRAY_SIZE(word));
  11090. }
  11091. fclose(fptr1);
  11092. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11093. }
  11094. }
  11095. //Check TxProfile_%d.json
  11096. for(int j=1; j <= gunTotalNumber; j++)
  11097. {
  11098. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11099. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  11100. if((access(fnametemp,F_OK))!=-1)
  11101. {
  11102. i = 0;
  11103. fptr1 = fopen(fnametemp, "r");
  11104. //Check Charging Profile Count
  11105. while(fscanf(fptr1, "%s", word) != EOF)
  11106. {
  11107. //DEBUG_INFO("word=%s\n",word);
  11108. if(strstr(word, "chargingProfileId")!= NULL)
  11109. {
  11110. //DEBUG_INFO("test chargingProfileId \n");
  11111. n_chargingProfile = n_chargingProfile + 1;
  11112. i = i + 1;
  11113. //DEBUG_INFO("chargingProfileId Found\n");
  11114. }
  11115. memset(word, 0, ARRAY_SIZE(word));
  11116. }
  11117. fclose(fptr1);
  11118. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  11119. }
  11120. }
  11121. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  11122. {
  11123. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  11124. goto end;
  11125. }
  11126. }
  11127. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  11128. //**********************************Write to File********************************************************/
  11129. FILE *infile;
  11130. FILE *outfile;
  11131. infile = fopen (filename, "r");
  11132. outfile = fopen (tempfile, "w");
  11133. int d =0;
  11134. d = fgetc(infile);
  11135. rewind(infile);
  11136. if(d == EOF)
  11137. {
  11138. // Profile is empty
  11139. fprintf(outfile,"%s\n",payload);
  11140. fclose(infile);
  11141. fclose(outfile);
  11142. sprintf(rmFileCmd,"rm -f %s",filename);
  11143. system(rmFileCmd);
  11144. rename(tempfile, filename);
  11145. }
  11146. else
  11147. {
  11148. // Profile is not empty
  11149. char buf[2048]={0};
  11150. int ChargingProfileAdded = FALSE;
  11151. while (fgets(buf, sizeof(buf), infile) != NULL)
  11152. {
  11153. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  11154. json_object *tmpChargingProfile;
  11155. tmpChargingProfile = json_tokener_parse(buf);
  11156. if(!is_error(SetChargingProfile))
  11157. {
  11158. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  11159. {
  11160. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  11161. }
  11162. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11163. {
  11164. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11165. {
  11166. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11167. }
  11168. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11169. {
  11170. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  11171. }
  11172. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11173. {
  11174. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11175. }
  11176. }
  11177. }
  11178. json_object_put(tmpChargingProfile);
  11179. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  11180. {
  11181. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11182. {
  11183. //DEBUG_INFO("update set chargingProfile to file -0\n");
  11184. if(ChargingProfileAdded == FALSE)
  11185. {
  11186. fprintf(outfile,"%s\n",payload);
  11187. ChargingProfileAdded = TRUE;
  11188. }
  11189. }
  11190. else
  11191. {
  11192. if(tempstackLevelInt < stackLevelInt)
  11193. {
  11194. if(ChargingProfileAdded == FALSE)
  11195. {
  11196. fprintf(outfile,"%s\n",buf);
  11197. fprintf(outfile,"%s\n",payload);
  11198. ChargingProfileAdded = TRUE;
  11199. }
  11200. else
  11201. {
  11202. fprintf(outfile,"%s\n",buf);
  11203. }
  11204. }
  11205. else
  11206. {
  11207. if(ChargingProfileAdded == FALSE)
  11208. {
  11209. fprintf(outfile,"%s\n",buf);
  11210. fprintf(outfile,"%s\n",payload);
  11211. ChargingProfileAdded = TRUE;
  11212. }
  11213. else
  11214. {
  11215. fprintf(outfile,"%s\n",buf);
  11216. }
  11217. }
  11218. }
  11219. }
  11220. else
  11221. {
  11222. if(tempchargingProfileIdInt < chargingProfileIdInt)
  11223. {
  11224. if(ChargingProfileAdded == FALSE)
  11225. {
  11226. fprintf(outfile,"%s\n",buf);
  11227. fprintf(outfile,"%s\n",payload);
  11228. ChargingProfileAdded = TRUE;
  11229. }
  11230. else
  11231. {
  11232. fprintf(outfile,"%s\n",buf);
  11233. }
  11234. }
  11235. else if(tempstackLevelInt < stackLevelInt)
  11236. {
  11237. if(ChargingProfileAdded == FALSE)
  11238. {
  11239. fprintf(outfile,"%s\n",buf);
  11240. fprintf(outfile,"%s\n",payload);
  11241. ChargingProfileAdded = TRUE;
  11242. }
  11243. else
  11244. {
  11245. fprintf(outfile,"%s\n",buf);
  11246. }
  11247. }
  11248. else
  11249. {
  11250. if(ChargingProfileAdded == FALSE)
  11251. {
  11252. fprintf(outfile,"%s\n",buf);
  11253. fprintf(outfile,"%s\n",payload);
  11254. ChargingProfileAdded = TRUE;
  11255. }
  11256. else
  11257. {
  11258. fprintf(outfile,"%s\n",buf);
  11259. }
  11260. }
  11261. }
  11262. } // end of while loop
  11263. fclose(infile);
  11264. fclose(outfile);
  11265. sprintf(rmFileCmd,"rm -f %s",filename);
  11266. system(rmFileCmd);
  11267. rename(tempfile, filename);
  11268. }
  11269. sleep(1);
  11270. result = TRUE;
  11271. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  11272. end:
  11273. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  11274. {
  11275. if(connectorIdInt == 0)
  11276. {
  11277. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11278. {
  11279. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx], TRUE);
  11280. }
  11281. }
  11282. else
  11283. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1], TRUE);
  11284. }
  11285. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  11286. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11287. return result;
  11288. }
  11289. int handleTriggerMessageRequest(char *uuid, char *payload)
  11290. {
  11291. mtrace();
  11292. int result = FAIL;
  11293. int connectorIdIsNULL = FALSE;
  11294. int connectorIdInt =0;
  11295. char sstr[40]={0},sstrtemp[100]={ 0 };
  11296. char requestedMessagestr[40]={0};
  11297. char comfirmstr[20]={0};
  11298. int c = 0;
  11299. char *loc;
  11300. DEBUG_INFO("handleTriggerMessageRequest\n");
  11301. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  11302. strcpy(sstrtemp, stringtrimspace(payload));
  11303. c = 0;
  11304. loc = strstr(sstrtemp, "requestedMessage");
  11305. while (loc[3+strlen("requestedMessage")+c] != '\"')
  11306. {
  11307. sstr[c] = loc[3+strlen("requestedMessage")+c];
  11308. c++;
  11309. }
  11310. sstr[c] = '\0';
  11311. strcpy(requestedMessagestr, sstr);
  11312. c = 0;
  11313. loc = strstr(sstrtemp, "connectorId");
  11314. if(loc == NULL)
  11315. {
  11316. connectorIdIsNULL = TRUE;
  11317. }
  11318. else
  11319. {
  11320. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11321. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11322. {
  11323. sstr[c] = loc[strlen("connectorId")+2+c];
  11324. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11325. c++;
  11326. }
  11327. sstr[c] = '\0';
  11328. connectorIdInt = atoi(sstr);
  11329. }
  11330. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11331. {
  11332. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11333. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11334. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11335. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11336. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11337. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11338. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11339. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11340. {
  11341. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11342. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11343. return TRUE;
  11344. }
  11345. else
  11346. {
  11347. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11348. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11349. }
  11350. }
  11351. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11352. {
  11353. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11354. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11355. return TRUE;
  11356. }
  11357. //==========================
  11358. // Trigger message
  11359. //==========================
  11360. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11361. {
  11362. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11363. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11364. {
  11365. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11366. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11367. }
  11368. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11369. }
  11370. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11371. {
  11372. if(strlen((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status) == 0)
  11373. sprintf((char*)ShmOCPP16Data->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11374. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11375. }
  11376. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11377. {
  11378. //sendBootNotificationRequest();
  11379. server_sign = FALSE;
  11380. }
  11381. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11382. {
  11383. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11384. }
  11385. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11386. {
  11387. if(connectorIdIsNULL == FALSE)
  11388. {
  11389. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11390. {
  11391. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11392. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11393. }
  11394. }
  11395. else
  11396. {
  11397. for(int idx=0;idx< gunTotalNumber;idx++)
  11398. {
  11399. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11400. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11401. }
  11402. }
  11403. }
  11404. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11405. {
  11406. if(connectorIdIsNULL == FALSE)
  11407. {
  11408. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  11409. {
  11410. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11411. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = 1;
  11412. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11413. }
  11414. }
  11415. else
  11416. {
  11417. for(int idx=0;idx< gunTotalNumber;idx++)
  11418. {
  11419. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  11420. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11421. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11422. }
  11423. }
  11424. }
  11425. return result;
  11426. }
  11427. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11428. {
  11429. mtrace();
  11430. int result = FAIL;
  11431. int connectorIdInt =0;
  11432. char comfirmstr[20]={0};
  11433. int tempIndex = 0;
  11434. json_object *UnlockConnector;
  11435. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11436. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11437. UnlockConnector = json_tokener_parse(payload);
  11438. if(!is_error(UnlockConnector))
  11439. {
  11440. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11441. {
  11442. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11443. }
  11444. }
  11445. json_object_put(UnlockConnector);
  11446. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11447. if(gunTotalNumber == 0)
  11448. {
  11449. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11450. goto end;
  11451. }
  11452. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11453. {
  11454. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11455. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11456. goto end;
  11457. }
  11458. else
  11459. {
  11460. //check Transaction active
  11461. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11462. {
  11463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11464. {
  11465. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11466. }
  11467. else
  11468. {
  11469. tempIndex = connectorIdInt -1;
  11470. }
  11471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11472. {
  11473. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11474. {
  11475. //stop Transaction
  11476. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11477. }
  11478. }
  11479. }
  11480. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11481. {
  11482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11483. {
  11484. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11485. }
  11486. else
  11487. {
  11488. tempIndex = connectorIdInt -1;
  11489. }
  11490. for (int index = 0; index < CCS_QUANTITY; index++)
  11491. {
  11492. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11493. {
  11494. //stop Transaction
  11495. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11496. }
  11497. }
  11498. }
  11499. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11500. {
  11501. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11502. {
  11503. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11504. }
  11505. else
  11506. {
  11507. tempIndex = connectorIdInt -1;
  11508. }
  11509. for (int index = 0; index < GB_QUANTITY; index++)
  11510. {
  11511. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11512. {
  11513. //stop Transaction
  11514. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11515. }
  11516. }
  11517. }
  11518. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11519. {
  11520. tempIndex = connectorIdInt -1;
  11521. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11522. {
  11523. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  11524. {
  11525. //stop Transaction
  11526. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11527. }
  11528. }
  11529. }
  11530. else
  11531. {
  11532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11533. {
  11534. tempIndex = 2;
  11535. }
  11536. else
  11537. {
  11538. tempIndex = connectorIdInt-1;
  11539. }
  11540. for (int index = 0; index < AC_QUANTITY; index++)
  11541. {
  11542. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11543. {
  11544. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11545. }
  11546. }
  11547. }
  11548. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11549. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  11550. result = TRUE;
  11551. return result;
  11552. }
  11553. end:
  11554. //json_object_put(obj); --- remove temporally
  11555. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11556. return result;
  11557. }
  11558. static char UpdateFirmwarepayloadData[300]={0};
  11559. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11560. {
  11561. mtrace();
  11562. int result = FAIL;
  11563. pthread_t t;
  11564. sendUpdateFirmwareConfirmation(uuid);
  11565. memset(UpdateFirmwarepayloadData, 0, 300);
  11566. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11567. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11568. ////pthread_join(t, NULL); //
  11569. //pthread_detach(t);
  11570. //sendUpdateFirmwareConfirmation(uuid);
  11571. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  11572. return result;
  11573. }
  11574. void *UpdateFirmwareProcess(void *data)
  11575. {
  11576. pthread_detach(pthread_self());
  11577. mtrace();
  11578. int retriesInt =0, retryIntervalInt=0;
  11579. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  11580. int port=0;
  11581. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  11582. int isSuccess = 0;
  11583. char ftpbuf[1024];
  11584. char temp[1024];
  11585. char * pch;
  11586. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11587. json_object *UpdateFirmware;
  11588. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11589. if(!is_error(UpdateFirmware))
  11590. {
  11591. // Required data
  11592. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11593. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11594. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11595. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11596. // Optional data
  11597. if(json_object_object_get(UpdateFirmware, "retries"))
  11598. {
  11599. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11600. }
  11601. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11602. {
  11603. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11604. }
  11605. }
  11606. json_object_put(UpdateFirmware);
  11607. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11608. memset(path, 0, ARRAY_SIZE(path));
  11609. // Wait retrieveData
  11610. if(strlen(retrieveDatestr) > 10)
  11611. {
  11612. do
  11613. {
  11614. sleep(1);
  11615. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11616. }
  11617. // Ready to download
  11618. system("rm -f /mnt/*");
  11619. if(strncmp(locationstr,"http", 4) == 0)
  11620. {
  11621. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11622. sprintf(ftppath,"/%s", path);
  11623. DEBUG_INFO("locationstr: %s\n", locationstr);
  11624. DEBUG_INFO("protocol: %s\n",protocol);
  11625. DEBUG_INFO("host: %s\n",host);
  11626. DEBUG_INFO("path: %s\n",path);
  11627. DEBUG_INFO("ftppath: %s\n",ftppath);
  11628. int ftppathlen=strlen(ftppath);
  11629. int i=1;
  11630. char filenametemp[50];
  11631. while(i < ftppathlen)
  11632. {
  11633. int len=ftppathlen-i;
  11634. if(ftppath[len]== 47) // '/' ascll code: 47
  11635. {
  11636. DEBUG_INFO("compare '/' all right\n");
  11637. break;
  11638. }
  11639. i=i+1;
  11640. }
  11641. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11642. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11643. filenametemp[i+1] = 0;
  11644. do
  11645. {
  11646. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11647. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11648. sleep(1);
  11649. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11650. if(!isSuccess)
  11651. {
  11652. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11653. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11654. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11655. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11656. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11657. }
  11658. else
  11659. {
  11660. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11661. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11662. }
  11663. retriesInt--;
  11664. }while((isSuccess == 0)&&(retriesInt >= 0));
  11665. }
  11666. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11667. {
  11668. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11669. memset(temp, 0, ARRAY_SIZE(temp));
  11670. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11671. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11672. int ftppathlen=strlen(ftpbuf);
  11673. int i=1;
  11674. char filenametemp[50];
  11675. while(i < ftppathlen)
  11676. {
  11677. int len=ftppathlen-i;
  11678. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11679. {
  11680. DEBUG_INFO(" compare '/' all right\n");
  11681. break;
  11682. }
  11683. i=i+1;
  11684. }
  11685. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11686. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11687. filenametemp[i+1] = 0;
  11688. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11689. pch=strchr(temp,'@');
  11690. if(pch==NULL)
  11691. {
  11692. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11693. protocol, host, &port, path);
  11694. strcpy(user,"anonymous");
  11695. strcpy(password,"");
  11696. }
  11697. else
  11698. {
  11699. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11700. protocol, user, password, host, &port, path);
  11701. }
  11702. sscanf(host,"%[^/]%s",host1, path1);
  11703. sprintf(ftppath,"%s", path1);
  11704. //DEBUG_INFO("protocol =%s\n",protocol);
  11705. //DEBUG_INFO("user =%s\n",user);
  11706. //DEBUG_INFO("password =%s\n",password);
  11707. //DEBUG_INFO("host1 =%s\n",host1);
  11708. //DEBUG_INFO("port =%d\n",port);
  11709. //DEBUG_INFO("path1 =%s\n",path1);
  11710. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11711. //ftpFile(host, user, password, port, ftppath, fname);
  11712. //download firmware pthred
  11713. if(port == 0)
  11714. {
  11715. port = 21;
  11716. }
  11717. do
  11718. {
  11719. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11720. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11721. sleep(1);
  11722. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11723. if(!isSuccess)
  11724. {
  11725. //BulldogUtil.sleepMs(interval*1000);
  11726. DEBUG_INFO("Update firmware request and download file fail.\n");
  11727. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11728. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11729. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11730. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11731. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11732. }
  11733. else
  11734. {
  11735. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11736. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11737. }
  11738. retriesInt--;
  11739. }while((!isSuccess)&&(retriesInt >= 0));
  11740. }
  11741. else
  11742. {
  11743. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11744. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11745. sleep(1);
  11746. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11747. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11748. }
  11749. if(strstr((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  11750. pthread_exit(NULL);
  11751. }
  11752. int handleCertificateSignedRequest(char *uuid, char *payload)
  11753. {
  11754. mtrace();
  11755. int result = PASS;
  11756. json_object *CertificateSigned;
  11757. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11758. CertificateSigned = json_tokener_parse(payload);
  11759. if(!is_error(CertificateSigned))
  11760. {
  11761. sprintf((char*)ShmOCPP16Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11762. }
  11763. json_object_put(CertificateSigned);
  11764. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  11765. fprintf(fp, "%s", ShmOCPP16Data->CertificateSigned.certificateChain);
  11766. fclose(fp);
  11767. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11768. ShmOCPP16Data->MsMsg.bits.CertificateSignedReq = 1;
  11769. sprintf((char*)ShmOCPP16Data->CertificateSigned.Response_status, "Accepted");
  11770. sendCertificateSignedConfirmation(uuid);
  11771. return result;
  11772. }
  11773. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11774. {
  11775. mtrace();
  11776. int result = PASS;
  11777. json_object *DeleteCertificate;
  11778. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11779. DeleteCertificate = json_tokener_parse(payload);
  11780. if(!is_error(DeleteCertificate))
  11781. {
  11782. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11783. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11784. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11785. sprintf((char*)ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11786. }
  11787. json_object_put(DeleteCertificate);
  11788. /*
  11789. * TODO: Delete certificateSigned process
  11790. */
  11791. ShmOCPP16Data->MsMsg.bits.DeleteCertificateReq = 1;
  11792. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  11793. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerNameHash);
  11794. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  11795. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16Data->DeleteCertificate.certificateHashData.serialNumber);
  11796. sprintf((char*)ShmOCPP16Data->DeleteCertificate.Response_status, "NotFound");
  11797. sendDeleteCertificateConfirmation(uuid);
  11798. return result;
  11799. }
  11800. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11801. {
  11802. mtrace();
  11803. int result = PASS;
  11804. json_object *ExtendedTriggerMessage;
  11805. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11806. ExtendedTriggerMessage = json_tokener_parse(payload);
  11807. if(!is_error(ExtendedTriggerMessage))
  11808. {
  11809. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11810. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11811. {
  11812. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11813. }
  11814. else
  11815. {
  11816. ShmOCPP16Data->ExtendedTriggerMessage.connectorId = -1;
  11817. }
  11818. }
  11819. json_object_put(ExtendedTriggerMessage);
  11820. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage);
  11821. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16Data->ExtendedTriggerMessage.connectorId);
  11822. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16Data->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11823. {
  11824. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11825. }
  11826. else
  11827. {
  11828. if((strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11829. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11830. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11831. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11832. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11833. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11834. (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11835. {
  11836. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11837. }
  11838. else
  11839. {
  11840. sprintf((char*)ShmOCPP16Data->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11841. }
  11842. }
  11843. sendExtendedTriggerMessageConfirmation(uuid);
  11844. //==========================
  11845. // Trigger message
  11846. //==========================
  11847. if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11848. {
  11849. //sendBootNotificationRequest();
  11850. server_sign = FALSE;
  11851. }
  11852. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11853. {
  11854. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationReq = 1;
  11855. }
  11856. else if( strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11857. {
  11858. if((strlen((char*)ShmOCPP16Data->FirmwareStatusNotification.Status) == 0) ||
  11859. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11860. {
  11861. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11862. sprintf((char*)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11863. }
  11864. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11865. }
  11866. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11867. {
  11868. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  11869. }
  11870. else if (strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11871. {
  11872. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11873. {
  11874. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11875. }
  11876. else
  11877. {
  11878. for(int idx=0;idx< gunTotalNumber;idx++)
  11879. {
  11880. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11881. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11882. }
  11883. }
  11884. }
  11885. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11886. {
  11887. ShmOCPP16Data->SpMsg.bits.SignCertificateReq = 1;
  11888. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  11889. {
  11890. 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\" &");
  11891. }
  11892. }
  11893. else if(strcmp((char*)ShmOCPP16Data->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11894. {
  11895. if((ShmOCPP16Data->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16Data->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11896. {
  11897. cpinitateMsg.bits[ShmOCPP16Data->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11898. }
  11899. else
  11900. {
  11901. for(int idx=0;idx< gunTotalNumber;idx++)
  11902. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11903. }
  11904. }
  11905. return result;
  11906. }
  11907. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11908. {
  11909. mtrace();
  11910. int result = PASS;
  11911. json_object *GetInstalledCertificateIds;
  11912. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11913. GetInstalledCertificateIds = json_tokener_parse(payload);
  11914. if(!is_error(GetInstalledCertificateIds))
  11915. {
  11916. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11917. }
  11918. json_object_put(GetInstalledCertificateIds);
  11919. /*
  11920. * TODO: Return installed certificate process
  11921. */
  11922. ShmOCPP16Data->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11923. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16Data->GetInstalledCertificateIds.certificateType);
  11924. memset(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11925. sprintf((char*)ShmOCPP16Data->GetInstalledCertificateIds.Response_status, "NotFound");
  11926. sendGetInstalledCertificateIdsConfirmation(uuid);
  11927. return result;
  11928. }
  11929. int handleGetLogRequest(char *uuid, char *payload)
  11930. {
  11931. mtrace();
  11932. int result = PASS;
  11933. json_object *GetLog;
  11934. DEBUG_INFO("handleGetLogRequest...\n");
  11935. GetLog = json_tokener_parse(payload);
  11936. if(!is_error(GetLog))
  11937. {
  11938. sprintf((char*)ShmOCPP16Data->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11939. ShmOCPP16Data->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11940. if(json_object_object_get(GetLog, "retries") != NULL)
  11941. {
  11942. ShmOCPP16Data->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11943. }
  11944. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11945. {
  11946. ShmOCPP16Data->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11947. }
  11948. sprintf((char*)ShmOCPP16Data->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11949. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11950. {
  11951. sprintf((char*)ShmOCPP16Data->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11952. }
  11953. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11954. {
  11955. sprintf((char*)ShmOCPP16Data->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11956. }
  11957. }
  11958. json_object_put(GetLog);
  11959. /*
  11960. * TODO: Upload log process
  11961. */
  11962. ShmOCPP16Data->MsMsg.bits.GetLogReq = 1;
  11963. DEBUG_INFO("logType: %s\n", ShmOCPP16Data->GetLog.logType);
  11964. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->GetLog.requestId);
  11965. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->GetLog.retries);
  11966. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->GetLog.retryInterval);
  11967. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16Data->GetLog.log.remoteLocation);
  11968. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.oldestTimestamp);
  11969. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16Data->GetLog.log.latestTimestamp);
  11970. sprintf((char*)ShmOCPP16Data->GetLog.Response_status, "Rejected");
  11971. sendGetLogConfirmation(uuid);
  11972. return result;
  11973. }
  11974. int handleInstallCertificateRequest(char *uuid, char *payload)
  11975. {
  11976. mtrace();
  11977. int result = PASS;
  11978. json_object *InstallCertificate;
  11979. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11980. InstallCertificate = json_tokener_parse(payload);
  11981. if(!is_error(InstallCertificate))
  11982. {
  11983. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11984. sprintf((char*)ShmOCPP16Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11985. /*
  11986. * TODO: Install certificate process
  11987. */
  11988. ShmOCPP16Data->MsMsg.bits.InstallCertificateReq = 1;
  11989. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificateType);
  11990. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16Data->InstallCertificate.certificate);
  11991. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Rejected");
  11992. sendInstallCertificateConfirmation(uuid);
  11993. }
  11994. json_object_put(InstallCertificate);
  11995. return result;
  11996. }
  11997. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11998. {
  11999. mtrace();
  12000. int result = PASS;
  12001. json_object *SignedUpdateFirmware;
  12002. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  12003. SignedUpdateFirmware = json_tokener_parse(payload);
  12004. if(!is_error(SignedUpdateFirmware))
  12005. {
  12006. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  12007. {
  12008. ShmOCPP16Data->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  12009. }
  12010. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  12011. {
  12012. ShmOCPP16Data->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  12013. }
  12014. ShmOCPP16Data->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  12015. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  12016. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  12017. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  12018. {
  12019. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  12020. }
  12021. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  12022. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  12023. }
  12024. json_object_put(SignedUpdateFirmware);
  12025. /*
  12026. * TODO: Upgrade firmware process
  12027. */
  12028. ShmOCPP16Data->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  12029. DEBUG_INFO("retries: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retries);
  12030. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16Data->SignedUpdateFirmware.retryInterval);
  12031. DEBUG_INFO("requestId: %d\n", ShmOCPP16Data->SignedUpdateFirmware.requestId);
  12032. DEBUG_INFO("location: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.location);
  12033. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.retrieveDateTime);
  12034. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.installDateTime);
  12035. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signingCertificate);
  12036. DEBUG_INFO("signature: %s\n", ShmOCPP16Data->SignedUpdateFirmware.firmware.signature);
  12037. sprintf((char*)ShmOCPP16Data->SignedUpdateFirmware.Response_status, "Rejected");
  12038. sendInstallCertificateConfirmation(uuid);
  12039. return result;
  12040. }
  12041. int handleUnknownRequest(char *uuid, char *payload)
  12042. {
  12043. mtrace();
  12044. int result = PASS;
  12045. DEBUG_INFO("handleUnknownRequest...\n");
  12046. sendUnknownConfirmation(uuid);
  12047. result = PASS;
  12048. return result;
  12049. }
  12050. //==========================================
  12051. // Handle server response routine
  12052. //==========================================
  12053. void handleAuthorizeResponse(char *payload, int gun_index)
  12054. {
  12055. mtrace();
  12056. char expiryDatestr[30]={0};
  12057. char parentIdTagstr[20]={0};
  12058. char statusstr[20]={0};
  12059. int expiryDateISNULL=FALSE;
  12060. int parentIdTagISNULL=FALSE;
  12061. DEBUG_INFO("handleAuthorizeResponse...\n");
  12062. json_object *Authorize;
  12063. Authorize = json_tokener_parse(payload);
  12064. if(!is_error(Authorize))
  12065. {
  12066. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  12067. {
  12068. // Required data
  12069. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  12070. // Optional data
  12071. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  12072. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  12073. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  12074. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  12075. }
  12076. }
  12077. json_object_put(Authorize);
  12078. if(expiryDateISNULL == FALSE)
  12079. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  12080. if(parentIdTagISNULL == FALSE)
  12081. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  12082. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  12083. //Update idTag information to authorization cache if supproted
  12084. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  12085. {
  12086. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  12087. }
  12088. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  12089. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  12090. authorizeRetryTimes = 0;
  12091. }
  12092. void handleBootNotificationResponse(char *payload, int gun_index)
  12093. {
  12094. mtrace();
  12095. char statusStr[12]={0};
  12096. char currentTimeStr[30]={0};
  12097. int intervalInt = 0;
  12098. DEBUG_INFO("handleBootNotificationResponse...\n");
  12099. json_object *BootNotification;
  12100. BootNotification = json_tokener_parse(payload);
  12101. if(!is_error(BootNotification))
  12102. {
  12103. // Required data
  12104. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  12105. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  12106. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  12107. }
  12108. json_object_put(BootNotification);
  12109. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12110. BootNotificationInterval = intervalInt;
  12111. HeartBeatWaitTime = intervalInt;
  12112. //write back to ShmOCPP16Data->BootNotification
  12113. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  12114. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  12115. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  12116. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  12117. {
  12118. server_sign = TRUE;
  12119. server_pending =FALSE;
  12120. }
  12121. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  12122. {
  12123. server_pending = TRUE;
  12124. }
  12125. syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
  12126. srand(time(NULL));
  12127. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  12128. SetOcppConnStatus(TRUE);
  12129. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  12130. }
  12131. void handleDataTransferResponse(char *payload, int gun_index)
  12132. {
  12133. char sstr[160]={0};//sstr[200]={ 0 };
  12134. int c = 0;
  12135. char *loc;
  12136. DEBUG_INFO("handleDataTransferResponse ...\n");
  12137. loc = strstr(payload, "status");
  12138. c = 0;
  12139. while (loc[3+strlen("status")+c] != '\"')
  12140. {
  12141. sstr[c] = loc[3+strlen("status")+c];
  12142. c++;
  12143. }
  12144. sstr[c] = '\0';
  12145. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  12146. }
  12147. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  12148. {
  12149. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  12150. //struct json_object *obj;
  12151. // obj = json_tokener_parse(payload);
  12152. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  12153. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  12154. //No fields are defined.
  12155. }
  12156. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12157. {
  12158. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  12159. //struct json_object *obj;
  12160. // obj = json_tokener_parse(payload);
  12161. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  12162. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  12163. //No fields are defined.
  12164. }
  12165. void handleHeartbeatResponse(char *payload, int gun_index)
  12166. {
  12167. mtrace();
  12168. DEBUG_INFO("handleHeartbeatResponse...\n");
  12169. json_object *Heartbeat;
  12170. Heartbeat = json_tokener_parse(payload);
  12171. if(!is_error(Heartbeat))
  12172. {
  12173. // Required data
  12174. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  12175. }
  12176. json_object_put(Heartbeat);
  12177. if(FirstHeartBeat == 0)
  12178. {
  12179. FirstHeartBeat = 1;
  12180. DEBUG_INFO("FirstHeartBeat \n");
  12181. }
  12182. HeartBeatWithNOResponse = 0;
  12183. clientTime.Heartbeat=time((time_t*)NULL);
  12184. syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  12185. }
  12186. void handleMeterValuesResponse(char *payload, int gun_index)
  12187. {
  12188. mtrace();
  12189. DEBUG_INFO("handleMeterValuesResponse...\n");
  12190. }
  12191. void handleStartTransactionResponse(char *payload, int gun_index)
  12192. {
  12193. mtrace();
  12194. //int transactionIdInt = 0;
  12195. FILE *outfile;
  12196. char data[100]={0};
  12197. DEBUG_INFO("handleStartTransactionResponse...\n");
  12198. json_object *StartTransaction;
  12199. StartTransaction = json_tokener_parse(payload);
  12200. if(!is_error(StartTransaction))
  12201. {
  12202. // Required data
  12203. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  12204. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  12205. // Optional data
  12206. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  12207. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  12208. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12209. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  12210. }
  12211. json_object_put(StartTransaction);
  12212. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  12213. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  12214. //-----------Start : write to the Queue TransactionId file -----------------//
  12215. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  12216. {}
  12217. else
  12218. {
  12219. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  12220. if(log == NULL)
  12221. {
  12222. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  12223. return ;
  12224. }
  12225. else
  12226. {
  12227. fclose(log);
  12228. }
  12229. }
  12230. // open file for writing
  12231. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  12232. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  12233. {
  12234. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  12235. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  12236. fputs(data, outfile);
  12237. fclose (outfile);
  12238. }
  12239. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12240. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12241. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  12242. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  12243. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12244. }
  12245. void handleStatusNotificationResponse(char *payload, int gun_index)
  12246. {
  12247. mtrace();
  12248. DEBUG_INFO("handleStatusNotificationResponse...\n");
  12249. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  12250. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  12251. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  12252. }
  12253. void handleStopTransactionnResponse(char *payload, int gun_index)
  12254. {
  12255. mtrace();
  12256. DEBUG_INFO("handleStopTransactionnResponse...\n");
  12257. json_object *StopTransaction;
  12258. StopTransaction = json_tokener_parse(payload);
  12259. if(!is_error(StopTransaction))
  12260. {
  12261. // Optional data
  12262. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  12263. {
  12264. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  12265. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  12266. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  12267. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  12268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  12269. }
  12270. }
  12271. json_object_put(StopTransaction);
  12272. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  12273. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  12274. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  12275. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  12276. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  12277. }
  12278. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  12279. {
  12280. mtrace();
  12281. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  12282. ShmOCPP16Data->SpMsg.bits.LogStatusNotificationConf = 1;
  12283. }
  12284. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  12285. {
  12286. mtrace();
  12287. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  12288. ShmOCPP16Data->SpMsg.bits.SecurityEventNotificationConf = 1;
  12289. }
  12290. void handleSignCertificateResponse(char *payload, int gun_index)
  12291. {
  12292. mtrace();
  12293. DEBUG_INFO("handleSignCertificateResponse...\n");
  12294. json_object *SignCertificate;
  12295. SignCertificate = json_tokener_parse(payload);
  12296. if(!is_error(SignCertificate))
  12297. {
  12298. sprintf((char*)ShmOCPP16Data->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  12299. DEBUG_INFO("status: %s\n", ShmOCPP16Data->SignCertificate.Response_status);
  12300. }
  12301. json_object_put(SignCertificate);
  12302. ShmOCPP16Data->SpMsg.bits.SignCertificateConf = 1;
  12303. }
  12304. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  12305. {
  12306. mtrace();
  12307. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  12308. ShmOCPP16Data->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  12309. }
  12310. //==========================================
  12311. // Handle Error routine
  12312. //==========================================
  12313. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  12314. {
  12315. mtrace();
  12316. #ifdef SystemLogMessage
  12317. DEBUG_INFO("errorCode: %s\n", errorCode);
  12318. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12319. DEBUG_INFO("errorDetails: %s\n", payload);
  12320. #endif
  12321. }
  12322. //===============================================
  12323. // Common routine
  12324. //===============================================
  12325. int initialConfigurationTable(void)
  12326. {
  12327. //clock_t start_t, end_t, total_t;
  12328. FILE *fp;
  12329. FILE *outfile;
  12330. char str[512]={0};
  12331. char sstr[256]={0};
  12332. int c = 0;
  12333. char *loc;
  12334. int confVersion = 7;
  12335. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12336. //start_t = clock();
  12337. //printf("Starting of the program, start_t = %ld\n", start_t);
  12338. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12339. // Check configuration file size is correct
  12340. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))!=-1)
  12341. {
  12342. struct stat st;
  12343. stat("/Storage/OCPP/OCPPConfiguration", &st);
  12344. if(st.st_size < 3100)
  12345. {
  12346. system("rm -f /Storage/OCPP/OCPPConfiguration");
  12347. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12348. }
  12349. }
  12350. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  12351. {
  12352. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  12353. if(outfile == NULL)
  12354. {
  12355. DEBUG_INFO("Error opening file\n");
  12356. return FALSE;
  12357. }
  12358. /*Core Profile*/
  12359. //AllowOfflineTxForUnknownId
  12360. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12364. //AuthorizationCacheEnabled
  12365. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12369. //AuthorizeRemoteTxRequests
  12370. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12373. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12374. //BlinkRepeat
  12375. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12379. //ClockAlignedDataInterval
  12380. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12383. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12384. //ConnectionTimeOut
  12385. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12389. //GetConfigurationMaxKeys
  12390. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12394. // HeartbeatInterval
  12395. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12399. // LightIntensity
  12400. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12404. // LocalAuthorizeOffline
  12405. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12409. // LocalPreAuthorize
  12410. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12414. // MaxEnergyOnInvalidId
  12415. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12416. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12417. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12419. // MeterValuesAlignedData
  12420. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12422. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12423. 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" );
  12424. else
  12425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12427. // MeterValuesAlignedDataMaxLength
  12428. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12430. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12431. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12432. else
  12433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12434. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12435. // MeterValuesSampledData
  12436. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12439. 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" );
  12440. else
  12441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12442. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12443. // MeterValuesSampledDataMaxLength
  12444. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12445. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12446. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12448. else
  12449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12451. // MeterValueSampleInterval
  12452. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12453. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12455. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12456. // MinimumStatusDuration
  12457. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12459. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12460. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12461. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12462. // NumberOfConnectors
  12463. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12465. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12466. {
  12467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12468. }
  12469. else
  12470. {
  12471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12472. }
  12473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12474. // ResetRetries
  12475. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12479. // ConnectorPhaseRotation
  12480. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12481. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12483. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12484. // ConnectorPhaseRotationMaxLength
  12485. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12487. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12489. // StopTransactionOnEVSideDisconnect
  12490. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12493. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12494. // StopTransactionOnInvalidId
  12495. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12498. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12499. // StopTxnAlignedData
  12500. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12503. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12504. // StopTxnAlignedDataMaxLength
  12505. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12509. // StopTxnSampledData
  12510. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12512. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12514. else
  12515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12517. // StopTxnSampledDataMaxLength
  12518. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12520. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12521. {
  12522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12523. }
  12524. else
  12525. {
  12526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12527. }
  12528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12529. // SupportedFeatureProfiles
  12530. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12534. // SupportedFeatureProfilesMaxLength
  12535. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12539. // TransactionMessageAttempts
  12540. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12543. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12545. // TransactionMessageRetryInterval
  12546. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12549. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12551. // UnlockConnectorOnEVSideDisconnect
  12552. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12556. // WebSocketPingInterval
  12557. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12561. // QueueOffLineStartTransactionMessage
  12562. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12566. // AuthorizationKey
  12567. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12571. // SecurityProfile
  12572. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12576. // DefaultPrice
  12577. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12581. // CustomDisplayCostAndPrice
  12582. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12586. // CustomIdleFeeAfterStop
  12587. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12591. // TimeOffset
  12592. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  12593. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  12594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "+00:00" );
  12595. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  12596. // NextTimeOffsetTransitionDateTime
  12597. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  12598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  12599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, " " );
  12600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  12601. // TimeOffsetNextTransition
  12602. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  12603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  12604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "+00:00" );
  12605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  12606. // Configuration Version
  12607. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12610. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12611. //* Local Auth List Management Profile*/
  12612. #if 0
  12613. //For OCTT Test Case
  12614. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12617. #endif
  12618. #if 1
  12619. //LocalAuthListEnabled
  12620. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12624. #endif
  12625. //LocalAuthListMaxLength
  12626. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "100000" );
  12629. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12630. //SendLocalListMaxLength
  12631. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12635. //ReserveConnectorZeroSupported
  12636. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12640. //* Smart Charging Profile */
  12641. //ChargeProfileMaxStackLevel
  12642. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12645. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12646. // ChargingScheduleAllowedChargingRateUnit
  12647. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12651. // ChargingScheduleMaxPeriods
  12652. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12655. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12656. // ConnectorSwitch3to1PhaseSupported
  12657. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12661. // MaxChargingProfilesInstalled
  12662. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12666. fclose(outfile);
  12667. }
  12668. else
  12669. {
  12670. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  12671. char keystr[60]={0};
  12672. char readonlystr[10]={0};
  12673. char valuestr[256]={0};
  12674. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  12675. if(fp == NULL) {
  12676. DEBUG_INFO("Error opening file");
  12677. return FALSE;
  12678. }
  12679. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12680. {
  12681. //DEBUG_INFO("Get Configuration \n");
  12682. if(strlen(str) > 0)
  12683. {
  12684. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12685. //*************************key*********************************/
  12686. if(strstr(str, "key") != NULL)
  12687. {
  12688. loc = strstr(str, "key");
  12689. c = 0;
  12690. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12691. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12692. {
  12693. sstr[c] = loc[strlen("key")+3+c];
  12694. c++;
  12695. }
  12696. sstr[c] = '\0';
  12697. strcpy(keystr,sstr);
  12698. }
  12699. //*************************readonly*********************************/
  12700. if(strstr(str, "readonly") != NULL)
  12701. {
  12702. loc = strstr(str, "readonly");
  12703. c = 0;
  12704. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12705. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12706. {
  12707. sstr[c] = loc[strlen("readonly")+2+c];
  12708. c++;
  12709. }
  12710. sstr[c] = '\0';
  12711. strcpy(readonlystr,sstr);
  12712. }
  12713. //*************************value*********************************/
  12714. if(strstr(str, "value") != NULL)
  12715. {
  12716. loc = strstr(str, "value");
  12717. c = 0;
  12718. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12719. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12720. {
  12721. sstr[c] = loc[strlen("value")+3+c];
  12722. c++;
  12723. }
  12724. sstr[c] = '\0';
  12725. strcpy(valuestr,sstr);
  12726. }
  12727. // DEBUG_INFO("keystr=%s\n",keystr);
  12728. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12729. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12730. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12731. {
  12732. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12733. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12735. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12736. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12737. }
  12738. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12739. {
  12740. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12741. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12742. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12743. }
  12744. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12745. {
  12746. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12747. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12748. }
  12749. if(strcmp(keystr, "BlinkRepeat") == 0)
  12750. {
  12751. //Charger.BlinkRepeat = Integer.parseInt(value);
  12752. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12754. }
  12755. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12756. {
  12757. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12758. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12759. }
  12760. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12761. {
  12762. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12764. }
  12765. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12766. {
  12767. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12769. }
  12770. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12771. {
  12772. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12773. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12774. HeartBeatWaitTime = atoi(valuestr);
  12775. }
  12776. if(strcmp(keystr, "LightIntensity") == 0)
  12777. {
  12778. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12780. }
  12781. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12782. {
  12783. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12785. }
  12786. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12787. {
  12788. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12789. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12790. }
  12791. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12792. {
  12793. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12794. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12795. }
  12796. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12797. {
  12798. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12800. }
  12801. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12802. {
  12803. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12805. }
  12806. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12807. {
  12808. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12810. }
  12811. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12812. {
  12813. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12814. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12815. }
  12816. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12817. {
  12818. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12819. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12820. }
  12821. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12822. {
  12823. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12825. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12826. }
  12827. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12828. {
  12829. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12831. }
  12832. if(strcmp(keystr, "ResetRetries") == 0)
  12833. {
  12834. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12835. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12836. }
  12837. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12838. {
  12839. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12841. }
  12842. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12843. {
  12844. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12846. }
  12847. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12848. {
  12849. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12851. }
  12852. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12853. {
  12854. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12855. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12856. }
  12857. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12858. {
  12859. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12860. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12861. }
  12862. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12863. {
  12864. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12865. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12866. }
  12867. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12868. {
  12869. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12870. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12871. }
  12872. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12873. {
  12874. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12876. }
  12877. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12878. {
  12879. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12881. }
  12882. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12883. {
  12884. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12886. }
  12887. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12888. {
  12889. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12891. TransactionMessageAttemptsValue = atoi(valuestr);
  12892. }
  12893. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12894. {
  12895. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12896. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12897. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12898. }
  12899. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12900. {
  12901. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12903. }
  12904. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12905. {
  12906. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12908. }
  12909. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12910. {
  12911. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12912. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12913. }
  12914. if(strcmp(keystr, "AuthorizationKey") == 0)
  12915. {
  12916. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12917. //sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12919. }
  12920. if(strcmp(keystr, "SecurityProfile") == 0)
  12921. {
  12922. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  12924. }
  12925. if(strcmp(keystr, "DefaultPrice") == 0)
  12926. {
  12927. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12929. }
  12930. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12931. {
  12932. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12934. }
  12935. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12936. {
  12937. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12939. }
  12940. if(strcmp(keystr, "TimeOffset") == 0)
  12941. {
  12942. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12943. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", valuestr);
  12944. }
  12945. if(strcmp(keystr, "NextTimeOffsetTransitionDateTime") == 0)
  12946. {
  12947. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", valuestr);
  12949. }
  12950. if(strcmp(keystr, "TimeOffsetNextTransition") == 0)
  12951. {
  12952. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", valuestr);
  12954. }
  12955. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12956. {
  12957. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12959. }
  12960. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12961. {
  12962. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12964. }
  12965. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12966. {
  12967. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12969. }
  12970. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12971. {
  12972. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12974. }
  12975. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12976. {
  12977. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12979. }
  12980. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12981. {
  12982. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12984. }
  12985. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12986. {
  12987. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12989. }
  12990. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12991. {
  12992. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12994. }
  12995. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12996. {
  12997. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12999. }
  13000. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  13001. {
  13002. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  13003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  13004. }
  13005. }
  13006. }
  13007. fclose(fp);
  13008. }
  13009. if(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  13010. {
  13011. return PASS;
  13012. }
  13013. else
  13014. {
  13015. return FAIL;
  13016. }
  13017. }
  13018. void StoreConfigurationTable(void)
  13019. {
  13020. FILE *outfile;
  13021. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  13022. if(outfile == NULL)
  13023. {
  13024. DEBUG_INFO("Error opening file");
  13025. return ;
  13026. }
  13027. /*Core Profile*/
  13028. //AllowOfflineTxForUnknownId
  13029. /*
  13030. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  13031. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  13032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  13033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  13034. */
  13035. //DEBUG_INFO("data=%s\n",data);
  13036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  13037. //AuthorizationCacheEnabled
  13038. /*
  13039. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  13040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  13041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  13042. */
  13043. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  13044. //AuthorizeRemoteTxRequests
  13045. /*
  13046. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  13047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  13048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  13049. */
  13050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  13051. //BlinkRepeat
  13052. /*
  13053. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  13054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  13055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  13056. */
  13057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  13058. //ClockAlignedDataInterval
  13059. /*
  13060. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  13061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  13062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  13063. */
  13064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  13065. //ConnectionTimeOut
  13066. /*
  13067. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  13068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  13069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  13070. */
  13071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  13072. //GetConfigurationMaxKeys
  13073. /*
  13074. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  13075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  13076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  13077. */
  13078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  13079. // HeartbeatInterval
  13080. /*
  13081. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  13082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  13083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  13084. */
  13085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  13086. // LightIntensity
  13087. /*
  13088. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  13089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  13090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  13091. */
  13092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  13093. // LocalAuthorizeOffline
  13094. /*
  13095. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  13096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  13097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  13098. */
  13099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13100. // LocalPreAuthorize
  13101. /*
  13102. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  13103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  13104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  13105. */
  13106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  13107. // MaxEnergyOnInvalidId
  13108. /*
  13109. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  13110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  13111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  13112. */
  13113. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  13114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  13115. // MeterValuesAlignedData
  13116. /*
  13117. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  13118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  13119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13120. */
  13121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  13122. // MeterValuesAlignedDataMaxLength
  13123. /*
  13124. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  13125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  13126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  13127. */
  13128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  13129. // MeterValuesSampledData
  13130. /*
  13131. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  13132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  13133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  13134. */
  13135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  13136. // MeterValuesSampledDataMaxLength
  13137. /*
  13138. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  13139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  13140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  13141. */
  13142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  13143. // MeterValueSampleInterval
  13144. /*
  13145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  13146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  13147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  13148. */
  13149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  13150. // MinimumStatusDuration
  13151. /*
  13152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  13153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  13154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  13155. */
  13156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  13157. // NumberOfConnectors
  13158. /*
  13159. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  13160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  13161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13162. {
  13163. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  13164. }
  13165. else
  13166. {
  13167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  13168. }
  13169. */
  13170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  13171. // ResetRetries
  13172. /*
  13173. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  13174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  13175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  13176. */
  13177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  13178. // ConnectorPhaseRotation
  13179. /*
  13180. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  13181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  13182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  13183. */
  13184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  13185. // ConnectorPhaseRotationMaxLength
  13186. /*
  13187. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  13188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  13189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  13190. */
  13191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  13192. // StopTransactionOnEVSideDisconnect
  13193. /*
  13194. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  13195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  13196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  13197. */
  13198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  13199. // StopTransactionOnInvalidId
  13200. /*
  13201. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  13202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  13203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  13204. */
  13205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  13206. // StopTxnAlignedData
  13207. /*
  13208. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  13209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  13210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  13211. */
  13212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  13213. // StopTxnAlignedDataMaxLength
  13214. /*
  13215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  13216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  13217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  13218. */
  13219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  13220. // StopTxnSampledData
  13221. /*
  13222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  13223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  13224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  13225. */
  13226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  13227. // StopTxnSampledDataMaxLength
  13228. /*
  13229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  13230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  13231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  13232. */
  13233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  13234. // SupportedFeatureProfiles
  13235. /*
  13236. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  13237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  13238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  13239. */
  13240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  13241. // SupportedFeatureProfilesMaxLength
  13242. /*
  13243. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  13244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  13245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  13246. */
  13247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  13248. // TransactionMessageAttempts
  13249. /*
  13250. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  13251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  13252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  13253. */
  13254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13255. // TransactionMessageRetryInterval
  13256. /*
  13257. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  13258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  13259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  13260. */
  13261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13262. // UnlockConnectorOnEVSideDisconnect
  13263. /*
  13264. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  13265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  13266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  13267. */
  13268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  13269. // WebSocketPingInterval
  13270. /*
  13271. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  13272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  13273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  13274. */
  13275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13276. // QueueOffLineStartTransactionMessage
  13277. /*
  13278. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  13279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  13280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  13281. */
  13282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  13283. // AuthorizationKey
  13284. /*
  13285. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  13286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  13287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  13288. */
  13289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13290. // SecurityProfile
  13291. /*
  13292. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  13293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  13294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  13295. */
  13296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13297. // DefaultPrice
  13298. /*
  13299. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  13300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  13301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  13302. */
  13303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  13304. // CustomDisplayCostAndPrice
  13305. /*
  13306. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  13307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  13308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  13309. */
  13310. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  13311. // CustomIdleFeeAfterStop
  13312. /*
  13313. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  13314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  13315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  13316. */
  13317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  13318. // TimeOffset
  13319. /*
  13320. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility = 1;
  13321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemName, "TimeOffset");
  13322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "FALSE" );
  13323. */
  13324. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffset", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData);
  13325. // NextTimeOffsetTransitionDateTime
  13326. /*
  13327. ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility = 1;
  13328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemName, "NextTimeOffsetTransitionDateTime");
  13329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "FALSE" );
  13330. */
  13331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NextTimeOffsetTransitionDateTime", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData);
  13332. // TimeOffsetNextTransition
  13333. /*
  13334. ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility = 1;
  13335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemName, "TimeOffsetNextTransition");
  13336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "FALSE" );
  13337. */
  13338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TimeOffsetNextTransition", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData);
  13339. // ConfigurationVersion
  13340. /*
  13341. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  13342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  13343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  13344. */
  13345. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  13346. //* Local Auth List Management Profile*/
  13347. //LocalAuthListEnabled
  13348. /*
  13349. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  13350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  13351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  13352. */
  13353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13354. //LocalAuthListMaxLength
  13355. /*
  13356. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  13357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  13358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  13359. */
  13360. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  13361. //SendLocalListMaxLength
  13362. /*
  13363. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  13364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13366. */
  13367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13368. //ReserveConnectorZeroSupported
  13369. /*
  13370. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13373. */
  13374. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13375. //* Smart Charging Profile */
  13376. //ChargeProfileMaxStackLevel
  13377. /*
  13378. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13381. */
  13382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13383. // ChargingScheduleAllowedChargingRateUnit
  13384. /*
  13385. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13388. */
  13389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13390. // ChargingScheduleMaxPeriods
  13391. /*
  13392. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13395. */
  13396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13397. // ConnectorSwitch3to1PhaseSupported
  13398. /*
  13399. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13402. */
  13403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13404. // MaxChargingProfilesInstalled
  13405. /*
  13406. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13409. */
  13410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13411. fclose(outfile);
  13412. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13413. }
  13414. void getKeyValue(char *keyReq)
  13415. {
  13416. int isEmpty = FALSE;
  13417. int isKnowKey = FALSE;
  13418. DEBUG_INFO("keyReq = %s\n", keyReq);
  13419. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13420. isEmpty = TRUE;
  13421. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13422. {
  13423. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13425. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13426. {
  13427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13428. }
  13429. else
  13430. {
  13431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13432. }
  13433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13434. isKnowKey = TRUE;
  13435. }
  13436. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13437. {
  13438. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13440. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13441. {
  13442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13443. }
  13444. else
  13445. {
  13446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13447. }
  13448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13449. isKnowKey = TRUE;
  13450. }
  13451. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13452. {
  13453. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13455. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13456. {
  13457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13458. }
  13459. else
  13460. {
  13461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13462. }
  13463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13464. isKnowKey = TRUE;
  13465. }
  13466. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13467. {
  13468. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13470. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13471. {
  13472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13473. }
  13474. else
  13475. {
  13476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13477. }
  13478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13479. isKnowKey = TRUE;
  13480. }
  13481. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13482. {
  13483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13485. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13486. {
  13487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13488. }
  13489. else
  13490. {
  13491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13492. }
  13493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13494. isKnowKey = TRUE;
  13495. }
  13496. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13497. {
  13498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13500. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13501. {
  13502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13503. }
  13504. else
  13505. {
  13506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13507. }
  13508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13509. isKnowKey = TRUE;
  13510. }
  13511. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13512. {
  13513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13515. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13516. {
  13517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13518. }
  13519. else
  13520. {
  13521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13522. }
  13523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13524. isKnowKey = TRUE;
  13525. }
  13526. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13527. {
  13528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13530. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13531. {
  13532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13533. }
  13534. else
  13535. {
  13536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13537. }
  13538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13539. isKnowKey = TRUE;
  13540. }
  13541. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13542. {
  13543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13546. {
  13547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13548. }
  13549. else
  13550. {
  13551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13552. }
  13553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13554. isKnowKey = TRUE;
  13555. }
  13556. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13557. {
  13558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13561. {
  13562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13563. }
  13564. else
  13565. {
  13566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13567. }
  13568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13569. isKnowKey = TRUE;
  13570. }
  13571. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13572. {
  13573. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13575. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13576. {
  13577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13578. }
  13579. else
  13580. {
  13581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13582. }
  13583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13584. isKnowKey = TRUE;
  13585. }
  13586. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13587. {
  13588. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13591. {
  13592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13593. }
  13594. else
  13595. {
  13596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13597. }
  13598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13599. isKnowKey = TRUE;
  13600. }
  13601. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13602. {
  13603. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13605. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13606. {
  13607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13608. }
  13609. else
  13610. {
  13611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13612. }
  13613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13614. isKnowKey = TRUE;
  13615. }
  13616. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13617. {
  13618. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13620. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13621. {
  13622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13623. }
  13624. else
  13625. {
  13626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13627. }
  13628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13629. isKnowKey = TRUE;
  13630. }
  13631. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13632. {
  13633. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13635. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13636. {
  13637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13638. }
  13639. else
  13640. {
  13641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13642. }
  13643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13644. isKnowKey = TRUE;
  13645. }
  13646. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13647. {
  13648. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13651. {
  13652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13653. }
  13654. else
  13655. {
  13656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13657. }
  13658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13659. isKnowKey = TRUE;
  13660. }
  13661. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13662. {
  13663. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13666. {
  13667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13668. }
  13669. else
  13670. {
  13671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13672. }
  13673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13674. isKnowKey = TRUE;
  13675. }
  13676. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13677. {
  13678. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13680. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13681. {
  13682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13683. }
  13684. else
  13685. {
  13686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13687. }
  13688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  13689. isKnowKey = TRUE;
  13690. }
  13691. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13692. {
  13693. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13695. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13696. {
  13697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13698. }
  13699. else
  13700. {
  13701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13702. }
  13703. sprintf((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13705. isKnowKey = TRUE;
  13706. }
  13707. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13708. {
  13709. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13711. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13712. {
  13713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13714. }
  13715. else
  13716. {
  13717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13718. }
  13719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13720. isKnowKey = TRUE;
  13721. }
  13722. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13723. {
  13724. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13726. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13727. {
  13728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13729. }
  13730. else
  13731. {
  13732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13733. }
  13734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13735. isKnowKey = TRUE;
  13736. }
  13737. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13738. {
  13739. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13742. {
  13743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13744. }
  13745. else
  13746. {
  13747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13748. }
  13749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13750. isKnowKey = TRUE;
  13751. }
  13752. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13753. {
  13754. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13757. {
  13758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13759. }
  13760. else
  13761. {
  13762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13763. }
  13764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13765. isKnowKey = TRUE;
  13766. }
  13767. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13768. {
  13769. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13772. {
  13773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13774. }
  13775. else
  13776. {
  13777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13778. }
  13779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13780. isKnowKey = TRUE;
  13781. }
  13782. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13783. {
  13784. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13787. {
  13788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13789. }
  13790. else
  13791. {
  13792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13793. }
  13794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13795. isKnowKey = TRUE;
  13796. }
  13797. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13798. {
  13799. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13801. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13802. {
  13803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13804. }
  13805. else
  13806. {
  13807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13808. }
  13809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13810. isKnowKey = TRUE;
  13811. }
  13812. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13813. {
  13814. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13817. {
  13818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13819. }
  13820. else
  13821. {
  13822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13823. }
  13824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13825. isKnowKey = TRUE;
  13826. }
  13827. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13828. {
  13829. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13832. {
  13833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13834. }
  13835. else
  13836. {
  13837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13838. }
  13839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13840. isKnowKey = TRUE;
  13841. }
  13842. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13843. {
  13844. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13847. {
  13848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13849. }
  13850. else
  13851. {
  13852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13853. }
  13854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13855. isKnowKey = TRUE;
  13856. }
  13857. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13858. {
  13859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13862. {
  13863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13864. }
  13865. else
  13866. {
  13867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13868. }
  13869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13870. isKnowKey = TRUE;
  13871. }
  13872. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13873. {
  13874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13877. {
  13878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13879. }
  13880. else
  13881. {
  13882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13883. }
  13884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13885. isKnowKey = TRUE;
  13886. }
  13887. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13888. {
  13889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13892. {
  13893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13894. }
  13895. else
  13896. {
  13897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13898. }
  13899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13900. isKnowKey = TRUE;
  13901. }
  13902. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13903. {
  13904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13907. {
  13908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13909. }
  13910. else
  13911. {
  13912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13913. }
  13914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13915. isKnowKey = TRUE;
  13916. }
  13917. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13918. {
  13919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13922. {
  13923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13924. }
  13925. else
  13926. {
  13927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13928. }
  13929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13930. isKnowKey = TRUE;
  13931. }
  13932. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13933. {
  13934. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13935. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13936. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13937. {
  13938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13939. }
  13940. else
  13941. {
  13942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13943. }
  13944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13945. isKnowKey = TRUE;
  13946. }
  13947. /*
  13948. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13949. {
  13950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13953. {
  13954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13955. }
  13956. else
  13957. {
  13958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13959. }
  13960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13961. isKnowKey = TRUE;
  13962. }*/
  13963. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13964. {
  13965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13968. {
  13969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13970. }
  13971. else
  13972. {
  13973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13974. }
  13975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13976. isKnowKey = TRUE;
  13977. }
  13978. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13979. {
  13980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13983. {
  13984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13985. }
  13986. else
  13987. {
  13988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13989. }
  13990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13991. isKnowKey = TRUE;
  13992. }
  13993. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13994. {
  13995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13998. {
  13999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  14000. }
  14001. else
  14002. {
  14003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  14004. }
  14005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  14006. isKnowKey = TRUE;
  14007. }
  14008. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  14009. {
  14010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  14011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  14012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14013. {
  14014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  14015. }
  14016. else
  14017. {
  14018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  14019. }
  14020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  14021. isKnowKey = TRUE;
  14022. }
  14023. if(isEmpty || strcmp(keyReq, "TimeOffset") == 0 )
  14024. {
  14025. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffset].Item, "TimeOffset");
  14026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Key, "TimeOffset");
  14027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  14028. {
  14029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "0"/*"FALSE"*/);
  14030. }
  14031. else
  14032. {
  14033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].ReadOnly, "1"/*"TRUE"*/);
  14034. }
  14035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffset].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData );
  14036. isKnowKey = TRUE;
  14037. }
  14038. if(isEmpty || strcmp(keyReq, "NextTimeOffsetTransitionDateTime") == 0 )
  14039. {
  14040. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NextTimeOffsetTransitionDateTime].Item, "NextTimeOffsetTransitionDateTime");
  14041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Key, "NextTimeOffsetTransitionDateTime");
  14042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  14043. {
  14044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "0"/*"FALSE"*/);
  14045. }
  14046. else
  14047. {
  14048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].ReadOnly, "1"/*"TRUE"*/);
  14049. }
  14050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NextTimeOffsetTransitionDateTime].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData );
  14051. isKnowKey = TRUE;
  14052. }
  14053. if(isEmpty || strcmp(keyReq, "TimeOffsetNextTransition") == 0 )
  14054. {
  14055. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TimeOffsetNextTransition].Item, "TimeOffsetNextTransition");
  14056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Key, "TimeOffsetNextTransition");
  14057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  14058. {
  14059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "0"/*"FALSE"*/);
  14060. }
  14061. else
  14062. {
  14063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].ReadOnly, "1"/*"TRUE"*/);
  14064. }
  14065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TimeOffsetNextTransition].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData );
  14066. isKnowKey = TRUE;
  14067. }
  14068. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  14069. {
  14070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  14071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  14072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  14073. {
  14074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  14075. }
  14076. else
  14077. {
  14078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  14079. }
  14080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  14081. isKnowKey = TRUE;
  14082. }
  14083. #if 1
  14084. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  14085. {
  14086. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  14087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  14088. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14089. {
  14090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  14091. }
  14092. else
  14093. {
  14094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  14095. }
  14096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  14097. isKnowKey = TRUE;
  14098. }
  14099. #endif
  14100. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  14101. {
  14102. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  14103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  14104. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14105. {
  14106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14107. }
  14108. else
  14109. {
  14110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14111. }
  14112. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  14113. isKnowKey = TRUE;
  14114. }
  14115. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  14116. {
  14117. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  14118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  14119. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14120. {
  14121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  14122. }
  14123. else
  14124. {
  14125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  14126. }
  14127. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  14128. isKnowKey = TRUE;
  14129. }
  14130. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  14131. {
  14132. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  14133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  14134. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14135. {
  14136. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  14137. }
  14138. else
  14139. {
  14140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  14141. }
  14142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  14143. isKnowKey = TRUE;
  14144. }
  14145. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  14146. {
  14147. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  14148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  14149. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14150. {
  14151. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  14152. }
  14153. else
  14154. {
  14155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  14156. }
  14157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  14158. isKnowKey = TRUE;
  14159. }
  14160. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  14161. {
  14162. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  14163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  14164. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14165. {
  14166. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  14167. }
  14168. else
  14169. {
  14170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  14171. }
  14172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  14173. isKnowKey = TRUE;
  14174. }
  14175. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  14176. {
  14177. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  14178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  14179. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14180. {
  14181. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  14182. }
  14183. else
  14184. {
  14185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  14186. }
  14187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  14188. isKnowKey = TRUE;
  14189. }
  14190. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  14191. {
  14192. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  14193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  14194. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14195. {
  14196. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  14197. }
  14198. else
  14199. {
  14200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  14201. }
  14202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  14203. isKnowKey = TRUE;
  14204. }
  14205. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  14206. {
  14207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  14208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  14209. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14210. {
  14211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  14212. }
  14213. else
  14214. {
  14215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  14216. }
  14217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  14218. isKnowKey = TRUE;
  14219. }
  14220. //=========================================================
  14221. if(!isEmpty && !isKnowKey)
  14222. {
  14223. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  14224. strcpy(unknownkey[UnknownKeynum], keyReq);
  14225. UnknownKeynum = UnknownKeynum + 1;
  14226. }
  14227. }
  14228. void processUnkownKey(void)
  14229. {
  14230. DEBUG_INFO("processUnkownKey...\n");
  14231. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  14232. for(int index=0; index < UnknownKeynum; index++)
  14233. {
  14234. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  14235. {
  14236. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  14237. }
  14238. }
  14239. }
  14240. int setKeyValue(char *key, char *value)
  14241. {
  14242. int isSuccess = NotSupported;
  14243. int check_ascii=0;
  14244. char str[256]={0};
  14245. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  14246. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  14247. {
  14248. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  14249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  14250. {
  14251. strcpy(str, (const char*)value);
  14252. for(int i = 0; str[i]; i++){
  14253. str[i] = tolower(str[i]);
  14254. }
  14255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14256. isSuccess = ConfigurationStatus_Accepted;
  14257. }
  14258. else
  14259. {
  14260. isSuccess = ConfigurationStatus_Rejected;
  14261. }
  14262. }
  14263. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  14264. {
  14265. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  14266. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  14267. {
  14268. strcpy(str, (const char*)value);
  14269. for(int i = 0; str[i]; i++){
  14270. str[i] = tolower(str[i]);
  14271. }
  14272. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14273. isSuccess = ConfigurationStatus_Accepted;
  14274. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  14275. }
  14276. else
  14277. {
  14278. isSuccess = ConfigurationStatus_Rejected;
  14279. }
  14280. }
  14281. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  14282. {
  14283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  14284. {
  14285. strcpy(str, (const char*)value);
  14286. for(int i = 0; str[i]; i++)
  14287. {
  14288. str[i] = tolower(str[i]);
  14289. }
  14290. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  14291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14292. isSuccess = ConfigurationStatus_Accepted;
  14293. }
  14294. else
  14295. {
  14296. isSuccess = ConfigurationStatus_Rejected;
  14297. }
  14298. }
  14299. if(strcmp(key, "BlinkRepeat") == 0)
  14300. {
  14301. //Charger.BlinkRepeat = Integer.parseInt(value);
  14302. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  14303. {
  14304. check_ascii = value[0];
  14305. if( (check_ascii < 48) || (check_ascii > 57) )
  14306. {
  14307. isSuccess = ConfigurationStatus_Rejected;
  14308. }
  14309. else
  14310. {
  14311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  14312. isSuccess = ConfigurationStatus_Accepted;
  14313. }
  14314. }
  14315. else
  14316. {
  14317. isSuccess = ConfigurationStatus_Rejected;
  14318. }
  14319. }
  14320. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  14321. {
  14322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  14323. {
  14324. check_ascii = value[0];
  14325. if( (check_ascii < 48) || (check_ascii > 57) )
  14326. {
  14327. isSuccess = ConfigurationStatus_Rejected;
  14328. }
  14329. else
  14330. {
  14331. if((atoi(value) == 0) || (atoi(value) >= 10))
  14332. {
  14333. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  14334. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  14335. isSuccess = ConfigurationStatus_Accepted;
  14336. }
  14337. else
  14338. isSuccess = ConfigurationStatus_Rejected;
  14339. }
  14340. }
  14341. else
  14342. {
  14343. isSuccess = ConfigurationStatus_Rejected;
  14344. }
  14345. }
  14346. if(strcmp(key, "ConnectionTimeOut") == 0 )
  14347. {
  14348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  14349. {
  14350. check_ascii = value[0];
  14351. if( (check_ascii < 48) || (check_ascii > 57) )
  14352. {
  14353. isSuccess = ConfigurationStatus_Rejected;
  14354. }
  14355. else
  14356. {
  14357. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  14358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  14359. isSuccess = ConfigurationStatus_Accepted;
  14360. }
  14361. }
  14362. else
  14363. {
  14364. isSuccess = ConfigurationStatus_Rejected;
  14365. }
  14366. }
  14367. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  14368. {
  14369. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  14370. {
  14371. check_ascii = value[0];
  14372. if( (check_ascii < 48) || (check_ascii > 57) )
  14373. {
  14374. isSuccess = ConfigurationStatus_Rejected;
  14375. }
  14376. else
  14377. {
  14378. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  14380. isSuccess = ConfigurationStatus_Accepted;
  14381. }
  14382. }
  14383. else
  14384. {
  14385. isSuccess = ConfigurationStatus_Rejected;
  14386. }
  14387. }
  14388. if(strcmp(key, "HeartbeatInterval") == 0)
  14389. {
  14390. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  14391. {
  14392. check_ascii = value[0];
  14393. if( (check_ascii < 48) || (check_ascii > 57) )
  14394. {
  14395. isSuccess = ConfigurationStatus_Rejected;
  14396. }
  14397. else
  14398. {
  14399. if((atoi(value) == 0) || (atoi(value) >= 10))
  14400. {
  14401. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  14402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  14403. HeartBeatWaitTime = atoi(value);
  14404. isSuccess = ConfigurationStatus_Accepted;
  14405. }
  14406. else
  14407. {
  14408. isSuccess = ConfigurationStatus_Rejected;
  14409. }
  14410. }
  14411. }
  14412. else
  14413. {
  14414. isSuccess = ConfigurationStatus_Rejected;
  14415. }
  14416. }
  14417. if(strcmp(key, "LightIntensity") == 0)
  14418. {
  14419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14420. {
  14421. check_ascii = value[0];
  14422. if( (check_ascii < 48) || (check_ascii > 57) )
  14423. {
  14424. isSuccess = ConfigurationStatus_Rejected;
  14425. }
  14426. else
  14427. {
  14428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14429. isSuccess = ConfigurationStatus_Accepted;
  14430. }
  14431. }
  14432. else
  14433. {
  14434. isSuccess = ConfigurationStatus_Rejected;
  14435. }
  14436. }
  14437. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14438. {
  14439. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14440. {
  14441. strcpy(str, (const char*)value);
  14442. for(int i = 0; str[i]; i++)
  14443. {
  14444. str[i] = tolower(str[i]);
  14445. }
  14446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14447. isSuccess = ConfigurationStatus_Accepted;
  14448. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14449. }
  14450. else
  14451. {
  14452. isSuccess = ConfigurationStatus_Rejected;
  14453. }
  14454. }
  14455. if(strcmp(key, "LocalPreAuthorize") == 0)
  14456. {
  14457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14458. {
  14459. strcpy(str, (const char*)value);
  14460. for(int i = 0; str[i]; i++)
  14461. {
  14462. str[i] = tolower(str[i]);
  14463. }
  14464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14465. isSuccess = ConfigurationStatus_Accepted;
  14466. }
  14467. else
  14468. {
  14469. isSuccess = ConfigurationStatus_Rejected;
  14470. }
  14471. }
  14472. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14473. {
  14474. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14475. {
  14476. check_ascii = value[0];
  14477. if( (check_ascii < 48) || (check_ascii > 57) )
  14478. {
  14479. isSuccess = ConfigurationStatus_Rejected;
  14480. }
  14481. else
  14482. {
  14483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14484. isSuccess = ConfigurationStatus_Accepted;
  14485. }
  14486. }
  14487. else
  14488. {
  14489. isSuccess = ConfigurationStatus_Rejected;
  14490. }
  14491. }
  14492. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14493. {
  14494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14495. {
  14496. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14497. isSuccess = ConfigurationStatus_Accepted;
  14498. }
  14499. else
  14500. {
  14501. isSuccess = ConfigurationStatus_Rejected;
  14502. }
  14503. }
  14504. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14505. {
  14506. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14507. {
  14508. check_ascii = value[0];
  14509. if( (check_ascii < 48) || (check_ascii > 57) )
  14510. {
  14511. isSuccess = ConfigurationStatus_Rejected;
  14512. }
  14513. else
  14514. {
  14515. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14517. isSuccess = ConfigurationStatus_Accepted;
  14518. }
  14519. }
  14520. else
  14521. {
  14522. isSuccess = ConfigurationStatus_Rejected;
  14523. }
  14524. }
  14525. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14526. {
  14527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14528. {
  14529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14530. isSuccess = ConfigurationStatus_Accepted;
  14531. }
  14532. else
  14533. {
  14534. isSuccess = ConfigurationStatus_Rejected;
  14535. }
  14536. }
  14537. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14538. {
  14539. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14540. {
  14541. check_ascii = value[0];
  14542. if( (check_ascii < 48) || (check_ascii > 57) )
  14543. {
  14544. isSuccess = ConfigurationStatus_Rejected;
  14545. }
  14546. else
  14547. {
  14548. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14550. isSuccess = ConfigurationStatus_Accepted;
  14551. }
  14552. }
  14553. else
  14554. {
  14555. isSuccess = ConfigurationStatus_Rejected;
  14556. }
  14557. }
  14558. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14559. {
  14560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14561. {
  14562. check_ascii = value[0];
  14563. if( (check_ascii < 48) || (check_ascii > 57) )
  14564. {
  14565. isSuccess = ConfigurationStatus_Rejected;
  14566. }
  14567. else
  14568. {
  14569. if((atoi(value) == 0) || (atoi(value) >= 10))
  14570. {
  14571. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14573. isSuccess = ConfigurationStatus_Accepted;
  14574. }
  14575. else
  14576. {
  14577. isSuccess = ConfigurationStatus_Rejected;
  14578. }
  14579. }
  14580. }
  14581. else
  14582. {
  14583. isSuccess = ConfigurationStatus_Rejected;
  14584. }
  14585. }
  14586. if(strcmp(key, "MinimumStatusDuration") == 0)
  14587. {
  14588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14589. {
  14590. check_ascii = value[0];
  14591. if( (check_ascii < 48) || (check_ascii > 57) )
  14592. {
  14593. isSuccess = ConfigurationStatus_Rejected;
  14594. }
  14595. else
  14596. {
  14597. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14598. {
  14599. isSuccess = ConfigurationStatus_Rejected;
  14600. }
  14601. else
  14602. {
  14603. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14605. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14606. isSuccess = ConfigurationStatus_Accepted;
  14607. }
  14608. }
  14609. }
  14610. else
  14611. {
  14612. isSuccess = ConfigurationStatus_Rejected;
  14613. }
  14614. }
  14615. if(strcmp(key, "NumberOfConnectors") == 0)
  14616. {
  14617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14618. {
  14619. check_ascii = value[0];
  14620. if( (check_ascii < 48) || (check_ascii > 57) )
  14621. {
  14622. isSuccess = ConfigurationStatus_Rejected;
  14623. }
  14624. else
  14625. {
  14626. //Charger.ResetRetries = Integer.parseInt(value);
  14627. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14628. isSuccess = ConfigurationStatus_Accepted;
  14629. }
  14630. }
  14631. else
  14632. {
  14633. isSuccess = ConfigurationStatus_Rejected;
  14634. }
  14635. }
  14636. if(strcmp(key, "ResetRetries") == 0)
  14637. {
  14638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14639. {
  14640. check_ascii = value[0];
  14641. if( (check_ascii < 48) || (check_ascii > 57) )
  14642. {
  14643. isSuccess = ConfigurationStatus_Rejected;
  14644. }
  14645. else
  14646. {
  14647. //Charger.ResetRetries = Integer.parseInt(value);
  14648. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14649. isSuccess = ConfigurationStatus_Accepted;
  14650. }
  14651. }
  14652. else
  14653. {
  14654. isSuccess = ConfigurationStatus_Rejected;
  14655. }
  14656. }
  14657. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14658. {
  14659. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14660. {
  14661. strcpy(str, (const char*)value);
  14662. for(int i = 0; str[i]; i++)
  14663. {
  14664. str[i] = tolower(str[i]);
  14665. }
  14666. if(strcmp(str, "notapplicable")== 0)
  14667. {
  14668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14669. isSuccess = ConfigurationStatus_Accepted;
  14670. }
  14671. else if(strcmp(str, "unknown")== 0)
  14672. {
  14673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14674. isSuccess = ConfigurationStatus_Accepted;
  14675. }
  14676. else if(strcmp(str, "rst")== 0)
  14677. {
  14678. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14679. isSuccess = ConfigurationStatus_Accepted;
  14680. }
  14681. else if(strcmp(str, "rts")== 0)
  14682. {
  14683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14684. isSuccess = ConfigurationStatus_Accepted;
  14685. }
  14686. else if(strcmp(str, "srt")== 0)
  14687. {
  14688. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14689. isSuccess = ConfigurationStatus_Accepted;
  14690. }
  14691. else if(strcmp(str, "str")== 0)
  14692. {
  14693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14694. isSuccess = ConfigurationStatus_Accepted;
  14695. }
  14696. else if(strcmp(str, "trs")== 0)
  14697. {
  14698. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14699. isSuccess = ConfigurationStatus_Accepted;
  14700. }
  14701. else if(strcmp(str, "tsr")== 0)
  14702. {
  14703. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14704. isSuccess = ConfigurationStatus_Accepted;
  14705. }
  14706. else
  14707. {
  14708. isSuccess = ConfigurationStatus_Rejected;
  14709. }
  14710. }
  14711. else
  14712. {
  14713. isSuccess = ConfigurationStatus_Rejected;
  14714. }
  14715. }
  14716. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14717. {
  14718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14719. {
  14720. check_ascii = value[0];
  14721. if( (check_ascii < 48) || (check_ascii > 57) )
  14722. {
  14723. isSuccess = ConfigurationStatus_Rejected;
  14724. }
  14725. else
  14726. {
  14727. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14728. isSuccess = ConfigurationStatus_Accepted;
  14729. }
  14730. }
  14731. else
  14732. {
  14733. isSuccess = ConfigurationStatus_Rejected;
  14734. }
  14735. }
  14736. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14737. {
  14738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14739. {
  14740. strcpy(str, (const char*)value);
  14741. for(int i = 0; str[i]; i++)
  14742. {
  14743. str[i] = tolower(str[i]);
  14744. }
  14745. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14747. isSuccess = ConfigurationStatus_Accepted;
  14748. }
  14749. else
  14750. {
  14751. isSuccess = ConfigurationStatus_Rejected;
  14752. }
  14753. }
  14754. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14755. {
  14756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14757. {
  14758. strcpy(str, (const char*)value);
  14759. for(int i = 0; str[i]; i++)
  14760. {
  14761. str[i] = tolower(str[i]);
  14762. }
  14763. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14765. isSuccess = ConfigurationStatus_Accepted;
  14766. }
  14767. else
  14768. {
  14769. isSuccess = ConfigurationStatus_Rejected;
  14770. }
  14771. }
  14772. if(strcmp(key, "StopTxnAlignedData") == 0)
  14773. {
  14774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14775. {
  14776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14777. isSuccess = ConfigurationStatus_Accepted;
  14778. }
  14779. else
  14780. {
  14781. isSuccess = ConfigurationStatus_Rejected;
  14782. }
  14783. }
  14784. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14785. {
  14786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14787. {
  14788. check_ascii = value[0];
  14789. if( (check_ascii < 48) || (check_ascii > 57) )
  14790. {
  14791. isSuccess = ConfigurationStatus_Rejected;
  14792. }
  14793. else
  14794. {
  14795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14796. isSuccess = ConfigurationStatus_Accepted;
  14797. }
  14798. }
  14799. else
  14800. {
  14801. isSuccess = ConfigurationStatus_Rejected;
  14802. }
  14803. }
  14804. if(strcmp(key, "StopTxnSampledData") == 0)
  14805. {
  14806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14807. {
  14808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14809. isSuccess = ConfigurationStatus_Accepted;
  14810. }
  14811. else
  14812. {
  14813. isSuccess = ConfigurationStatus_Rejected;
  14814. }
  14815. }
  14816. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14817. {
  14818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14819. {
  14820. check_ascii = value[0];
  14821. if( (check_ascii < 48) || (check_ascii > 57) )
  14822. {
  14823. isSuccess = ConfigurationStatus_Rejected;
  14824. }
  14825. else
  14826. {
  14827. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14828. isSuccess = ConfigurationStatus_Accepted;
  14829. }
  14830. }
  14831. else
  14832. {
  14833. isSuccess = ConfigurationStatus_Rejected;
  14834. }
  14835. }
  14836. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14837. {
  14838. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14839. {
  14840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14841. isSuccess = ConfigurationStatus_Accepted;
  14842. }
  14843. else
  14844. {
  14845. isSuccess = ConfigurationStatus_Rejected;
  14846. }
  14847. }
  14848. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14849. {
  14850. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14851. {
  14852. check_ascii = value[0];
  14853. if( (check_ascii < 48) || (check_ascii > 57) )
  14854. {
  14855. isSuccess = ConfigurationStatus_Rejected;
  14856. }
  14857. else
  14858. {
  14859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14860. isSuccess = ConfigurationStatus_Accepted;
  14861. }
  14862. }
  14863. else
  14864. {
  14865. isSuccess = ConfigurationStatus_Rejected;
  14866. }
  14867. }
  14868. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14869. {
  14870. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14871. {
  14872. check_ascii = value[0];
  14873. if( (check_ascii < 48) || (check_ascii > 57) )
  14874. {
  14875. isSuccess = ConfigurationStatus_Rejected;
  14876. }
  14877. else
  14878. {
  14879. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14881. TransactionMessageAttemptsValue = atoi(value);
  14882. isSuccess = ConfigurationStatus_Accepted;
  14883. }
  14884. }
  14885. else
  14886. {
  14887. isSuccess = ConfigurationStatus_Rejected;
  14888. }
  14889. }
  14890. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14891. {
  14892. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14893. {
  14894. check_ascii = value[0];
  14895. if( (check_ascii < 48) || (check_ascii > 57) )
  14896. {
  14897. isSuccess = ConfigurationStatus_Rejected;
  14898. }
  14899. else
  14900. {
  14901. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14903. TransactionMessageRetryIntervalValue = atoi(value);
  14904. isSuccess = ConfigurationStatus_Accepted;
  14905. }
  14906. }
  14907. else
  14908. {
  14909. isSuccess = ConfigurationStatus_Rejected;
  14910. }
  14911. }
  14912. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14913. {
  14914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14915. {
  14916. strcpy(str, (const char*)value);
  14917. for(int i = 0; str[i]; i++)
  14918. {
  14919. str[i] = tolower(str[i]);
  14920. }
  14921. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14922. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14923. isSuccess = ConfigurationStatus_Accepted;
  14924. }
  14925. else
  14926. {
  14927. isSuccess = ConfigurationStatus_Rejected;
  14928. }
  14929. }
  14930. if(strcmp(key, "WebSocketPingInterval") == 0)
  14931. {
  14932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14933. {
  14934. check_ascii = value[0];
  14935. if( (check_ascii < 48) || (check_ascii > 57) )
  14936. {
  14937. isSuccess = ConfigurationStatus_Rejected;
  14938. }
  14939. else
  14940. {
  14941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14942. isSuccess = ConfigurationStatus_Accepted;
  14943. }
  14944. }
  14945. else
  14946. {
  14947. isSuccess = ConfigurationStatus_Rejected;
  14948. }
  14949. }
  14950. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14951. {
  14952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14953. {
  14954. strcpy(str, (const char*)value);
  14955. for(int i = 0; str[i]; i++)
  14956. {
  14957. str[i] = tolower(str[i]);
  14958. }
  14959. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14961. isSuccess = ConfigurationStatus_Accepted;
  14962. }
  14963. else
  14964. {
  14965. isSuccess = ConfigurationStatus_Rejected;
  14966. }
  14967. }
  14968. if(strcmp(key, "AuthorizationKey") == 0)
  14969. {
  14970. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14971. {
  14972. strcpy(str, (const char*)value);
  14973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14974. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14975. isSuccess = ConfigurationStatus_Accepted;
  14976. }
  14977. else
  14978. {
  14979. isSuccess = ConfigurationStatus_Rejected;
  14980. }
  14981. }
  14982. if(strcmp(key, "SecurityProfile") == 0)
  14983. {
  14984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14985. {
  14986. check_ascii = value[0];
  14987. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14988. {
  14989. isSuccess = ConfigurationStatus_Rejected;
  14990. }
  14991. else if(check_ascii == 0x33)
  14992. {
  14993. isSuccess = NotSupported;
  14994. }
  14995. else
  14996. {
  14997. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14998. {
  14999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  15000. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  15001. isSuccess = ConfigurationStatus_Accepted;
  15002. }
  15003. else
  15004. isSuccess = ConfigurationStatus_Rejected;
  15005. }
  15006. }
  15007. else
  15008. {
  15009. isSuccess = ConfigurationStatus_Rejected;
  15010. }
  15011. }
  15012. if(strcmp(key, "DefaultPrice") == 0)
  15013. {
  15014. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  15015. {
  15016. strcpy(str, (const char*)value);
  15017. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  15018. isSuccess = ConfigurationStatus_Accepted;
  15019. }
  15020. else
  15021. {
  15022. isSuccess = ConfigurationStatus_Rejected;
  15023. }
  15024. }
  15025. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  15026. {
  15027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  15028. {
  15029. strcpy(str, (const char*)value);
  15030. for(int i = 0; str[i]; i++)
  15031. {
  15032. str[i] = tolower(str[i]);
  15033. }
  15034. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  15035. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15036. isSuccess = ConfigurationStatus_Accepted;
  15037. }
  15038. else
  15039. {
  15040. isSuccess = ConfigurationStatus_Rejected;
  15041. }
  15042. }
  15043. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  15044. {
  15045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  15046. {
  15047. strcpy(str, (const char*)value);
  15048. for(int i = 0; str[i]; i++)
  15049. {
  15050. str[i] = tolower(str[i]);
  15051. }
  15052. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  15053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15054. isSuccess = ConfigurationStatus_Accepted;
  15055. }
  15056. else
  15057. {
  15058. isSuccess = ConfigurationStatus_Rejected;
  15059. }
  15060. }
  15061. if(strcmp(key, "TimeOffset") == 0)
  15062. {
  15063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemAccessibility == 1)
  15064. {
  15065. strcpy(str, (const char*)value);
  15066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffset].ItemData, "%s", str);
  15067. isSuccess = ConfigurationStatus_Accepted;
  15068. }
  15069. else
  15070. {
  15071. isSuccess = ConfigurationStatus_Rejected;
  15072. }
  15073. }
  15074. if(strcmp(key, "NextTimeOffsetTransitionDateTime") == 0)
  15075. {
  15076. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemAccessibility == 1)
  15077. {
  15078. strcpy(str, (const char*)value);
  15079. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NextTimeOffsetTransitionDateTime].ItemData, "%s", str);
  15080. isSuccess = ConfigurationStatus_Accepted;
  15081. }
  15082. else
  15083. {
  15084. isSuccess = ConfigurationStatus_Rejected;
  15085. }
  15086. }
  15087. if(strcmp(key, "TimeOffsetNextTransition") == 0)
  15088. {
  15089. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemAccessibility == 1)
  15090. {
  15091. strcpy(str, (const char*)value);
  15092. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TimeOffsetNextTransition].ItemData, "%s", str);
  15093. isSuccess = ConfigurationStatus_Accepted;
  15094. }
  15095. else
  15096. {
  15097. isSuccess = ConfigurationStatus_Rejected;
  15098. }
  15099. }
  15100. #if 0
  15101. //For OCPP Test Case
  15102. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  15103. {
  15104. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15105. {
  15106. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  15107. isSuccess = ConfigurationStatus_Accepted;
  15108. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15109. }
  15110. else
  15111. {
  15112. isSuccess = ConfigurationStatus_Rejected;
  15113. }
  15114. }
  15115. #endif
  15116. #if 1
  15117. if(strcmp(key, "LocalAuthListEnabled") == 0)
  15118. {
  15119. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  15120. {
  15121. strcpy(str, (const char*)value);
  15122. for(int i = 0; str[i]; i++)
  15123. {
  15124. str[i] = tolower(str[i]);
  15125. }
  15126. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15127. isSuccess = ConfigurationStatus_Accepted;
  15128. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  15129. }
  15130. else
  15131. {
  15132. isSuccess = ConfigurationStatus_Rejected;
  15133. }
  15134. }
  15135. #endif
  15136. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  15137. {
  15138. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  15139. {
  15140. check_ascii = value[0];
  15141. if( (check_ascii < 48) || (check_ascii > 57) )
  15142. {
  15143. isSuccess = ConfigurationStatus_Rejected;
  15144. }
  15145. else
  15146. {
  15147. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  15148. isSuccess = ConfigurationStatus_Accepted;
  15149. }
  15150. }
  15151. else
  15152. {
  15153. isSuccess = ConfigurationStatus_Rejected;
  15154. }
  15155. }
  15156. if(strcmp(key, "SendLocalListMaxLength") == 0)
  15157. {
  15158. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  15159. {
  15160. check_ascii = value[0];
  15161. if( (check_ascii < 48) || (check_ascii > 57) )
  15162. {
  15163. isSuccess = ConfigurationStatus_Rejected;
  15164. }
  15165. else
  15166. {
  15167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  15168. isSuccess = ConfigurationStatus_Accepted;
  15169. }
  15170. }
  15171. else
  15172. {
  15173. isSuccess = ConfigurationStatus_Rejected;
  15174. }
  15175. }
  15176. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  15177. {
  15178. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  15179. {
  15180. strcpy(str, (const char*)value);
  15181. for(int i = 0; str[i]; i++)
  15182. {
  15183. str[i] = tolower(str[i]);
  15184. }
  15185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15186. isSuccess = ConfigurationStatus_Accepted;
  15187. }
  15188. else
  15189. {
  15190. isSuccess = ConfigurationStatus_Rejected;
  15191. }
  15192. }
  15193. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  15194. {
  15195. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  15196. {
  15197. check_ascii = value[0];
  15198. if( (check_ascii < 48) || (check_ascii > 57) )
  15199. {
  15200. isSuccess = ConfigurationStatus_Rejected;
  15201. }
  15202. else
  15203. {
  15204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  15205. isSuccess = ConfigurationStatus_Accepted;
  15206. }
  15207. }
  15208. else
  15209. {
  15210. isSuccess = ConfigurationStatus_Rejected;
  15211. }
  15212. }
  15213. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  15214. {
  15215. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  15216. {
  15217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  15218. isSuccess = ConfigurationStatus_Accepted;
  15219. }
  15220. else
  15221. {
  15222. isSuccess = ConfigurationStatus_Rejected;
  15223. }
  15224. }
  15225. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  15226. {
  15227. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  15228. {
  15229. check_ascii = value[0];
  15230. if( (check_ascii < 48) || (check_ascii > 57) )
  15231. {
  15232. isSuccess = ConfigurationStatus_Rejected;
  15233. }
  15234. else
  15235. {
  15236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  15237. isSuccess = ConfigurationStatus_Accepted;
  15238. }
  15239. }
  15240. else
  15241. {
  15242. isSuccess = ConfigurationStatus_Rejected;
  15243. }
  15244. }
  15245. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  15246. {
  15247. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  15248. {
  15249. strcpy(str, (const char*)value);
  15250. for(int i = 0; str[i]; i++)
  15251. {
  15252. str[i] = tolower(str[i]);
  15253. }
  15254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  15255. isSuccess = ConfigurationStatus_Accepted;
  15256. }
  15257. else
  15258. {
  15259. isSuccess = ConfigurationStatus_Rejected;
  15260. }
  15261. }
  15262. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  15263. {
  15264. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  15265. {
  15266. check_ascii = value[0];
  15267. if( (check_ascii < 48) || (check_ascii > 57) )
  15268. {
  15269. isSuccess = ConfigurationStatus_Rejected;
  15270. }
  15271. else
  15272. {
  15273. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  15274. isSuccess = ConfigurationStatus_Accepted;
  15275. }
  15276. }
  15277. else
  15278. {
  15279. isSuccess = ConfigurationStatus_Rejected;
  15280. }
  15281. }
  15282. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15283. return isSuccess;
  15284. }
  15285. int TransactionMessageAttemptsGet(void)
  15286. {
  15287. return TransactionMessageAttemptsValue;
  15288. }
  15289. int FirstHeartBeatResponse(void)
  15290. {
  15291. return FirstHeartBeat;
  15292. }
  15293. int TransactionMessageRetryIntervalGet(void)
  15294. {
  15295. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15296. }
  15297. int ReadHttpStatus(int sock)
  15298. {
  15299. //char c;
  15300. char buff[1024]="",*ptr=buff+1;
  15301. int bytes_received, status;
  15302. DEBUG_INFO("Begin Response ..\n");
  15303. while((bytes_received = recv(sock, ptr, 1, 0))){
  15304. if(bytes_received==-1){
  15305. perror("ReadHttpStatus");
  15306. exit(1);
  15307. }
  15308. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  15309. ptr++;
  15310. }
  15311. *ptr=0;
  15312. ptr=buff+1;
  15313. sscanf(ptr,"%*s %d ", &status);
  15314. DEBUG_INFO("%s\n",ptr);
  15315. DEBUG_INFO("status=%d\n",status);
  15316. DEBUG_INFO("End Response ..\n");
  15317. return (bytes_received>0)?status:0;
  15318. }
  15319. //the only filed that it parsed is 'Content-Length'
  15320. int ParseHeader(int sock)
  15321. {
  15322. //char c;
  15323. char buff[1024]="",*ptr=buff+4;
  15324. int bytes_received;
  15325. DEBUG_INFO("Begin HEADER ..\n");
  15326. while((bytes_received = recv(sock, ptr, 1, 0))){
  15327. if(bytes_received==-1){
  15328. perror("Parse Header");
  15329. exit(1);
  15330. }
  15331. if(
  15332. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  15333. (ptr[-1]=='\r') && (*ptr=='\n' )
  15334. ) break;
  15335. ptr++;
  15336. }
  15337. *ptr=0;
  15338. ptr=buff+4;
  15339. //printf("%s",ptr);
  15340. if(bytes_received){
  15341. ptr=strstr(ptr,"Content-Length:");
  15342. if(ptr){
  15343. sscanf(ptr,"%*s %d",&bytes_received);
  15344. }else
  15345. bytes_received=-1; //unknown size
  15346. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  15347. }
  15348. DEBUG_INFO("End HEADER ..\n");
  15349. return bytes_received ;
  15350. }
  15351. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  15352. {
  15353. int result = TRUE;
  15354. char rmFileCmd[100]={0};
  15355. char FilePath[100]={0};
  15356. char ftpbuf[200];
  15357. int systemresult;
  15358. //DEBUG_INFO("filename=%s\n",filename);
  15359. //DEBUG_INFO("url=%s\n",url);
  15360. sprintf(FilePath,"/mnt/%s",filename);
  15361. system("ping 8.8.8.8 &");
  15362. if((access(FilePath,F_OK))!=-1)
  15363. {
  15364. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15365. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15366. system(rmFileCmd);
  15367. }
  15368. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15369. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15370. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15371. systemresult = system(ftpbuf);
  15372. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15373. if(systemresult != 0)
  15374. {
  15375. DEBUG_INFO("http DownLoad error!\n");
  15376. result = FALSE;
  15377. }
  15378. system("pkill ping");
  15379. return result;
  15380. }
  15381. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  15382. {
  15383. int result = TRUE;
  15384. char rmFileCmd[100]={0};
  15385. char FilePath[100]={0};
  15386. char ftpbuf[200];
  15387. int systemresult;
  15388. //char temp[100];
  15389. sprintf(FilePath,"/mnt/%s",filename);
  15390. system("ping 8.8.8.8 &");
  15391. if((access(FilePath,F_OK))!=-1)
  15392. {
  15393. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15394. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15395. system(rmFileCmd);
  15396. }
  15397. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15398. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  15399. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  15400. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15401. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15402. systemresult = system(ftpbuf);
  15403. //DEBUG_INFO("systemresult=%d\n",systemresult);
  15404. if(systemresult != 0)
  15405. {
  15406. DEBUG_WARN("wget error!\n");
  15407. result = FALSE;
  15408. }
  15409. system("pkill ping");
  15410. return result;
  15411. }
  15412. int httpUploadFile(char *location, char *path, char *filename,char *url)
  15413. {
  15414. char rmFileCmd[100]={0};
  15415. char FilePath[100]={0};
  15416. char buf[512];
  15417. int systemresult = 0;
  15418. //DEBUG_INFO("filename=%s\n",filename);
  15419. //DEBUG_INFO("url=%s\n",url);
  15420. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  15421. if((access(FilePath,F_OK))!=-1)
  15422. {
  15423. DEBUG_INFO("filename=%s exist.\n",FilePath);
  15424. sprintf(rmFileCmd,"rm -f %s",FilePath);
  15425. system(rmFileCmd);
  15426. }
  15427. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  15428. if(fp == NULL)
  15429. {
  15430. DEBUG_INFO("log is NULL\n");
  15431. return FALSE;
  15432. }
  15433. else
  15434. {
  15435. fprintf(fp, "%s\n", url);
  15436. fprintf(fp, "%s\n", filename);
  15437. fclose(fp);
  15438. }
  15439. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  15440. if(phpFP == NULL)
  15441. {
  15442. DEBUG_INFO("PHP upload fail.\n");
  15443. return FALSE;
  15444. }
  15445. else
  15446. {
  15447. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  15448. {
  15449. if(strstr(buf, "result") != NULL)
  15450. {
  15451. sscanf(buf, "result: %d", &systemresult);
  15452. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15453. }
  15454. }
  15455. pclose(phpFP);
  15456. }
  15457. if(systemresult != 1)
  15458. {
  15459. DEBUG_INFO("HTTP upload error!\n");
  15460. return FALSE;
  15461. }
  15462. return TRUE;
  15463. }
  15464. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15465. {
  15466. struct hostent* server;
  15467. char *IPbuffer;
  15468. char ftpbuf[200];
  15469. int systemresult;
  15470. // To retrieve host information
  15471. server = gethostbyname(location);
  15472. // To convert an Internet network
  15473. // address into ASCII string
  15474. IPbuffer = inet_ntoa(*((struct in_addr*)
  15475. server->h_addr_list[0]));
  15476. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15477. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15478. /* format : ftpput -u username -p passwd IP target source*/
  15479. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15480. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15481. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15482. systemresult = system(ftpbuf);
  15483. DEBUG_INFO("systemresult=%d\n",systemresult);
  15484. if(systemresult != 0)
  15485. {
  15486. DEBUG_INFO("ftpput error!\n");
  15487. return FALSE;
  15488. }
  15489. return TRUE;
  15490. }
  15491. int GetOcppServerURL()
  15492. {
  15493. int result = FALSE;
  15494. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15495. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15496. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15497. struct yuarel url;
  15498. char urlStr[512];
  15499. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  15500. {
  15501. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  15502. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15503. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15504. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  15505. if(yuarel_parse(&url, urlStr) != -1)
  15506. {
  15507. sprintf(OcppProtocol, "%s", url.scheme);
  15508. sprintf(OcppHost, "%s", url.host);
  15509. if(url.path == NULL)
  15510. OcppTempPath[0] = '\0';
  15511. else
  15512. {
  15513. if((url.path[strlen(url.path)-1] != '/') && (strlen(url.path) > 0))
  15514. {
  15515. sprintf(OcppTempPath, "%s/", url.path);
  15516. }
  15517. else
  15518. {
  15519. sprintf(OcppTempPath, "%s", url.path);
  15520. }
  15521. }
  15522. if(url.port == 0)
  15523. {
  15524. if(strcmp(OcppProtocol, "wss") == 0)
  15525. OcppPort = 443;
  15526. else
  15527. OcppPort = 80;
  15528. }
  15529. else
  15530. OcppPort = url.port;
  15531. result = TRUE;
  15532. }
  15533. }
  15534. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  15535. {
  15536. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  15537. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15538. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15539. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  15540. if(yuarel_parse(&url, urlStr) != -1)
  15541. {
  15542. sprintf(OcppProtocol, "%s", url.scheme);
  15543. sprintf(OcppHost, "%s", url.host);
  15544. if(url.path == NULL)
  15545. OcppTempPath[0] = '\0';
  15546. else
  15547. sprintf(OcppTempPath, "%s", url.path);
  15548. if(url.port == 0)
  15549. {
  15550. if(strcmp(OcppProtocol, "wss") == 0)
  15551. OcppPort = 443;
  15552. else
  15553. OcppPort = 80;
  15554. }
  15555. else
  15556. OcppPort = url.port;
  15557. result = TRUE;
  15558. }
  15559. }
  15560. else
  15561. {
  15562. strcpy(OcppHost,"");
  15563. }
  15564. return result;
  15565. }
  15566. int GetOcppPath()
  15567. {
  15568. int result = FALSE;
  15569. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  15570. {
  15571. if(OcppTempPath == NULL)
  15572. {
  15573. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15574. }
  15575. else
  15576. {
  15577. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15578. }
  15579. result = TRUE;
  15580. goto End;
  15581. }
  15582. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  15583. {
  15584. if(OcppTempPath == NULL)
  15585. {
  15586. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  15587. }
  15588. else
  15589. {
  15590. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  15591. }
  15592. result = TRUE;
  15593. goto End;
  15594. }
  15595. else
  15596. {
  15597. strcpy(OcppPath,"");
  15598. }
  15599. End:
  15600. return result;
  15601. }
  15602. int GetOcppPort()
  15603. {
  15604. return OcppPort;
  15605. }
  15606. int GetOcppConnStatus(void)
  15607. {
  15608. return ShmOCPP16Data->OcppConnStatus;
  15609. }
  15610. void SetOcppConnStatus(uint8_t status)
  15611. {
  15612. ShmOCPP16Data->OcppConnStatus = status;
  15613. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  15614. }
  15615. int GetHeartBeatWithNOResponse(void)
  15616. {
  15617. return HeartBeatWithNOResponse;
  15618. }
  15619. void SetHeartBeatWithNOResponse(void)
  15620. {
  15621. HeartBeatWithNOResponse = 0;
  15622. }
  15623. void GetStartTransactionIdTag(int gun_index)
  15624. {
  15625. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15626. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15627. }
  15628. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15629. {
  15630. char ch;
  15631. FILE *fptr1;
  15632. int temptransactionId;
  15633. char str[100]={0};
  15634. temptransactionId = 0;
  15635. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15636. {
  15637. DEBUG_INFO("IdTag is empty.\n");
  15638. return temptransactionId;
  15639. }
  15640. /*------ Read the file ----------------*/
  15641. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  15642. if (!fptr1)
  15643. {
  15644. DEBUG_INFO("QueueTransactionId file open error.\n");
  15645. //printf(" File not found or unable to open the input file!!\n");
  15646. return temptransactionId;
  15647. }
  15648. ch=fgetc(fptr1);
  15649. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  15650. rewind(fptr1);
  15651. if(ch!=EOF)
  15652. {
  15653. // printf("%c",ch);
  15654. while (fgets(str, 100, fptr1) != NULL)
  15655. {
  15656. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15657. if(str[0]=='\0')
  15658. {
  15659. break;
  15660. }
  15661. char *revbuf[8] = {0}; // Variable store string split
  15662. int num = 0;// Quantity after string split
  15663. DEBUG_INFO("Transaction queue data= %s\n", str);
  15664. splitstring(str,",",revbuf,&num); // String split
  15665. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15666. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15667. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15668. DEBUG_INFO("------------------------------\n");
  15669. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15670. {
  15671. if(isStopTransaction)
  15672. {
  15673. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15674. {
  15675. temptransactionId = atoi(revbuf[2]);
  15676. //break;
  15677. }
  15678. }
  15679. else
  15680. {
  15681. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15682. {
  15683. temptransactionId = atoi(revbuf[2]);
  15684. //break;
  15685. }
  15686. }
  15687. }
  15688. }
  15689. }
  15690. else
  15691. DEBUG_INFO("EOF\n");
  15692. fclose(fptr1);
  15693. /*------- End of reading ---------------*/
  15694. return temptransactionId;
  15695. }
  15696. void SetTransactionIdZero(int transactionId)
  15697. {
  15698. char ch;
  15699. FILE *fptr1, *fptr2;
  15700. int temptransactionId = 0;
  15701. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  15702. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  15703. if (!fptr1)
  15704. {
  15705. //printf(" File not found or unable to open the input file!!\n");
  15706. return ;
  15707. }
  15708. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15709. if (!fptr2)
  15710. {
  15711. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15712. fclose(fptr1);
  15713. return ;
  15714. }
  15715. ch=fgetc(fptr1);
  15716. rewind(fptr1);
  15717. if(ch!=EOF)
  15718. {
  15719. // copy all contents to the temporary file except the specific line
  15720. while (fgets(str, 100, fptr1) != NULL)
  15721. {
  15722. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15723. if(str[0]=='\0')
  15724. {
  15725. break;
  15726. }
  15727. char *revbuf[8] = {0};
  15728. int num = 0;
  15729. strcpy(strtemp, str);
  15730. splitstring(str,",",revbuf,&num);
  15731. if(revbuf[2][0] != '\0')
  15732. {
  15733. temptransactionId = atoi(revbuf[2]);
  15734. if(transactionId != temptransactionId)
  15735. {
  15736. fprintf(fptr2, "%s\n", strtemp);
  15737. }
  15738. }
  15739. }
  15740. }
  15741. fclose(fptr1);
  15742. fclose(fptr2);
  15743. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  15744. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  15745. /*------ Read the file ----------------*/
  15746. }
  15747. int InternetDisconnect(void)
  15748. {
  15749. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15750. }
  15751. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15752. void storeTempStopTransaction(int gun_index)
  15753. {
  15754. char guid[37]={0};
  15755. int tempIndex = 0;
  15756. char TempStopTransaction[256];
  15757. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15758. DEBUG_INFO("storeTempStopTransaction...\n");
  15759. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15760. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  15761. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15762. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15763. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15764. {
  15765. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15766. {
  15767. tempIndex = ((gun_index==2) ? 1: 0);
  15768. }
  15769. else
  15770. {
  15771. tempIndex = gun_index;
  15772. }
  15773. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15774. {
  15775. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15776. {
  15777. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15778. }
  15779. }// END OF CHAdeMO_QUANTITY
  15780. }
  15781. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15782. {
  15783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15784. {
  15785. tempIndex = ((gun_index==2) ? 1: 0);
  15786. }
  15787. else
  15788. {
  15789. tempIndex = gun_index;
  15790. }
  15791. for (int index = 0; index < CCS_QUANTITY; index++)
  15792. {
  15793. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15794. {
  15795. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15796. }
  15797. }// END OF CCS_QUANTITY
  15798. }
  15799. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15800. {
  15801. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15802. {
  15803. tempIndex = ((gun_index==2) ? 1: 0);
  15804. }
  15805. else
  15806. {
  15807. tempIndex = gun_index;
  15808. }
  15809. for (int index = 0; index < GB_QUANTITY; index++)
  15810. {
  15811. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15812. {
  15813. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15814. }
  15815. }// END OF GB_QUANTITY
  15816. }
  15817. else if(gunType[gun_index] == GUN_TYPE_DO)
  15818. {
  15819. tempIndex = gun_index;
  15820. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15821. {
  15822. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15823. {
  15824. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15825. }
  15826. }
  15827. }
  15828. else
  15829. {
  15830. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15831. {
  15832. tempIndex = 2;
  15833. }
  15834. else
  15835. {
  15836. tempIndex = gun_index;
  15837. }
  15838. for (int index = 0; index < AC_QUANTITY; index++)
  15839. {
  15840. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15841. {
  15842. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15843. }
  15844. }// END OF AC_QUANTITY
  15845. }
  15846. //Stop Transaction Time
  15847. struct timeval tmnow;
  15848. struct tm *tm;
  15849. char buf[28];//, usec_buf[6];
  15850. gettimeofday(&tmnow, NULL);
  15851. time_t t;
  15852. t = time(NULL);
  15853. /*UTC time and date*/
  15854. tm = gmtime(&t);
  15855. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15857. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15858. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15859. random_uuid(guid);
  15860. /***********************************transactionData******************************************************/
  15861. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15863. //=================================
  15864. //1. Transaction_Begin
  15865. //=================================
  15866. //============================== Energy.Active.Import.Interval ===========================================
  15867. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15868. {
  15869. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15872. 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*/]);
  15873. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15874. 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))
  15875. {
  15876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15877. }
  15878. else
  15879. {
  15880. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15881. }
  15882. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15883. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15884. }
  15885. //=================================
  15886. //2. Transaction_End
  15887. //=================================
  15888. //2.1====================================== Current.Import L1 ==============================================
  15889. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15890. {
  15891. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15892. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15893. {
  15894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15895. {
  15896. tempIndex = ((gun_index==2) ? 1: 0);
  15897. }
  15898. else
  15899. {
  15900. tempIndex = gun_index;
  15901. }
  15902. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15903. {
  15904. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15905. {
  15906. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15907. }
  15908. }// End of for CHAdeMO_QUANTITY
  15909. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15910. }
  15911. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15912. {
  15913. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15914. {
  15915. tempIndex = ((gun_index==2) ? 1: 0);
  15916. }
  15917. else
  15918. {
  15919. tempIndex = gun_index;
  15920. }
  15921. for (int index = 0; index < CCS_QUANTITY; index++)
  15922. {
  15923. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15924. {
  15925. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15926. }
  15927. }// End of for CCS_QUANTITY
  15928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15929. }
  15930. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15931. {
  15932. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15933. {
  15934. tempIndex = ((gun_index==2) ? 1: 0);
  15935. }
  15936. else
  15937. {
  15938. tempIndex = gun_index;
  15939. }
  15940. for (int index = 0; index < GB_QUANTITY; index++)
  15941. {
  15942. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15943. {
  15944. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15945. }
  15946. }// End of for GB_QUANTITY
  15947. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15948. }
  15949. else if(gunType[gun_index] == GUN_TYPE_DO)
  15950. {
  15951. tempIndex = gun_index;
  15952. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15953. {
  15954. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15955. {
  15956. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15957. }
  15958. }
  15959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15960. }
  15961. else
  15962. {
  15963. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15964. {
  15965. tempIndex = 2;
  15966. }
  15967. else
  15968. {
  15969. tempIndex = gun_index;
  15970. }
  15971. for (int index = 0; index < AC_QUANTITY; index++)
  15972. {
  15973. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15974. {
  15975. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15976. }
  15977. }// End of for AC_QUANTITY
  15978. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15979. }
  15980. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15982. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15983. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15986. }
  15987. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15988. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15989. {
  15990. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15991. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15992. {
  15993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15994. {
  15995. tempIndex = ((gun_index==2) ? 1: 0);
  15996. }
  15997. else
  15998. {
  15999. tempIndex = gun_index;
  16000. }
  16001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16002. {
  16003. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16004. {
  16005. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16006. }
  16007. }// END OF CHAdeMO_QUANTITY
  16008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16009. }
  16010. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16011. {
  16012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16013. {
  16014. tempIndex = ((gun_index==2) ? 1: 0);
  16015. }
  16016. else
  16017. {
  16018. tempIndex = gun_index;
  16019. }
  16020. for (int index = 0; index < CCS_QUANTITY; index++)
  16021. {
  16022. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16023. {
  16024. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16025. }
  16026. }// END OF CCS_QUANTITY
  16027. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16028. }
  16029. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16030. {
  16031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16032. {
  16033. tempIndex = ((gun_index==2) ? 1: 0);
  16034. }
  16035. else
  16036. {
  16037. tempIndex = gun_index;
  16038. }
  16039. for (int index = 0; index < GB_QUANTITY; index++)
  16040. {
  16041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16042. {
  16043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16044. }
  16045. }// END OF GB_QUANTITY
  16046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16047. }
  16048. else if(gunType[gun_index] == GUN_TYPE_DO)
  16049. {
  16050. tempIndex = gun_index;
  16051. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16052. {
  16053. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16054. {
  16055. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16056. }
  16057. }
  16058. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  16059. }
  16060. else
  16061. {
  16062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16063. {
  16064. tempIndex = 2;
  16065. }
  16066. else
  16067. {
  16068. tempIndex = gun_index;
  16069. }
  16070. for (int index = 0; index < AC_QUANTITY; index++)
  16071. {
  16072. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16073. {
  16074. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  16075. }
  16076. }// END OF AC_QUANTITY
  16077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16078. }
  16079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16080. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  16081. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  16082. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  16083. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  16084. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  16085. }
  16086. //2.3====================================== Power.Active.Import =========================================
  16087. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  16088. {
  16089. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16090. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16091. {
  16092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16093. {
  16094. tempIndex = ((gun_index==2) ? 1: 0);
  16095. }
  16096. else
  16097. {
  16098. tempIndex = gun_index;
  16099. }
  16100. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16101. {
  16102. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16103. {
  16104. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16105. }
  16106. } // End for CHAdeMO_QUANTITY
  16107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16108. }
  16109. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16110. {
  16111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16112. {
  16113. tempIndex = ((gun_index==2) ? 1: 0);
  16114. }
  16115. else
  16116. {
  16117. tempIndex = gun_index;
  16118. }
  16119. for (int index = 0; index < CCS_QUANTITY; index++)
  16120. {
  16121. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16122. {
  16123. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16124. }
  16125. } // END for CCS_QUANTITY
  16126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16127. }
  16128. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16129. {
  16130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16131. {
  16132. tempIndex = ((gun_index==2) ? 1: 0);
  16133. }
  16134. else
  16135. {
  16136. tempIndex = gun_index;
  16137. }
  16138. for (int index = 0; index < GB_QUANTITY; index++)
  16139. {
  16140. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16141. {
  16142. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16143. }
  16144. }// END for GB_QUANTITY
  16145. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16146. }
  16147. else if(gunType[gun_index] == GUN_TYPE_DO)
  16148. {
  16149. tempIndex = gun_index;
  16150. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16151. {
  16152. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16153. {
  16154. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16155. }
  16156. }
  16157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  16158. }
  16159. else
  16160. {
  16161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16162. {
  16163. tempIndex = 2;
  16164. }
  16165. else
  16166. {
  16167. tempIndex = gun_index;
  16168. }
  16169. for (int index = 0; index < AC_QUANTITY; index++)
  16170. {
  16171. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16172. {
  16173. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  16174. }
  16175. } // END for AC_QUANTITY
  16176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16177. }
  16178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  16180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  16181. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  16182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  16183. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  16184. }
  16185. //2.4====================================== Voltage L1 ====================================================
  16186. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16187. {
  16188. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16189. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16190. {
  16191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16192. {
  16193. tempIndex = ((gun_index==2) ? 1: 0);
  16194. }
  16195. else
  16196. {
  16197. tempIndex = gun_index;
  16198. }
  16199. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16200. {
  16201. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16202. {
  16203. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16204. }
  16205. } // END OF FOR CHAdeMO_QUANTITY
  16206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16207. }
  16208. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16209. {
  16210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16211. {
  16212. tempIndex = ((gun_index==2) ? 1: 0);
  16213. }
  16214. else
  16215. {
  16216. tempIndex = gun_index;
  16217. }
  16218. for (int index = 0; index < CCS_QUANTITY; index++)
  16219. {
  16220. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16221. {
  16222. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16223. }
  16224. } // END OF FOR CCS_QUANTITY
  16225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16226. }
  16227. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16228. {
  16229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16230. {
  16231. tempIndex = ((gun_index==2) ? 1: 0);
  16232. }
  16233. else
  16234. {
  16235. tempIndex = gun_index;
  16236. }
  16237. for (int index = 0; index < GB_QUANTITY; index++)
  16238. {
  16239. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16240. {
  16241. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16242. }
  16243. } // END OF FOR GB_QUANTITY
  16244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16245. }
  16246. else if(gunType[gun_index] == GUN_TYPE_DO)
  16247. {
  16248. tempIndex = gun_index;
  16249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16250. {
  16251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16252. {
  16253. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  16254. }
  16255. }
  16256. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  16257. }
  16258. else
  16259. {
  16260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16261. {
  16262. tempIndex = 2;
  16263. }
  16264. else
  16265. {
  16266. tempIndex = gun_index;
  16267. }
  16268. for (int index = 0; index < AC_QUANTITY; index++)
  16269. {
  16270. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16271. {
  16272. 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
  16273. }
  16274. } // END OF FOR AC_QUANTITY
  16275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16276. }
  16277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16278. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  16279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  16280. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  16281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  16282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16283. }
  16284. //2.5============================================== End SoC =========================================================
  16285. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16286. {
  16287. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16288. 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))
  16289. {
  16290. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16291. {
  16292. tempIndex = ((gun_index==2) ? 1: 0);
  16293. }
  16294. else
  16295. {
  16296. tempIndex = gun_index;
  16297. }
  16298. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16299. {
  16300. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16301. {
  16302. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16303. {
  16304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  16305. }
  16306. }
  16307. }
  16308. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16309. {
  16310. for (int index = 0; index < CCS_QUANTITY; index++)
  16311. {
  16312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16313. {
  16314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  16315. }
  16316. }
  16317. }
  16318. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16319. {
  16320. for (int index = 0; index < GB_QUANTITY; index++)
  16321. {
  16322. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16323. {
  16324. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  16325. }
  16326. }
  16327. }
  16328. else if(gunType[gun_index] == GUN_TYPE_DO)
  16329. {
  16330. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16331. {
  16332. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16333. {
  16334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  16335. }
  16336. }
  16337. }
  16338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  16340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  16342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  16343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16344. } // END FOR DC CASE
  16345. }
  16346. //2.6====================================== Current.Import L2 ==============================================
  16347. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16348. {
  16349. // AC 3 phase L2 current
  16350. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16351. {
  16352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16353. {
  16354. tempIndex = 2;
  16355. }
  16356. else
  16357. {
  16358. tempIndex = gun_index;
  16359. }
  16360. for (int index = 0; index < AC_QUANTITY; index++)
  16361. {
  16362. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16363. {
  16364. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  16365. }
  16366. }// End of for AC_QUANTITY
  16367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  16368. }
  16369. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  16371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  16372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  16373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16374. }
  16375. //2.7====================================== Current.Import L3 ==============================================
  16376. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  16377. {
  16378. // AC 3 phase L3 current
  16379. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16380. {
  16381. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16382. {
  16383. tempIndex = 2;
  16384. }
  16385. else
  16386. {
  16387. tempIndex = gun_index;
  16388. }
  16389. for (int index = 0; index < AC_QUANTITY; index++)
  16390. {
  16391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16392. {
  16393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  16394. }
  16395. }// End of for AC_QUANTITY
  16396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  16397. }
  16398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  16400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  16401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  16402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  16403. }
  16404. //2.9====================================== Voltage L2 ====================================================
  16405. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16406. {
  16407. // AC 3 phase L2 volatge
  16408. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16409. {
  16410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16411. {
  16412. tempIndex = 2;
  16413. }
  16414. else
  16415. {
  16416. tempIndex = gun_index;
  16417. }
  16418. for (int index = 0; index < AC_QUANTITY; index++)
  16419. {
  16420. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16421. {
  16422. 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
  16423. }
  16424. } // END OF FOR AC_QUANTITY
  16425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  16426. }
  16427. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16428. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  16429. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  16430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  16431. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16432. }
  16433. //2.10====================================== Voltage L3 ====================================================
  16434. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  16435. {
  16436. // AC 3 phase L3 volatge
  16437. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  16438. {
  16439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16440. {
  16441. tempIndex = 2;
  16442. }
  16443. else
  16444. {
  16445. tempIndex = gun_index;
  16446. }
  16447. for (int index = 0; index < AC_QUANTITY; index++)
  16448. {
  16449. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16450. {
  16451. 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
  16452. }
  16453. } // END OF FOR AC_QUANTITY
  16454. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  16455. }
  16456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  16457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  16458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  16459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  16460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  16461. }
  16462. //====================== Start SoC ================================
  16463. if(strstr((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  16464. {
  16465. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  16466. 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))
  16467. {
  16468. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  16469. {
  16470. tempIndex = ((gun_index==2) ? 1: 0);
  16471. }
  16472. else
  16473. {
  16474. tempIndex = gun_index;
  16475. }
  16476. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16477. {
  16478. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16479. {
  16480. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  16481. {
  16482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  16483. }
  16484. }
  16485. }
  16486. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16487. {
  16488. for (int index = 0; index < CCS_QUANTITY; index++)
  16489. {
  16490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16491. {
  16492. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  16493. }
  16494. }
  16495. }
  16496. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16497. {
  16498. for (int index = 0; index < GB_QUANTITY; index++)
  16499. {
  16500. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16501. {
  16502. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16503. }
  16504. }
  16505. }
  16506. else if(gunType[gun_index] == GUN_TYPE_DO)
  16507. {
  16508. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16509. {
  16510. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16511. {
  16512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16513. }
  16514. }
  16515. }
  16516. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16522. } // END FOR DC CASE
  16523. }
  16524. //======================================== Message create ==============================================
  16525. json_object *StopTransaction = json_object_new_object();
  16526. json_object *transactionDatas = json_object_new_array();
  16527. json_object *sampledValues = json_object_new_array();
  16528. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  16529. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  16530. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  16531. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  16532. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  16533. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16534. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  16535. {
  16536. json_object *transactionData = json_object_new_object();
  16537. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16538. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16539. {
  16540. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16541. {
  16542. json_object *sampledValue = json_object_new_object();
  16543. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16544. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16545. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16546. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16547. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16548. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16549. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16550. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16551. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16552. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16553. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16554. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16555. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16556. json_object_array_add(sampledValues, sampledValue);
  16557. }
  16558. }
  16559. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16560. json_object_array_add(transactionDatas, transactionData);
  16561. }
  16562. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16563. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16564. ,MESSAGE_TYPE_CALL
  16565. ,guid
  16566. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16567. json_object_put(StopTransaction);
  16568. // Check File "TempStopTransaction" Exist
  16569. if((access(TempStopTransaction,F_OK))!=-1)
  16570. {
  16571. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16572. fclose(fopen(TempStopTransaction, "w"));
  16573. }
  16574. else
  16575. {
  16576. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16577. FILE *log = fopen(TempStopTransaction, "w+");
  16578. if(log == NULL)
  16579. {
  16580. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16581. return ;
  16582. }
  16583. else
  16584. {
  16585. fclose(log);
  16586. }
  16587. }
  16588. //Add TempStopTransaction | Update TempStopTransaction
  16589. // open file for writing
  16590. FILE *outfile;
  16591. outfile = fopen (TempStopTransaction, "a");
  16592. //DEBUG_INFO("data = %s\n", queuedata);
  16593. fputs(queuedata, outfile);
  16594. fputs("\n", outfile);
  16595. fclose (outfile);
  16596. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16597. }
  16598. void checkTempStopTransaction(int gun_index)
  16599. {
  16600. FILE *fptr1;
  16601. char ch;
  16602. char str[QUEUE_MESSAGE_LENGTH]={0};
  16603. char guid[37]={0};
  16604. char tempdata[65]={0};
  16605. char connectorStr[2]={0};
  16606. char TempStopTransaction[256];
  16607. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  16608. fptr1 = fopen(TempStopTransaction, "r");
  16609. //TempStopTransaction格式: 槍號,StopTransaction封包
  16610. if (!fptr1)
  16611. {
  16612. //printf(" File not found or unable to open the input file!!\n");
  16613. return ;
  16614. }
  16615. ch=fgetc(fptr1);
  16616. //printf(" Now the content of the file %s is : \n",fname);
  16617. rewind(fptr1);
  16618. if(ch!=EOF)
  16619. {
  16620. // copy all contents to the temporary file except the specific line
  16621. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16622. {
  16623. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16624. if(str[0]=='\0')
  16625. {
  16626. break;
  16627. }
  16628. //TempStopTransaction格式: 槍號,StopTransaction封包
  16629. strncpy(connectorStr, str, 1);
  16630. if(atoi(connectorStr) != (gun_index+1))
  16631. {
  16632. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16633. fclose(fptr1);
  16634. return ;
  16635. }
  16636. //random_uuid(guid);
  16637. strncpy(guid, str+6, 36); //copy guid
  16638. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16639. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16640. {
  16641. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16642. }
  16643. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16644. OCPP_insert_transaction_msg(NO, str);
  16645. memset(str,0,ARRAY_SIZE(str));
  16646. }
  16647. }
  16648. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16649. fclose(fptr1);
  16650. remove(TempStopTransaction); // remove the original file
  16651. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16652. }
  16653. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16654. {
  16655. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16656. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16657. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16658. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16659. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16660. }
  16661. int GetWebSocketPingInterval(void)
  16662. {
  16663. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16664. }
  16665. int GetServerSign(void)
  16666. {
  16667. return server_sign;
  16668. }
  16669. uint8_t GetOcppSecurityProfile()
  16670. {
  16671. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16672. }
  16673. void GetOcppChargerBoxId(uint8_t *data)
  16674. {
  16675. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16676. }
  16677. void GetOcppSecurityPassword(uint8_t *data)
  16678. {
  16679. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16680. }
  16681. void SetOcppVersion(uint8_t *version)
  16682. {
  16683. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16684. DEBUG_INFO("ocpp version: %s\n", version);
  16685. if(strstr((char*)version, "ocpp1.6") != NULL)
  16686. {
  16687. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16688. }
  16689. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16690. {
  16691. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16692. system("pkill OcppBackend");
  16693. }
  16694. }
  16695. void SetServerSign(int value)
  16696. {
  16697. server_sign = value;
  16698. }
  16699. int GetBootNotificationInterval(void)
  16700. {
  16701. return BootNotificationInterval;
  16702. }
  16703. int GetInternetConn(void)
  16704. {
  16705. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16706. }
  16707. int GetBackendConnectionTimeout(void)
  16708. {
  16709. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16710. }
  16711. int isConnectorInitMode(int gun_index)
  16712. {
  16713. int tempIndex = 0;
  16714. int result = TRUE;
  16715. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16716. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16717. {
  16718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16719. {
  16720. tempIndex = ((gun_index==2) ? 1: 0);
  16721. }
  16722. else
  16723. {
  16724. tempIndex = gun_index;
  16725. }
  16726. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16727. {
  16728. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16729. {
  16730. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16731. } //end of the same index
  16732. }//end of for CHAdeMO_QUANTITY
  16733. }
  16734. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16735. {
  16736. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16737. {
  16738. tempIndex = ((gun_index==2) ? 1: 0);
  16739. }
  16740. else
  16741. {
  16742. tempIndex = gun_index;
  16743. }
  16744. for (int index = 0; index < CCS_QUANTITY; index++)
  16745. {
  16746. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16747. {
  16748. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16749. } //end of the same index
  16750. } // end of for CCS_QUANTITY
  16751. }
  16752. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16753. {
  16754. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16755. {
  16756. tempIndex = ((gun_index==2) ? 1: 0);
  16757. }
  16758. else
  16759. {
  16760. tempIndex = gun_index;
  16761. }
  16762. for (int index = 0; index < GB_QUANTITY; index++)
  16763. {
  16764. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16765. {
  16766. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16767. } //end of the same index
  16768. } // end of for GB_QUANTITY
  16769. }
  16770. else if(gunType[gun_index] == GUN_TYPE_DO)
  16771. {
  16772. tempIndex = gun_index;
  16773. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16774. {
  16775. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16776. {
  16777. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16778. } //end of the same index
  16779. }
  16780. }
  16781. else
  16782. {
  16783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16784. {
  16785. tempIndex = 2;
  16786. }
  16787. else
  16788. {
  16789. tempIndex = gun_index;
  16790. }
  16791. for (int index = 0; index < AC_QUANTITY; index++)
  16792. {
  16793. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16794. {
  16795. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16796. }//end of the same index
  16797. }//end of for AC_QUANTITY
  16798. }
  16799. return result;
  16800. }
  16801. void refreshProcDogTimer()
  16802. {
  16803. ShmOCPP16Data->procDogTime = time((time_t*)NULL);
  16804. }
  16805. void InitialSystemValue(void)
  16806. {
  16807. int connectorIndex = 0;
  16808. //int valueASCII = 0;
  16809. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16810. gunTotalNumber=0;
  16811. SystemInitial = 0;
  16812. locallistVersion=0;
  16813. BootNotificationInterval = 0;
  16814. authorizeRetryTimes = 0;
  16815. GunStatusInterval = 10;
  16816. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16817. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16818. //Hear Beat
  16819. HeartBeatWithNOResponse = 0;
  16820. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16821. FirstHeartBeat = 0;
  16822. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16823. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16824. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16825. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16826. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16827. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16828. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16829. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16830. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16831. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16832. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16833. memset(gunType, 0, ARRAY_SIZE(gunType));
  16834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16835. {
  16836. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16837. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16838. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16839. {
  16840. // DO series
  16841. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16842. {
  16843. SystemInitial = SystemInitial + 1;
  16844. gunTotalNumber = gunTotalNumber + 1;
  16845. gunType[connectorIndex] = GUN_TYPE_DO;
  16846. connectorIndex = connectorIndex + 1;
  16847. }
  16848. }
  16849. else
  16850. {
  16851. // DM, DW, DS series
  16852. //check connector / socket type (index: 8, 9, 10)
  16853. for(int index=7; index <10 ; index++)
  16854. {
  16855. if(index != 8)
  16856. {
  16857. // DC Connector
  16858. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16859. {
  16860. SystemInitial = SystemInitial + 1;
  16861. gunTotalNumber = gunTotalNumber + 1;
  16862. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16863. connectorIndex = connectorIndex + 1;
  16864. }
  16865. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16866. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16867. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16868. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16869. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16870. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16871. {
  16872. SystemInitial = SystemInitial + 1;
  16873. gunTotalNumber = gunTotalNumber + 1;
  16874. gunType[connectorIndex] = GUN_TYPE_CCS;
  16875. connectorIndex = connectorIndex + 1;
  16876. }
  16877. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16878. {
  16879. SystemInitial = SystemInitial + 1;
  16880. gunTotalNumber = gunTotalNumber + 1;
  16881. gunType[connectorIndex] = GUN_TYPE_GBT;
  16882. connectorIndex = connectorIndex + 1;
  16883. }
  16884. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16885. {
  16886. SystemInitial = SystemInitial + 1;
  16887. gunTotalNumber = gunTotalNumber + 1;
  16888. gunType[connectorIndex] = GUN_TYPE_DO;
  16889. connectorIndex = connectorIndex + 1;
  16890. }
  16891. }
  16892. else
  16893. {
  16894. // AC Connector
  16895. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16896. {
  16897. SystemInitial = SystemInitial + 1;
  16898. gunTotalNumber = gunTotalNumber + 1;
  16899. gunType[connectorIndex] = GUN_TYPE_AC;
  16900. connectorIndex = connectorIndex + 1;
  16901. }
  16902. }
  16903. }
  16904. }
  16905. //DEBUG_INFO("DC ...\n");
  16906. }
  16907. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16908. {
  16909. //check connector / socket type (index: 8, 9, 10)
  16910. for(int index=7; index <10 ; index++)
  16911. {
  16912. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16913. {
  16914. SystemInitial = SystemInitial + 1;
  16915. gunTotalNumber = gunTotalNumber + 1;
  16916. gunType[connectorIndex] = GUN_TYPE_AC;
  16917. connectorIndex = connectorIndex + 1;
  16918. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16919. }
  16920. }
  16921. }
  16922. //Status && ConnectorPlugIn Setting
  16923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16924. {
  16925. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16926. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16927. }
  16928. for (int index = 0; index < CCS_QUANTITY; index++)
  16929. {
  16930. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16931. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16932. }
  16933. for (int index = 0; index < GB_QUANTITY; index++)
  16934. {
  16935. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16936. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16937. }
  16938. for (int index = 0; index < AC_QUANTITY; index++)
  16939. {
  16940. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16941. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16942. }
  16943. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16944. {
  16945. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16946. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16947. }
  16948. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16949. {
  16950. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16951. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16952. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16953. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16954. memset(&ShmOCPP16Data->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16955. }
  16956. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16957. clientTime.Heartbeat=time((time_t*)NULL);
  16958. sleep(1);
  16959. }
  16960. void LWS_Send(char *str)
  16961. {
  16962. //=====================================================
  16963. // Check InternetConn 0: disconnected, 1: connected
  16964. //====================================================
  16965. if(GetOcppConnStatus() == 0)
  16966. {
  16967. DEBUG_INFO("offline now !!!\n");
  16968. return;
  16969. }
  16970. // Only disable isWebsocketSendable operation initiated by charger
  16971. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16972. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16973. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16974. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16975. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16976. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16977. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16978. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16979. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16980. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16981. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16982. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16983. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16984. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16985. {
  16986. isWebsocketSendable = 0;
  16987. }
  16988. pthread_mutex_lock(&lock_send);
  16989. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16990. sprintf((char *)SendBuffer, "%s", str);
  16991. SendBufLen = strlen(str);
  16992. pthread_mutex_unlock(&lock_send);
  16993. lws_callback_on_writable(wsi_client);
  16994. //lws_service(context, 0);
  16995. //sleep(1);
  16996. }
  16997. void LWS_SendNow(char *str)
  16998. {
  16999. //=====================================================
  17000. // Check InternetConn 0: disconnected, 1: connected
  17001. //====================================================
  17002. if(GetOcppConnStatus() == 0)
  17003. {
  17004. DEBUG_INFO("offline now !!!\n");
  17005. return;
  17006. }
  17007. // Only disable isWebsocketSendable operation initiated by charger
  17008. if((strstr((char*)str, "\"Authorize\"") != NULL)
  17009. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  17010. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  17011. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  17012. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  17013. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  17014. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  17015. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  17016. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  17017. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  17018. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  17019. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  17020. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  17021. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  17022. {
  17023. isWebsocketSendable = 0;
  17024. }
  17025. pthread_mutex_lock(&lock_send);
  17026. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  17027. sprintf((char *)SendBuffer, "%s", str);
  17028. SendBufLen = strlen(str);
  17029. pthread_mutex_unlock(&lock_send);
  17030. lws_callback_on_writable(wsi_client);
  17031. lws_service(context, 0);
  17032. //sleep(1);
  17033. }