MessageHandler.c 823 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char isOnCharging:1; //bit 4.
  117. unsigned char :3; //bit 5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // Save configuration
  357. //=========================================
  358. int runShellCmd(const char*cmd)
  359. {
  360. int result = FAIL;
  361. char buf[256];
  362. FILE *fp;
  363. fp = popen(cmd, "r");
  364. if(fp != NULL)
  365. {
  366. while(fgets(buf, sizeof(buf), fp) != NULL)
  367. {
  368. DEBUG_INFO("%s\n", buf);
  369. }
  370. result = PASS;
  371. }
  372. pclose(fp);
  373. return result;
  374. }
  375. int StoreUsrConfigData(struct SysConfigData *UsrData)
  376. {
  377. int result = PASS;
  378. int fd,wrd;
  379. unsigned int i,Chk;
  380. unsigned char *ptr, *BufTmp;
  381. int MtdBlockSize = 0x300000;
  382. Chk=0;
  383. ptr=(unsigned char *)UsrData;
  384. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  385. {
  386. memset(BufTmp,0,MtdBlockSize);
  387. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  388. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  389. Chk+=*(BufTmp+i);
  390. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  391. // Output configuration to file.
  392. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  393. if (fd < 0)
  394. {
  395. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  396. free(BufTmp);
  397. return 0;
  398. }
  399. wrd=write(fd, BufTmp, MtdBlockSize);
  400. close(fd);
  401. if(wrd<MtdBlockSize)
  402. {
  403. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  404. free(BufTmp);
  405. return 0;
  406. }
  407. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  408. DEBUG_INFO("Erase /dev/mtd10.\n");
  409. runShellCmd("flash_erase /dev/mtd10 0 0");
  410. DEBUG_INFO("Write /dev/mtd10.\n");
  411. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  412. DEBUG_INFO("Erase /dev/mtd11.\n");
  413. runShellCmd("flash_erase /dev/mtd11 0 0");
  414. DEBUG_INFO("Write /dev/mtd11.\n");
  415. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  416. system("rm -f /mnt/EvseConfig.bin");
  417. DEBUG_INFO("EvseConfig write to flash OK\n");
  418. }
  419. else
  420. {
  421. DEBUG_ERROR("alloc BlockSize NG\r\n");
  422. result = FAIL;
  423. }
  424. if(BufTmp!=NULL)
  425. free(BufTmp);
  426. return result;
  427. }
  428. //=========================================
  429. // Sqlite3 related function
  430. //=========================================
  431. static int selectSqlCount = 0;
  432. static int callback(void *data, int argc, char **argv, char **azColName){
  433. int i;
  434. //printf("%s: ", (const char*)data);
  435. selectSqlCount = argc;
  436. for(i = 0; i<argc; i++){
  437. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  438. }
  439. //printf("\n");
  440. return 0;
  441. }
  442. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  443. //int i;
  444. //printf("%s:\n", (const char*)data);
  445. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  446. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  447. return 0;
  448. }
  449. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  450. //printf("%s:\n", (const char*)data);
  451. //idTag
  452. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. //parentIdTag
  455. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  456. //expir_date
  457. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  458. //status
  459. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  460. //version
  461. if(columenCount > 5)
  462. idTagQuery.listVersionInt = atoi(columnValue[5]);
  463. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  464. return 0;
  465. }
  466. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  467. {
  468. // localversion = argv[5] ? atoi(argv[5]) : 0;
  469. // printf("localversion=%d\n", localversion);
  470. return 0;
  471. }
  472. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  473. {
  474. for (int i = 0; i < n_columns; i++)
  475. {
  476. DEBUG_INFO("%s\t", col_values[i]);
  477. }
  478. DEBUG_INFO("\n");
  479. return 0;
  480. }
  481. int OCPP_cleanLocalCache()
  482. {
  483. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  484. char *errMsg = 0;
  485. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  486. if (SQLITE_OK != rc)
  487. {
  488. DEBUG_INFO("SQL error: %s\n",errMsg);
  489. return FALSE;
  490. }
  491. return TRUE;
  492. }
  493. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  494. {
  495. int isSuccess = TRUE;
  496. int ret = 0;
  497. //const char* data = "Callback function called";
  498. char sql[300];
  499. char zErrMsg[200];
  500. memset(sql, 0, 300);
  501. memset(zErrMsg, 0, 200);
  502. 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);
  503. //* Execute SQL statement */
  504. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  505. if( ret != SQLITE_OK )
  506. {
  507. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  508. isSuccess = FALSE;
  509. }
  510. return isSuccess;
  511. }
  512. void OCPP_getIdTagFromLocalCache(char idTag[])
  513. {
  514. int rc = 0;
  515. char sql[100];
  516. char zErrMsg[100];
  517. memset(sql, 0, 100);
  518. memset(zErrMsg, 0, 100);
  519. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  520. memset(&idTagQuery, 0, sizeof(idTagQuery));
  521. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  522. /* Execute SQL statement */
  523. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  524. if( rc != SQLITE_OK )
  525. {
  526. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  527. }
  528. }
  529. void OCPP_getListVerion()
  530. {
  531. int rc = 0;
  532. // const char* data = "Callback function called";
  533. char sql[100];
  534. char zErrMsg[100];
  535. memset(sql, 0, 100);
  536. memset(zErrMsg, 0, 100);
  537. strcpy(sql, "select * from ocpp_auth_local order by version desc, idx desc limit 1");
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. }
  545. void OCPP_get_TableAuthlocalAllData(void)
  546. {
  547. int rc = 0;
  548. char sql[100];
  549. char zErrMsg[100];
  550. memset(sql, 0, 100);
  551. memset(zErrMsg, 0, 100);
  552. sprintf(sql,"select * from ocpp_auth_local ");
  553. /* Execute SQL statement */
  554. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  555. if( rc != SQLITE_OK )
  556. {
  557. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  558. }
  559. //return ver;
  560. }
  561. int OCPP_cleanLocalList()
  562. {
  563. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  564. char *errMsg = 0;
  565. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  566. if (SQLITE_OK != rc)
  567. {
  568. DEBUG_INFO("%s\n",errMsg);
  569. return FALSE;
  570. }
  571. return TRUE;
  572. }
  573. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  574. {
  575. int isSuccess = FALSE;
  576. int ret = 0;
  577. //const char* data = "Callback function called";
  578. char sql[300];
  579. char zErrMsg[200];
  580. memset(sql, 0, 300);
  581. memset(zErrMsg, 0, 200);
  582. 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);
  583. //* Execute SQL statement */
  584. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  585. if( ret != SQLITE_OK )
  586. {
  587. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  588. return isSuccess;
  589. }
  590. memset(sql, 0, 300);
  591. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  592. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  593. if( ret != SQLITE_OK )
  594. {
  595. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  596. return isSuccess;
  597. }
  598. isSuccess = TRUE;
  599. return isSuccess;
  600. }
  601. void OCPP_getIdTagFromLocalList(char idTag[])
  602. {
  603. int rc = 0;
  604. // const char* data = "Callback function called";
  605. char sql[100];
  606. char zErrMsg[100];
  607. memset(sql, 0, 100);
  608. memset(zErrMsg, 0, 100);
  609. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  610. memset(&idTagQuery, 0, sizeof(idTagQuery));
  611. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  612. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  613. /* Execute SQL statement */
  614. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  615. if( rc != SQLITE_OK )
  616. {
  617. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  618. }
  619. //return ver;
  620. }
  621. void OCPP_deleteIdTagFromLocalList(char idTag[])
  622. {
  623. //int ver = 0;
  624. //int isSuccess = FALSE;
  625. int rc = 0;
  626. char sql[100];
  627. char zErrMsg[100];
  628. memset(sql, 0, 100);
  629. memset(zErrMsg, 0, 100);
  630. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  631. //* Execute SQL statement */
  632. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  633. if( rc != SQLITE_OK )
  634. {
  635. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  636. }
  637. }
  638. int getCurrentYear()
  639. {
  640. int result = 0;
  641. time_t CurrentTime;
  642. struct tm *tm;
  643. CurrentTime = time(NULL);
  644. tm=localtime(&CurrentTime);
  645. result = (tm->tm_year + 1900);
  646. return result;
  647. }
  648. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  649. {
  650. int result = PASS;
  651. char* errMsg = NULL;
  652. char sqlStr[8192];
  653. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  654. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  655. {
  656. result = FAIL;
  657. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  658. }
  659. 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));
  660. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  661. {
  662. result = FAIL;
  663. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  664. }
  665. return result;
  666. }
  667. //==========================================
  668. // Check time passed since today
  669. //==========================================
  670. long long DiffTimebWithNow(struct timeb ST)
  671. {
  672. //return milli-second
  673. struct timeb ET;
  674. long long StartTime,StopTime;
  675. ftime(&ET);
  676. StartTime=(long long)ST.time;
  677. StopTime=(long long)ET.time;
  678. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  679. }
  680. int getTimePassSinceToday(uint8_t gun_index)
  681. {
  682. int result = -1;
  683. static time_t lastTime[4];
  684. time_t t;
  685. struct tm *tmStartToday;
  686. struct timeb tbStartToday;
  687. t=time(NULL);
  688. if(difftime(t, lastTime[gun_index])>0)
  689. {
  690. tmStartToday=localtime(&t);
  691. tmStartToday->tm_hour = 0;
  692. tmStartToday->tm_min = 0;
  693. tmStartToday->tm_sec = 0;
  694. tbStartToday.time = mktime(tmStartToday);
  695. tbStartToday.millitm = 0;
  696. result = DiffTimebWithNow(tbStartToday)/1000;
  697. lastTime[gun_index] = t;
  698. }
  699. return result;
  700. }
  701. void getNowDatetime(uint8_t *data)
  702. {
  703. time_t t = time(NULL);
  704. struct tm tm = *localtime(&t);
  705. 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);
  706. }
  707. int syncDateTimeRTC(uint8_t *data)
  708. {
  709. struct ParsingResult
  710. {
  711. int result;
  712. int scanedElement;
  713. int year;
  714. int month;
  715. int mday;
  716. int hour;
  717. int min;
  718. int sec;
  719. int tz_hour;
  720. int tz_min;
  721. float minSec;
  722. }result;
  723. struct tm tmOrg;
  724. struct tm *tmTarget;
  725. struct timeb tbTarget;
  726. char buf[128];
  727. memset(&result, 0x00, sizeof(struct ParsingResult));
  728. result.result = PASS;
  729. if(strstr((char*)data, ".") != NULL)
  730. {
  731. // Original data with mini second
  732. if(strstr((char*)data, "Z") != NULL)
  733. {
  734. // Original data with Z
  735. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  736. &result.year,
  737. &result.month,
  738. &result.mday,
  739. &result.hour,
  740. &result.min,
  741. &result.sec,
  742. &result.minSec);
  743. }
  744. else
  745. {
  746. // Original data without Z
  747. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  748. &result.year,
  749. &result.month,
  750. &result.mday,
  751. &result.hour,
  752. &result.min,
  753. &result.sec,
  754. &result.minSec,
  755. &result.tz_hour,
  756. &result.tz_min);
  757. }
  758. }
  759. else
  760. {
  761. // Original data without mini second
  762. if(strstr((char*)data, "Z") != NULL)
  763. {
  764. // Original data with Z
  765. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  766. &result.year,
  767. &result.month,
  768. &result.mday,
  769. &result.hour,
  770. &result.min,
  771. &result.sec);
  772. }
  773. else
  774. {
  775. // Original data without Z
  776. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  777. &result.year,
  778. &result.month,
  779. &result.mday,
  780. &result.hour,
  781. &result.min,
  782. &result.sec,
  783. &result.tz_hour,
  784. &result.tz_min);
  785. }
  786. }
  787. tmOrg.tm_year = result.year - 1900;
  788. tmOrg.tm_mon = result.month - 1;
  789. tmOrg.tm_mday = result.mday;
  790. tmOrg.tm_hour = result.hour;
  791. tmOrg.tm_min = result.min;
  792. tmOrg.tm_sec = result.sec;
  793. tmOrg.tm_gmtoff = 0;
  794. tbTarget.time = mktime(&tmOrg);
  795. tbTarget.timezone = 0;
  796. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  797. tmTarget = gmtime(&tbTarget.time);
  798. 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);
  799. //DEBUG_INFO(" org date time: %s\n", data);
  800. //DEBUG_INFO("parse date time: %s\n", buf);
  801. system(buf);
  802. system("/sbin/hwclock -w --systohc");
  803. if(result.scanedElement < 6)
  804. result.result = FAIL;
  805. return result.result;
  806. }
  807. //==========================================
  808. // GetCompositeSchedule logic related function
  809. //==========================================
  810. int DiffTimebSec(struct timeb ST, struct timeb ET)
  811. {
  812. //return milli-second
  813. unsigned int StartTime,StopTime;
  814. StartTime=(unsigned int)ST.time;
  815. StopTime=(unsigned int)ET.time;
  816. return (StopTime-StartTime);
  817. }
  818. int DiffTimebWithNowSec(struct timeb ST)
  819. {
  820. //return milli-second
  821. struct timeb ET;
  822. unsigned int StartTime,StopTime;
  823. ftime(&ET);
  824. StartTime=(unsigned int)ST.time;
  825. StopTime=(unsigned int)ET.time;
  826. return (StopTime-StartTime);
  827. }
  828. int getStartStop(uint8_t *start, uint8_t *stop)
  829. {
  830. int result = -1;
  831. struct tm tmStart;
  832. struct timeb tbStart;
  833. struct tm tmStop;
  834. struct timeb tbStop;
  835. 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) &&
  836. (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))
  837. {
  838. //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);
  839. //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);
  840. tmStart.tm_year -= 1900;
  841. tmStart.tm_mon -= 1;
  842. tbStart.time = mktime(&tmStart);
  843. tbStart.millitm = 0;
  844. tmStop.tm_year -= 1900;
  845. tmStop.tm_mon -= 1;
  846. tbStop.time = mktime(&tmStop);
  847. tbStop.millitm = 0;
  848. result = DiffTimebSec(tbStart, tbStop);
  849. //DEBUG_INFO("getStartStop(): %d\n", result);
  850. }
  851. else
  852. {
  853. DEBUG_WARN("Start or stop date parsing error.\r\n");
  854. }
  855. return result;
  856. }
  857. int isOvertNow(uint8_t *start)
  858. {
  859. int result = NO;
  860. struct tm tmStart;
  861. struct timeb tbStart;
  862. 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))
  863. {
  864. //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);
  865. tmStart.tm_year -= 1900;
  866. tmStart.tm_mon -= 1;
  867. tbStart.time = mktime(&tmStart);
  868. tbStart.millitm = 0;
  869. if(DiffTimebWithNowSec(tbStart) <= 0)
  870. result = NO;
  871. else
  872. result = YES;
  873. }
  874. else
  875. {
  876. DEBUG_WARN("Start date parsing error.\n");
  877. }
  878. return result;
  879. }
  880. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  881. {
  882. int result = -1;
  883. struct tm tmStart;
  884. struct timeb tbStart;
  885. struct tm tmStop;
  886. struct timeb tbStop;
  887. 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) &&
  888. (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))
  889. {
  890. tmStart.tm_year -= 1900;
  891. tmStart.tm_mon -= 1;
  892. tbStart.time = mktime(&tmStart);
  893. tbStart.millitm = 0;
  894. tmStop.tm_year -= 1900;
  895. tmStop.tm_mon -= 1;
  896. tbStop.time = mktime(&tmStop);
  897. tbStop.millitm = 0;
  898. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  899. }
  900. return result;
  901. }
  902. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  903. {
  904. FILE *fp;
  905. char profileFileName[128];
  906. char *line = NULL;
  907. size_t len = 0;
  908. time_t CurrentTime;
  909. struct tm *tmComposite;
  910. struct StructChargingProfile maxProfile;
  911. uint8_t limitMax=0;
  912. int compositePeriodIdx = 0;
  913. CurrentTime = time(NULL);
  914. tmComposite=localtime(&CurrentTime);
  915. 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);
  916. if(isUnitA)
  917. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  918. else
  919. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  920. compositeProfile->ChargingSchedule.Duration = durationReq;
  921. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  922. {
  923. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  924. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  925. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  926. }
  927. compositeProfile->ChargingProfileId = 0;
  928. compositeProfile->StackLevel = 99 ;
  929. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  930. maxProfile.ChargingProfileId = -1;
  931. maxProfile.ChargingSchedule.Duration = -1;
  932. system("rm -f /tmp/*.json");
  933. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  934. // Search max profile
  935. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  936. if((access(profileFileName, F_OK))!=-1)
  937. {
  938. fp = fopen(profileFileName, "r");
  939. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  940. {
  941. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  942. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  943. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  944. }
  945. maxProfile.ChargingProfileId = -1;
  946. maxProfile.StackLevel = -1;
  947. while(getline(&line, &len, fp) != -1)
  948. {
  949. json_object *obj = NULL;
  950. obj = json_tokener_parse(line);
  951. if(is_error(obj))
  952. {
  953. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  954. }
  955. else
  956. {
  957. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  958. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  959. )
  960. {
  961. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  962. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  963. )
  964. {
  965. struct tm tmFrom, tmTo;
  966. struct timeb tbFrom, tbTo;
  967. 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) &&
  968. (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))
  969. {
  970. tmFrom.tm_year -= 1900;
  971. tmFrom.tm_mon -= 1;
  972. tbFrom.time = mktime(&tmFrom);
  973. tmTo.tm_year -= 1900;
  974. tmTo.tm_mon -= 1;
  975. tbTo.time = mktime(&tmTo);
  976. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  977. {
  978. if(maxProfile.ChargingProfileId == -1)
  979. DEBUG_INFO("MaxProfile found.\n");
  980. else
  981. DEBUG_INFO("MaxProfile updated.\n");
  982. // Required item
  983. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  984. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  985. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  986. if(isUnitA)
  987. {
  988. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  989. 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++)
  990. {
  991. 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"));
  992. 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?
  993. 3:
  994. 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")));
  995. 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")));
  996. }
  997. }
  998. else
  999. {
  1000. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1001. 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++)
  1002. {
  1003. 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"));
  1004. 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?
  1005. 3:
  1006. 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")));
  1007. 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));
  1008. }
  1009. }
  1010. // Optional item
  1011. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1012. {
  1013. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1014. }
  1015. else
  1016. {
  1017. sprintf((char*)maxProfile.ValidFrom, " ");
  1018. }
  1019. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1020. {
  1021. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1022. }
  1023. else
  1024. {
  1025. sprintf((char*)maxProfile.ValidTo, " ");
  1026. }
  1027. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1028. {
  1029. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1030. }
  1031. else
  1032. {
  1033. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1034. }
  1035. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1036. {
  1037. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1038. }
  1039. else
  1040. {
  1041. maxProfile.TransactionId = -1;
  1042. }
  1043. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1044. {
  1045. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1046. }
  1047. else
  1048. {
  1049. maxProfile.ChargingSchedule.Duration = 86400;
  1050. }
  1051. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1052. {
  1053. 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")));
  1054. }
  1055. else
  1056. {
  1057. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1058. }
  1059. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1060. {
  1061. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1062. }
  1063. else
  1064. {
  1065. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1066. }
  1067. }
  1068. }
  1069. }
  1070. else
  1071. {
  1072. if(maxProfile.ChargingProfileId == -1)
  1073. DEBUG_INFO("MaxProfile found.\n");
  1074. else
  1075. DEBUG_INFO("MaxProfile updated.\n");
  1076. // Required item
  1077. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1078. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1079. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1080. if(isUnitA)
  1081. {
  1082. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1083. 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++)
  1084. {
  1085. 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"));
  1086. 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?
  1087. 3:
  1088. 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")));
  1089. 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")));
  1090. }
  1091. }
  1092. else
  1093. {
  1094. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1095. 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++)
  1096. {
  1097. 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"));
  1098. 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?
  1099. 3:
  1100. 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")));
  1101. 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));
  1102. }
  1103. }
  1104. // Optional item
  1105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1106. {
  1107. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1108. }
  1109. else
  1110. {
  1111. sprintf((char*)maxProfile.ValidFrom, " ");
  1112. }
  1113. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1114. {
  1115. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1116. }
  1117. else
  1118. {
  1119. sprintf((char*)maxProfile.ValidTo, " ");
  1120. }
  1121. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1122. {
  1123. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1124. }
  1125. else
  1126. {
  1127. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1128. }
  1129. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1130. {
  1131. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1132. }
  1133. else
  1134. {
  1135. maxProfile.TransactionId = -1;
  1136. }
  1137. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1138. {
  1139. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1140. }
  1141. else
  1142. {
  1143. maxProfile.ChargingSchedule.Duration = 86400;
  1144. }
  1145. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1146. {
  1147. 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")));
  1148. }
  1149. else
  1150. {
  1151. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1152. }
  1153. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1154. {
  1155. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1156. }
  1157. else
  1158. {
  1159. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1160. }
  1161. }
  1162. }
  1163. }
  1164. json_object_put(obj);
  1165. }
  1166. fclose(fp);
  1167. /*
  1168. if(maxProfile.ChargingProfileId !=-1)
  1169. {
  1170. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1171. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1172. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1173. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1174. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1175. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1176. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1177. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1178. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1179. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1180. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1181. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1182. {
  1183. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1184. {
  1185. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1186. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1187. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1188. }
  1189. }
  1190. }
  1191. else
  1192. DEBUG_INFO("MaxProfile not found.\n");
  1193. DEBUG_INFO("------------------------------------\n");*/
  1194. }
  1195. if(maxProfile.ChargingProfileId != -1)
  1196. {
  1197. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1198. {
  1199. if(maxProfile.ChargingSchedule.Duration != -1)
  1200. {
  1201. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1202. 0:
  1203. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1204. }
  1205. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1206. {
  1207. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1208. {
  1209. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1210. 0:
  1211. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1212. if(idxPeriod > 0)
  1213. {
  1214. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1215. {
  1216. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. }
  1222. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1223. {
  1224. if(maxProfile.ChargingSchedule.Duration != -1)
  1225. {
  1226. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1227. }
  1228. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1229. {
  1230. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1231. {
  1232. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1233. if(idxPeriod > 0)
  1234. {
  1235. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1236. {
  1237. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1238. }
  1239. }
  1240. }
  1241. }
  1242. }
  1243. else
  1244. {
  1245. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1246. {
  1247. if(maxProfile.ChargingSchedule.Duration != -1)
  1248. {
  1249. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1250. 0:
  1251. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1252. }
  1253. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1254. {
  1255. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1256. {
  1257. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1258. 0:
  1259. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1260. if(idxPeriod > 0)
  1261. {
  1262. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1263. {
  1264. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1265. }
  1266. }
  1267. }
  1268. }
  1269. }
  1270. else
  1271. {
  1272. if(maxProfile.ChargingSchedule.Duration != -1)
  1273. {
  1274. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1275. 0:
  1276. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1277. }
  1278. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1279. {
  1280. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1281. {
  1282. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1283. 0:
  1284. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1285. if(idxPeriod > 0)
  1286. {
  1287. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1288. {
  1289. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }
  1296. /*
  1297. DEBUG_INFO("MaxProfile after align.\n");
  1298. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1299. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1300. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1301. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1302. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1303. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1304. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1305. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1306. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1307. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1308. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1309. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1310. {
  1311. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1312. {
  1313. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1314. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1315. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1316. }
  1317. }
  1318. DEBUG_INFO("------------------------------------\n");*/
  1319. }
  1320. // Find each profile period quantity
  1321. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1322. {
  1323. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1324. limitMax = idx+1;
  1325. }
  1326. if(maxProfile.ChargingProfileId != -1)
  1327. {
  1328. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1329. {
  1330. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1331. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1332. (maxProfile.ChargingSchedule.Duration > 0))
  1333. {
  1334. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1335. {
  1336. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1337. compositePeriodIdx++;
  1338. }
  1339. else
  1340. {
  1341. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1342. }
  1343. }
  1344. }
  1345. }
  1346. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1347. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1348. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1349. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1350. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1351. {
  1352. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1353. {
  1354. compositeProfile->ChargingProfileId = 1;
  1355. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1356. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1357. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1358. }
  1359. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1360. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1361. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1362. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1363. }
  1364. if(line)
  1365. free(line);
  1366. }
  1367. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1368. {
  1369. FILE *fp;
  1370. char profileFileName[128];
  1371. char *line = NULL;
  1372. size_t len = 0;
  1373. time_t CurrentTime;
  1374. struct tm *tmComposite;
  1375. struct StructChargingProfile maxProfile;
  1376. struct StructChargingProfile defaultTxProfile;
  1377. struct StructChargingProfile txProfile;
  1378. struct StructChargingSchedulePeriod tmpPeriod;
  1379. uint8_t limitMax=0;
  1380. uint8_t limitDef=0;
  1381. uint8_t limitTx=0;
  1382. int compositePeriodIdx = 0;
  1383. CurrentTime = time(NULL);
  1384. tmComposite=localtime(&CurrentTime);
  1385. 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);
  1386. if(isUnitA)
  1387. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1388. else
  1389. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1390. compositeProfile->ChargingSchedule.Duration = durationReq;
  1391. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1392. {
  1393. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1394. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1395. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1396. }
  1397. compositeProfile->ChargingProfileId = 0;
  1398. compositeProfile->StackLevel = 99 ;
  1399. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1400. maxProfile.ChargingProfileId = -1;
  1401. defaultTxProfile.ChargingProfileId = -1;
  1402. txProfile.ChargingProfileId = -1;
  1403. maxProfile.ChargingSchedule.Duration = -1;
  1404. defaultTxProfile.ChargingSchedule.Duration = -1;
  1405. txProfile.ChargingSchedule.Duration = -1;
  1406. system("rm -f /tmp/*.json");
  1407. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1408. /*
  1409. * Search valid charging profile
  1410. */
  1411. //DEBUG_INFO("====================================\n");
  1412. // Search tx profile
  1413. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1414. if((access(profileFileName, F_OK))!=-1)
  1415. {
  1416. fp = fopen(profileFileName, "r");
  1417. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1418. {
  1419. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1420. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1421. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1422. }
  1423. txProfile.ChargingProfileId = -1;
  1424. txProfile.StackLevel = -1;
  1425. while(getline(&line, &len, fp) != -1)
  1426. {
  1427. json_object *obj = NULL;
  1428. obj = json_tokener_parse(line);
  1429. if(is_error(obj))
  1430. {
  1431. DEBUG_ERROR("Parse txProfile from file error.\n");
  1432. }
  1433. else
  1434. {
  1435. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1436. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1437. )
  1438. {
  1439. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1440. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1441. )
  1442. {
  1443. struct tm tmFrom, tmTo;
  1444. struct timeb tbFrom, tbTo;
  1445. 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) &&
  1446. (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))
  1447. {
  1448. tmFrom.tm_year -= 1900;
  1449. tmFrom.tm_mon -= 1;
  1450. tbFrom.time = mktime(&tmFrom);
  1451. tmTo.tm_year -= 1900;
  1452. tmTo.tm_mon -= 1;
  1453. tbTo.time = mktime(&tmTo);
  1454. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1455. {
  1456. if(txProfile.ChargingProfileId == -1)
  1457. DEBUG_INFO("TxProfile found.\n");
  1458. else
  1459. DEBUG_INFO("TxProfile updated.\n");
  1460. // Required item
  1461. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1462. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1463. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1464. if(isUnitA)
  1465. {
  1466. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1467. 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++)
  1468. {
  1469. 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"));
  1470. 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?
  1471. 3:
  1472. 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")));
  1473. 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")));
  1474. }
  1475. }
  1476. else
  1477. {
  1478. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1479. 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++)
  1480. {
  1481. 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"));
  1482. 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?
  1483. 3:
  1484. 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")));
  1485. 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));
  1486. }
  1487. }
  1488. // Optional item
  1489. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1490. {
  1491. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1492. }
  1493. else
  1494. {
  1495. sprintf((char*)txProfile.ValidFrom, " ");
  1496. }
  1497. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1498. {
  1499. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1500. }
  1501. else
  1502. {
  1503. sprintf((char*)txProfile.ValidTo, " ");
  1504. }
  1505. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1506. {
  1507. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1508. }
  1509. else
  1510. {
  1511. sprintf((char*)txProfile.RecurrencyKind, " ");
  1512. }
  1513. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1514. {
  1515. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1516. }
  1517. else
  1518. {
  1519. txProfile.TransactionId = -1;
  1520. }
  1521. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1522. {
  1523. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1524. }
  1525. else
  1526. {
  1527. txProfile.ChargingSchedule.Duration = 86400;
  1528. }
  1529. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1530. {
  1531. 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")));
  1532. }
  1533. else
  1534. {
  1535. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1536. }
  1537. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1538. {
  1539. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1540. }
  1541. else
  1542. {
  1543. txProfile.ChargingSchedule.MinChargingRate = -1;
  1544. }
  1545. }
  1546. }
  1547. }
  1548. else
  1549. {
  1550. if(txProfile.ChargingProfileId == -1)
  1551. DEBUG_INFO("TxProfile found.\n");
  1552. else
  1553. DEBUG_INFO("TxProfile updated.\n");
  1554. // Required item
  1555. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1556. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1557. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1558. if(isUnitA)
  1559. {
  1560. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1561. 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++)
  1562. {
  1563. 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"));
  1564. 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?
  1565. 3:
  1566. 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")));
  1567. 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")));
  1568. }
  1569. }
  1570. else
  1571. {
  1572. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1573. 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++)
  1574. {
  1575. 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"));
  1576. 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?
  1577. 3:
  1578. 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")));
  1579. 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));
  1580. }
  1581. }
  1582. // Optional item
  1583. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1584. {
  1585. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1586. }
  1587. else
  1588. {
  1589. sprintf((char*)txProfile.ValidFrom, " ");
  1590. }
  1591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1592. {
  1593. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1594. }
  1595. else
  1596. {
  1597. sprintf((char*)txProfile.ValidTo, " ");
  1598. }
  1599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1600. {
  1601. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1602. }
  1603. else
  1604. {
  1605. sprintf((char*)txProfile.RecurrencyKind, " ");
  1606. }
  1607. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1608. {
  1609. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1610. }
  1611. else
  1612. {
  1613. txProfile.TransactionId = -1;
  1614. }
  1615. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1616. {
  1617. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1618. }
  1619. else
  1620. {
  1621. txProfile.ChargingSchedule.Duration = 86400;
  1622. }
  1623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1624. {
  1625. 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")));
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1630. }
  1631. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1632. {
  1633. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1634. }
  1635. else
  1636. {
  1637. txProfile.ChargingSchedule.MinChargingRate = -1;
  1638. }
  1639. }
  1640. }
  1641. }
  1642. json_object_put(obj);
  1643. }
  1644. fclose(fp);
  1645. /*
  1646. if(txProfile.ChargingProfileId != -1)
  1647. {
  1648. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1649. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1650. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1651. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1652. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1653. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1654. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1655. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1656. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1657. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1658. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1659. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1660. {
  1661. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1662. {
  1663. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1664. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1665. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1666. }
  1667. }
  1668. }
  1669. else
  1670. DEBUG_INFO("TxProfile not found.\n");*/
  1671. }
  1672. // Search default tx profile
  1673. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1674. if((access(profileFileName, F_OK))==-1)
  1675. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1676. if((access(profileFileName, F_OK))!=-1)
  1677. {
  1678. fp = fopen(profileFileName, "r");
  1679. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1680. {
  1681. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1682. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1683. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1684. }
  1685. defaultTxProfile.ChargingProfileId = -1;
  1686. defaultTxProfile.StackLevel = -1;
  1687. while(getline(&line, &len, fp) != -1)
  1688. {
  1689. json_object *obj = NULL;
  1690. obj = json_tokener_parse(line);
  1691. if(is_error(obj))
  1692. {
  1693. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1694. }
  1695. else
  1696. {
  1697. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1698. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1699. )
  1700. {
  1701. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1702. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1703. )
  1704. {
  1705. struct tm tmFrom, tmTo;
  1706. struct timeb tbFrom, tbTo;
  1707. 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) &&
  1708. (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))
  1709. {
  1710. tmFrom.tm_year -= 1900;
  1711. tmFrom.tm_mon -= 1;
  1712. tbFrom.time = mktime(&tmFrom);
  1713. tmTo.tm_year -= 1900;
  1714. tmTo.tm_mon -= 1;
  1715. tbTo.time = mktime(&tmTo);
  1716. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1717. {
  1718. if(defaultTxProfile.ChargingProfileId == -1)
  1719. DEBUG_INFO("TxDefaultProfile found.\n");
  1720. else
  1721. DEBUG_INFO("TxDefaultProfile updated.\n");
  1722. // Required item
  1723. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1724. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1725. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1726. if(isUnitA)
  1727. {
  1728. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1729. 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++)
  1730. {
  1731. 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"));
  1732. 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?
  1733. 3:
  1734. 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")));
  1735. 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")));
  1736. }
  1737. }
  1738. else
  1739. {
  1740. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1741. 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++)
  1742. {
  1743. 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"));
  1744. 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?
  1745. 3:
  1746. 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")));
  1747. 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));
  1748. }
  1749. }
  1750. // Optional item
  1751. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1752. {
  1753. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1754. }
  1755. else
  1756. {
  1757. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1758. }
  1759. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1760. {
  1761. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1762. }
  1763. else
  1764. {
  1765. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1766. }
  1767. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1768. {
  1769. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1770. }
  1771. else
  1772. {
  1773. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1774. }
  1775. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1776. {
  1777. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1778. }
  1779. else
  1780. {
  1781. defaultTxProfile.TransactionId = -1;
  1782. }
  1783. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1784. {
  1785. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1786. }
  1787. else
  1788. {
  1789. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1790. }
  1791. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1792. {
  1793. 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")));
  1794. }
  1795. else
  1796. {
  1797. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1798. }
  1799. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1800. {
  1801. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1802. }
  1803. else
  1804. {
  1805. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1806. }
  1807. }
  1808. }
  1809. }
  1810. else
  1811. {
  1812. if(defaultTxProfile.ChargingProfileId == -1)
  1813. DEBUG_INFO("TxDefaultProfile found.\n");
  1814. else
  1815. DEBUG_INFO("TxDefaultProfile updated.\n");
  1816. // Required item
  1817. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1818. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1819. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1820. if(isUnitA)
  1821. {
  1822. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1823. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1824. {
  1825. 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"));
  1826. 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?
  1827. 3:
  1828. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1829. 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")));
  1830. }
  1831. }
  1832. else
  1833. {
  1834. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1835. 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++)
  1836. {
  1837. 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"));
  1838. 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?
  1839. 3:
  1840. 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")));
  1841. 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));
  1842. }
  1843. }
  1844. // Optional item
  1845. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1846. {
  1847. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1848. }
  1849. else
  1850. {
  1851. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1852. }
  1853. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1854. {
  1855. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1856. }
  1857. else
  1858. {
  1859. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1860. }
  1861. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1862. {
  1863. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1864. }
  1865. else
  1866. {
  1867. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1868. }
  1869. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1870. {
  1871. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1872. }
  1873. else
  1874. {
  1875. defaultTxProfile.TransactionId = -1;
  1876. }
  1877. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1880. }
  1881. else
  1882. {
  1883. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1884. }
  1885. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1886. {
  1887. 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")));
  1888. }
  1889. else
  1890. {
  1891. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1892. }
  1893. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1894. {
  1895. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1896. }
  1897. else
  1898. {
  1899. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1900. }
  1901. }
  1902. }
  1903. }
  1904. json_object_put(obj);
  1905. }
  1906. fclose(fp);
  1907. /*
  1908. if(defaultTxProfile.ChargingProfileId != -1)
  1909. {
  1910. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1911. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1912. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1913. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1914. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1915. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1916. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1917. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1918. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1919. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1920. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1921. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1922. {
  1923. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1924. {
  1925. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1926. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1927. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1928. }
  1929. }
  1930. }
  1931. else
  1932. DEBUG_INFO("TxDefaultProfile not found.\n");
  1933. DEBUG_INFO("------------------------------------\n");*/
  1934. }
  1935. // Search max profile
  1936. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1937. if((access(profileFileName, F_OK))!=-1)
  1938. {
  1939. fp = fopen(profileFileName, "r");
  1940. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1941. {
  1942. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1943. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1944. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1945. }
  1946. maxProfile.ChargingProfileId = -1;
  1947. maxProfile.StackLevel = -1;
  1948. while(getline(&line, &len, fp) != -1)
  1949. {
  1950. json_object *obj = NULL;
  1951. obj = json_tokener_parse(line);
  1952. if(is_error(obj))
  1953. {
  1954. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1955. }
  1956. else
  1957. {
  1958. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1959. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1960. )
  1961. {
  1962. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1963. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1964. )
  1965. {
  1966. struct tm tmFrom, tmTo;
  1967. struct timeb tbFrom, tbTo;
  1968. 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) &&
  1969. (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))
  1970. {
  1971. tmFrom.tm_year -= 1900;
  1972. tmFrom.tm_mon -= 1;
  1973. tbFrom.time = mktime(&tmFrom);
  1974. tmTo.tm_year -= 1900;
  1975. tmTo.tm_mon -= 1;
  1976. tbTo.time = mktime(&tmTo);
  1977. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1978. {
  1979. if(maxProfile.ChargingProfileId == -1)
  1980. DEBUG_INFO("MaxProfile found.\n");
  1981. else
  1982. DEBUG_INFO("MaxProfile updated.\n");
  1983. // Required item
  1984. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1985. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1986. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1987. if(isUnitA)
  1988. {
  1989. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1990. 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++)
  1991. {
  1992. 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"));
  1993. 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?
  1994. 3:
  1995. 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")));
  1996. 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")));
  1997. }
  1998. }
  1999. else
  2000. {
  2001. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2002. 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++)
  2003. {
  2004. 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"));
  2005. 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?
  2006. 3:
  2007. 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")));
  2008. 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));
  2009. }
  2010. }
  2011. // Optional item
  2012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2013. {
  2014. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2015. }
  2016. else
  2017. {
  2018. sprintf((char*)maxProfile.ValidFrom, " ");
  2019. }
  2020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2021. {
  2022. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2023. }
  2024. else
  2025. {
  2026. sprintf((char*)maxProfile.ValidTo, " ");
  2027. }
  2028. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2029. {
  2030. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2031. }
  2032. else
  2033. {
  2034. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2035. }
  2036. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2037. {
  2038. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2039. }
  2040. else
  2041. {
  2042. maxProfile.TransactionId = -1;
  2043. }
  2044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2045. {
  2046. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2047. }
  2048. else
  2049. {
  2050. maxProfile.ChargingSchedule.Duration = 86400;
  2051. }
  2052. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2053. {
  2054. 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")));
  2055. }
  2056. else
  2057. {
  2058. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2059. }
  2060. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2061. {
  2062. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2063. }
  2064. else
  2065. {
  2066. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2067. }
  2068. }
  2069. }
  2070. }
  2071. else
  2072. {
  2073. if(maxProfile.ChargingProfileId == -1)
  2074. DEBUG_INFO("MaxProfile found.\n");
  2075. else
  2076. DEBUG_INFO("MaxProfile updated.\n");
  2077. // Required item
  2078. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2079. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2080. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2081. if(isUnitA)
  2082. {
  2083. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2084. 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++)
  2085. {
  2086. 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"));
  2087. 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?
  2088. 3:
  2089. 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")));
  2090. 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")));
  2091. }
  2092. }
  2093. else
  2094. {
  2095. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2096. 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++)
  2097. {
  2098. 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"));
  2099. 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?
  2100. 3:
  2101. 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")));
  2102. 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));
  2103. }
  2104. }
  2105. // Optional item
  2106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2107. {
  2108. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2109. }
  2110. else
  2111. {
  2112. sprintf((char*)maxProfile.ValidFrom, " ");
  2113. }
  2114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2115. {
  2116. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2117. }
  2118. else
  2119. {
  2120. sprintf((char*)maxProfile.ValidTo, " ");
  2121. }
  2122. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2123. {
  2124. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2125. }
  2126. else
  2127. {
  2128. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2129. }
  2130. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2131. {
  2132. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2133. }
  2134. else
  2135. {
  2136. maxProfile.TransactionId = -1;
  2137. }
  2138. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2139. {
  2140. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2141. }
  2142. else
  2143. {
  2144. maxProfile.ChargingSchedule.Duration = 86400;
  2145. }
  2146. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2147. {
  2148. 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")));
  2149. }
  2150. else
  2151. {
  2152. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  2153. }
  2154. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2155. {
  2156. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2157. }
  2158. else
  2159. {
  2160. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2161. }
  2162. }
  2163. }
  2164. }
  2165. json_object_put(obj);
  2166. }
  2167. fclose(fp);
  2168. /*
  2169. if(maxProfile.ChargingProfileId !=-1)
  2170. {
  2171. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2172. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2173. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2174. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2175. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2176. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2177. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2178. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2179. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2180. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2181. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2182. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2183. {
  2184. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2185. {
  2186. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2187. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2188. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2189. }
  2190. }
  2191. }
  2192. else
  2193. DEBUG_INFO("MaxProfile not found.\n");
  2194. DEBUG_INFO("------------------------------------\n");*/
  2195. }
  2196. /*
  2197. * Align found profile start schedule & periods
  2198. */
  2199. //DEBUG_INFO("====================================\n");
  2200. /*
  2201. // For local test usage, force modify found profile start schedule info
  2202. 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);
  2203. 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);
  2204. 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);
  2205. */
  2206. if(txProfile.ChargingProfileId != -1)
  2207. {
  2208. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2209. {
  2210. if(txProfile.ChargingSchedule.Duration != -1)
  2211. {
  2212. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2213. 0:
  2214. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2215. }
  2216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2217. {
  2218. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2219. {
  2220. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2221. 0:
  2222. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2223. if(idxPeriod > 0)
  2224. {
  2225. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2226. {
  2227. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2228. }
  2229. }
  2230. }
  2231. }
  2232. }
  2233. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2234. {
  2235. if(txProfile.ChargingSchedule.Duration != -1)
  2236. {
  2237. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2238. 0:
  2239. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2240. }
  2241. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2242. {
  2243. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2244. {
  2245. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2246. 0:
  2247. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2248. if(idxPeriod > 0)
  2249. {
  2250. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2251. {
  2252. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2253. }
  2254. }
  2255. }
  2256. }
  2257. }
  2258. else
  2259. {
  2260. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2261. {
  2262. if(txProfile.ChargingSchedule.Duration != -1)
  2263. {
  2264. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2265. 0:
  2266. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2267. }
  2268. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2269. {
  2270. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2271. {
  2272. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2273. 0:
  2274. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2275. if(idxPeriod > 0)
  2276. {
  2277. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2278. {
  2279. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2280. }
  2281. }
  2282. }
  2283. }
  2284. }
  2285. else
  2286. {
  2287. if(txProfile.ChargingSchedule.Duration != -1)
  2288. {
  2289. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2290. 0:
  2291. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2292. }
  2293. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2294. {
  2295. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2296. {
  2297. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2298. 0:
  2299. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2300. if(idxPeriod > 0)
  2301. {
  2302. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2303. {
  2304. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. /*
  2312. DEBUG_INFO("txProfile after align.\n");
  2313. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2314. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2315. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2316. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2317. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2318. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2319. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2320. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2321. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2322. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2323. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2324. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2325. {
  2326. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2327. {
  2328. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2329. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2330. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2331. }
  2332. }*/
  2333. }
  2334. if(defaultTxProfile.ChargingProfileId != -1)
  2335. {
  2336. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2337. {
  2338. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2339. {
  2340. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2341. 0:
  2342. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2343. }
  2344. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2345. {
  2346. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2347. {
  2348. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2349. 0:
  2350. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2351. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2352. {
  2353. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2354. }
  2355. if(idxPeriod > 0)
  2356. {
  2357. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2358. {
  2359. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2360. }
  2361. }
  2362. }
  2363. }
  2364. }
  2365. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2366. {
  2367. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2368. {
  2369. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2370. 0:
  2371. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2372. }
  2373. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2374. {
  2375. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2376. {
  2377. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2378. 0:
  2379. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2380. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2381. {
  2382. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2383. }
  2384. if(idxPeriod > 0)
  2385. {
  2386. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2387. {
  2388. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2389. }
  2390. }
  2391. }
  2392. }
  2393. }
  2394. else
  2395. {
  2396. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2397. {
  2398. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2399. {
  2400. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2401. 0:
  2402. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2403. }
  2404. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2405. {
  2406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2407. {
  2408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2409. 0:
  2410. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2411. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2412. {
  2413. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2414. }
  2415. if(idxPeriod > 0)
  2416. {
  2417. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2418. {
  2419. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. else
  2426. {
  2427. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2428. {
  2429. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2430. 0:
  2431. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2432. }
  2433. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2434. {
  2435. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2436. {
  2437. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2438. 0:
  2439. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2440. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2441. {
  2442. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2443. }
  2444. if(idxPeriod > 0)
  2445. {
  2446. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2447. {
  2448. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2449. }
  2450. }
  2451. }
  2452. }
  2453. }
  2454. }
  2455. /*
  2456. DEBUG_INFO("defaultTxProfile after align.\n");
  2457. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2458. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2459. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2460. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2461. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2462. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2463. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2464. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2465. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2466. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2467. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2468. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2469. {
  2470. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2471. {
  2472. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2473. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2474. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2475. }
  2476. }
  2477. DEBUG_INFO("------------------------------------\n");*/
  2478. }
  2479. if(maxProfile.ChargingProfileId != -1)
  2480. {
  2481. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2482. {
  2483. if(maxProfile.ChargingSchedule.Duration != -1)
  2484. {
  2485. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2486. 0:
  2487. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2488. }
  2489. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2490. {
  2491. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2492. {
  2493. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2494. 0:
  2495. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2496. if(idxPeriod > 0)
  2497. {
  2498. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2499. {
  2500. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2501. }
  2502. }
  2503. }
  2504. }
  2505. }
  2506. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2507. {
  2508. if(maxProfile.ChargingSchedule.Duration != -1)
  2509. {
  2510. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2511. 0:
  2512. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2513. }
  2514. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2515. {
  2516. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2517. {
  2518. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2519. 0:
  2520. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2521. if(idxPeriod > 0)
  2522. {
  2523. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2524. {
  2525. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2526. }
  2527. }
  2528. }
  2529. }
  2530. }
  2531. else
  2532. {
  2533. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2534. {
  2535. if(maxProfile.ChargingSchedule.Duration != -1)
  2536. {
  2537. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2538. 0:
  2539. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2540. }
  2541. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2542. {
  2543. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2544. {
  2545. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2546. 0:
  2547. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2548. if(idxPeriod > 0)
  2549. {
  2550. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2551. {
  2552. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2553. }
  2554. }
  2555. }
  2556. }
  2557. }
  2558. else
  2559. {
  2560. if(maxProfile.ChargingSchedule.Duration != -1)
  2561. {
  2562. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2563. 0:
  2564. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2565. }
  2566. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2567. {
  2568. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2569. {
  2570. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2571. 0:
  2572. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2573. if(idxPeriod > 0)
  2574. {
  2575. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2576. {
  2577. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. /*
  2585. DEBUG_INFO("MaxProfile after align.\n");
  2586. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2587. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2588. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2589. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2590. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2591. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2592. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2593. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2594. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2595. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2596. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2597. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2598. {
  2599. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2600. {
  2601. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2602. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2603. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2604. }
  2605. }
  2606. DEBUG_INFO("------------------------------------\n");*/
  2607. }
  2608. /*
  2609. * Merge to conposite schedule
  2610. */
  2611. //DEBUG_INFO("====================================\n");
  2612. // Find each profile period quantity
  2613. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2614. {
  2615. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2616. limitMax = idx+1;
  2617. }
  2618. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2619. {
  2620. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2621. limitDef = idx+1;
  2622. }
  2623. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2624. {
  2625. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2626. limitTx = idx+1;
  2627. }
  2628. // TxProfile found, composite schedule based on it
  2629. if(txProfile.ChargingProfileId != -1)
  2630. {
  2631. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2632. {
  2633. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2634. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2635. (txProfile.ChargingSchedule.Duration > 0))
  2636. {
  2637. if(maxProfile.ChargingProfileId != -1)
  2638. {
  2639. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2640. {
  2641. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2642. {
  2643. if((maxProfile.ChargingSchedule.Duration > 0))
  2644. {
  2645. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2646. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2647. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2648. }
  2649. else
  2650. {
  2651. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2652. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2653. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2654. }
  2655. }
  2656. if(idxMaxPeriod == (limitMax-1))
  2657. {
  2658. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2659. {
  2660. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2661. {
  2662. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2663. compositePeriodIdx++;
  2664. }
  2665. else
  2666. {
  2667. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2668. }
  2669. }
  2670. }
  2671. }
  2672. }
  2673. else
  2674. {
  2675. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2676. {
  2677. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2678. compositePeriodIdx++;
  2679. }
  2680. else
  2681. {
  2682. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2683. }
  2684. }
  2685. }
  2686. if(idxTxPeriod == (limitTx-1))
  2687. {
  2688. if(defaultTxProfile.ChargingProfileId != -1)
  2689. {
  2690. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2691. {
  2692. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2693. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2694. (defaultTxProfile.ChargingSchedule.Duration>0))
  2695. {
  2696. if(maxProfile.ChargingProfileId != -1)
  2697. {
  2698. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2699. {
  2700. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2701. {
  2702. if((maxProfile.ChargingSchedule.Duration > 0))
  2703. {
  2704. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2705. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2706. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2707. }
  2708. else
  2709. {
  2710. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2711. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2712. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2713. }
  2714. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2715. {
  2716. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2717. {
  2718. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2719. compositePeriodIdx++;
  2720. }
  2721. else
  2722. {
  2723. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2724. }
  2725. }
  2726. // Delete duplicate period
  2727. if(compositePeriodIdx > 1)
  2728. {
  2729. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2730. {
  2731. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2732. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2733. compositePeriodIdx -= 1;
  2734. }
  2735. }
  2736. }
  2737. else
  2738. break;
  2739. }
  2740. }
  2741. else
  2742. {
  2743. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2744. {
  2745. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2746. compositePeriodIdx++;
  2747. }
  2748. else
  2749. {
  2750. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2751. }
  2752. }
  2753. }
  2754. }
  2755. }
  2756. }
  2757. }
  2758. }
  2759. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2760. else if(defaultTxProfile.ChargingProfileId != -1)
  2761. {
  2762. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2763. {
  2764. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2765. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2766. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2767. {
  2768. if(maxProfile.ChargingProfileId != -1)
  2769. {
  2770. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2771. {
  2772. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2773. {
  2774. if((maxProfile.ChargingSchedule.Duration > 0))
  2775. {
  2776. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2777. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2778. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2779. }
  2780. else
  2781. {
  2782. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2783. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2784. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2785. }
  2786. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2787. {
  2788. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2789. {
  2790. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2791. compositePeriodIdx++;
  2792. }
  2793. else
  2794. {
  2795. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2796. }
  2797. }
  2798. // Delete duplicate period
  2799. if(compositePeriodIdx > 1)
  2800. {
  2801. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2802. {
  2803. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2804. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2805. compositePeriodIdx -= 1;
  2806. }
  2807. }
  2808. }
  2809. else
  2810. break;
  2811. }
  2812. }
  2813. else
  2814. {
  2815. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2816. {
  2817. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2818. compositePeriodIdx++;
  2819. }
  2820. else
  2821. {
  2822. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2823. }
  2824. }
  2825. }
  2826. }
  2827. }
  2828. // Fill other period by MaxProfile
  2829. if(maxProfile.ChargingProfileId != -1)
  2830. {
  2831. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2832. {
  2833. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2834. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2835. (maxProfile.ChargingSchedule.Duration > 0))
  2836. {
  2837. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2838. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2839. {
  2840. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2841. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2842. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2843. }
  2844. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2845. {
  2846. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2847. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2848. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2849. }
  2850. if(tmpPeriod.Limit != -1)
  2851. {
  2852. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2853. {
  2854. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2855. {
  2856. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2857. compositePeriodIdx++;
  2858. }
  2859. else
  2860. {
  2861. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2862. }
  2863. }
  2864. // Delete duplicate period
  2865. if(compositePeriodIdx > 1)
  2866. {
  2867. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2868. {
  2869. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2870. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2871. compositePeriodIdx -= 1;
  2872. }
  2873. }
  2874. }
  2875. }
  2876. }
  2877. }
  2878. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2879. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2880. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2881. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2882. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2883. {
  2884. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2885. {
  2886. compositeProfile->ChargingProfileId = 1;
  2887. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2888. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2889. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2890. }
  2891. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2892. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2893. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2894. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2895. }
  2896. if(line)
  2897. free(line);
  2898. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  2899. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2900. }
  2901. //==========================================
  2902. // Init all share memory
  2903. //==========================================
  2904. int InitShareMemory()
  2905. {
  2906. int result = PASS;
  2907. int MeterSMId;
  2908. //creat ShmSysConfigAndInfo
  2909. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2910. {
  2911. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2912. result = FAIL;
  2913. }
  2914. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2915. {
  2916. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2917. result = FAIL;
  2918. }
  2919. else
  2920. {}
  2921. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2922. {
  2923. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2924. result = FAIL;
  2925. }
  2926. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2927. {
  2928. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2929. result = FAIL;
  2930. }
  2931. else
  2932. {}
  2933. //creat ShmPsuData
  2934. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2935. {
  2936. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2937. result = FAIL;
  2938. }
  2939. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2940. {
  2941. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2942. result = FAIL;
  2943. }
  2944. else
  2945. {}
  2946. //link ShmOCPP16Data
  2947. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2948. {
  2949. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2950. result = FAIL;
  2951. }
  2952. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2953. {
  2954. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2955. result = FAIL;
  2956. }
  2957. else
  2958. {}
  2959. //creat ShmOCPP16DataPH
  2960. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  2961. {
  2962. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  2963. result = FAIL;
  2964. }
  2965. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2966. {
  2967. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  2968. result = FAIL;
  2969. }
  2970. else
  2971. {}
  2972. /****************************** For Initial Settings************************************************/
  2973. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  2974. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  2975. // allocate Configuration memory address
  2976. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  2977. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2978. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2979. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2980. //offline MeterValue Interval
  2981. TempMeterValueInterval = 0;
  2982. return result;
  2983. }
  2984. int ProcessShareMemory()
  2985. {
  2986. if(InitShareMemory() == FAIL)
  2987. {
  2988. DEBUG_ERROR("InitShareMemory NG\n");
  2989. if(ShmStatusCodeData!=NULL)
  2990. {
  2991. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2992. }
  2993. sleep(5);
  2994. return FAIL;
  2995. }
  2996. return PASS;
  2997. }
  2998. void CheckSystemValue(void)
  2999. {
  3000. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3001. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3002. char filenmae[100]={0};
  3003. char str[100]={0};
  3004. int tempIndex = 0;
  3005. //===============================
  3006. // send Heartbeat
  3007. //===============================
  3008. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3009. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3010. {
  3011. clientTime.Heartbeat=time((time_t*)NULL);
  3012. if(server_sign == TRUE)
  3013. {
  3014. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3015. }
  3016. else
  3017. {
  3018. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3019. }
  3020. }
  3021. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3022. {
  3023. //parameter for test
  3024. sendHeartbeatRequest(0);
  3025. //==============================================
  3026. // Reset Waiting Time
  3027. //==============================================
  3028. HeartBeatWithNOResponse += 2;
  3029. }
  3030. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3031. {
  3032. //==========================================
  3033. // csu trigger DataTransferReq
  3034. //==========================================
  3035. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3036. {
  3037. sendDataTransferRequest(gun_index);
  3038. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3039. }
  3040. //===============================
  3041. // CSU Trigger Authorize Request
  3042. //===============================
  3043. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3044. {
  3045. sendAuthorizeRequest(0);
  3046. authorizeRetryTimes = authorizeRetryTimes + 1;
  3047. if(authorizeRetryTimes < 3)
  3048. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3049. }
  3050. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3051. {
  3052. authorizeRetryTimes = 0;
  3053. SetOcppConnStatus(FALSE);
  3054. server_sign = FALSE;
  3055. }
  3056. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0)&& (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1))
  3057. {
  3058. sendAuthorizeRequest(0);
  3059. }
  3060. //==============================================
  3061. // Charger start transaction
  3062. //==============================================
  3063. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3064. {
  3065. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3066. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3067. sendStartTransactionRequest(gun_index);
  3068. clientTime.StartTransaction = time((time_t*)NULL);
  3069. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3070. storeTempStopTransaction(gun_index);
  3071. }
  3072. //==============================================
  3073. // Charger stop transaction
  3074. //==============================================
  3075. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3076. {
  3077. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3078. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3079. sendStopTransactionRequest(gun_index);
  3080. clientTime.StopTransaction = time((time_t*)NULL);
  3081. }
  3082. //==============================================
  3083. // Charger status report
  3084. //==============================================
  3085. //--- Check Mode Change ---//
  3086. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3087. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3088. {
  3089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3090. {
  3091. tempIndex = ((gun_index==2) ? 1: 0);
  3092. }
  3093. else
  3094. {
  3095. tempIndex = gun_index;
  3096. }
  3097. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3098. {
  3099. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3100. {
  3101. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3102. {
  3103. // Sent unplug message for California pricing logic
  3104. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3105. {
  3106. uint8_t ts[20];
  3107. getNowDatetime(ts);
  3108. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3109. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3110. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3111. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3112. }
  3113. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3114. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3115. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3116. }
  3117. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3118. {
  3119. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3120. if((access(filenmae,F_OK))!=-1)
  3121. {
  3122. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3123. sprintf(str,"rm -f %s",filenmae);
  3124. system(str);
  3125. }
  3126. }
  3127. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3128. #if 1 // for TempStopTransaction
  3129. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3130. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3131. {
  3132. checkTempStopTransaction(gun_index);
  3133. }
  3134. #endif
  3135. }
  3136. }
  3137. }
  3138. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3139. {
  3140. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3141. {
  3142. tempIndex = ((gun_index==2) ? 1: 0);
  3143. }
  3144. else
  3145. {
  3146. tempIndex = gun_index;
  3147. }
  3148. for (int index = 0; index < CCS_QUANTITY; index++)
  3149. {
  3150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3151. {
  3152. 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]*/ )
  3153. {
  3154. // Sent unplug message for California pricing logic
  3155. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3156. {
  3157. uint8_t ts[20];
  3158. getNowDatetime(ts);
  3159. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3160. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3161. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3162. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3163. }
  3164. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3165. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3166. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3167. }
  3168. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3169. {
  3170. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3171. if((access(filenmae,F_OK))!=-1)
  3172. {
  3173. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3174. sprintf(str,"rm -f %s",filenmae);
  3175. system(str);
  3176. }
  3177. }
  3178. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3179. #if 1 // for TempStopTransaction
  3180. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3181. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3182. {
  3183. checkTempStopTransaction(gun_index);
  3184. }
  3185. #endif
  3186. }
  3187. }
  3188. }
  3189. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3190. {
  3191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3192. {
  3193. tempIndex = ((gun_index==2) ? 1: 0);
  3194. }
  3195. else
  3196. {
  3197. tempIndex = gun_index;
  3198. }
  3199. for (int index = 0; index < GB_QUANTITY; index++)
  3200. {
  3201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3202. {
  3203. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3204. {
  3205. // Sent unplug message for California pricing logic
  3206. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3207. {
  3208. uint8_t ts[20];
  3209. getNowDatetime(ts);
  3210. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3211. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3212. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3213. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3214. }
  3215. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3216. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3217. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3218. }
  3219. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3220. {
  3221. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3222. if((access(filenmae,F_OK))!=-1)
  3223. {
  3224. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3225. sprintf(str,"rm -f %s",filenmae);
  3226. system(str);
  3227. }
  3228. }
  3229. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3230. #if 1 // for TempStopTransaction
  3231. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3232. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3233. {
  3234. checkTempStopTransaction(gun_index);
  3235. }
  3236. #endif
  3237. }
  3238. }
  3239. }
  3240. else if(gunType[gun_index] == GUN_TYPE_DO)
  3241. {
  3242. tempIndex = gun_index;
  3243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3244. {
  3245. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3246. {
  3247. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3248. {
  3249. // Sent unplug message for California pricing logic
  3250. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3251. {
  3252. uint8_t ts[20];
  3253. getNowDatetime(ts);
  3254. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3255. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3256. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3257. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3258. }
  3259. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3260. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3261. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3262. }
  3263. 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
  3264. {
  3265. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3266. if((access(filenmae,F_OK))!=-1)
  3267. {
  3268. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3269. sprintf(str,"rm -f %s",filenmae);
  3270. system(str);
  3271. }
  3272. }
  3273. 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);
  3274. #if 1 // for TempStopTransaction
  3275. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3276. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3277. {
  3278. checkTempStopTransaction(gun_index);
  3279. }
  3280. #endif
  3281. }
  3282. }
  3283. }
  3284. else
  3285. {
  3286. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3287. {
  3288. tempIndex = 2;
  3289. }
  3290. else
  3291. {
  3292. tempIndex = gun_index;
  3293. }
  3294. for (int index = 0; index < AC_QUANTITY; index++)
  3295. {
  3296. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3297. {
  3298. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3299. {
  3300. // Sent unplug message for California pricing logic
  3301. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3302. {
  3303. uint8_t ts[20];
  3304. getNowDatetime(ts);
  3305. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3306. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3307. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3308. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3309. }
  3310. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3311. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3312. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3313. }
  3314. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  3315. {
  3316. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3317. if((access(filenmae,F_OK))!=-1)
  3318. {
  3319. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3320. sprintf(str,"rm -f %s",filenmae);
  3321. system(str);
  3322. }
  3323. }
  3324. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3325. #if 1 // for TempStopTransaction
  3326. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3327. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3328. {
  3329. checkTempStopTransaction(gun_index);
  3330. }
  3331. #endif
  3332. }
  3333. }// END
  3334. }
  3335. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3336. (
  3337. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3338. )
  3339. )
  3340. {
  3341. if(SystemInitial > 0)
  3342. SystemInitial -= 1;
  3343. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3344. sendStatusNotificationRequest(gun_index);
  3345. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3346. }
  3347. //==============================================
  3348. // CSU Trigger Smart Charging Profilw
  3349. //==============================================
  3350. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3351. {
  3352. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3353. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3354. }
  3355. //==============================================
  3356. // Meter report
  3357. //==============================================
  3358. // Trigger MeterValue
  3359. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3360. {
  3361. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3362. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3363. }
  3364. // ClockAlign MeterValue
  3365. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  3366. {
  3367. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3368. {
  3369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3370. {
  3371. tempIndex = ((gun_index==2) ? 1: 0);
  3372. }
  3373. else
  3374. {
  3375. tempIndex = gun_index;
  3376. }
  3377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3378. {
  3379. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3380. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3381. {
  3382. reqClockAlignMeter[gun_index] = 1;
  3383. }
  3384. }// End for CHAdeMO
  3385. }
  3386. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3387. {
  3388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3389. {
  3390. tempIndex = ((gun_index==2) ? 1: 0);
  3391. }
  3392. else
  3393. {
  3394. tempIndex = gun_index;
  3395. }
  3396. for (int index = 0; index < CCS_QUANTITY; index++)
  3397. {
  3398. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3399. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3400. {
  3401. reqClockAlignMeter[gun_index] = 1;
  3402. }
  3403. } // End for CCS
  3404. }
  3405. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3406. {
  3407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3408. {
  3409. tempIndex = ((gun_index==2) ? 1: 0);
  3410. }
  3411. else
  3412. {
  3413. tempIndex = gun_index;
  3414. }
  3415. for (int index = 0; index < GB_QUANTITY; index++)
  3416. {
  3417. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3418. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3419. {
  3420. reqClockAlignMeter[gun_index] = 1;
  3421. }
  3422. }// End for GB
  3423. }
  3424. else if(gunType[gun_index] == GUN_TYPE_DO)
  3425. {
  3426. tempIndex = gun_index;
  3427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3428. {
  3429. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3430. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3431. {
  3432. reqClockAlignMeter[gun_index] = 1;
  3433. }
  3434. }
  3435. }
  3436. else
  3437. {
  3438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3439. {
  3440. tempIndex = 2;
  3441. }
  3442. else
  3443. {
  3444. tempIndex = gun_index;
  3445. }
  3446. for (int index = 0; index < AC_QUANTITY; index++)
  3447. {
  3448. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3449. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3450. {
  3451. reqClockAlignMeter[gun_index] = 1;
  3452. }
  3453. }//End for AC
  3454. }
  3455. if(reqClockAlignMeter[gun_index] == 1)
  3456. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3457. }
  3458. // Sample period MeterValue
  3459. if((((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData))>10?(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1):10))))
  3460. {
  3461. //check Transaction active
  3462. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3463. {
  3464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3465. {
  3466. tempIndex = ((gun_index==2) ? 1: 0);
  3467. }
  3468. else
  3469. {
  3470. tempIndex = gun_index;
  3471. }
  3472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3473. {
  3474. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3475. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3476. {
  3477. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3478. {
  3479. reqSampleMeter[gun_index] = 1;
  3480. }
  3481. }
  3482. }// End for CHAdeMO
  3483. }
  3484. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3485. {
  3486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3487. {
  3488. tempIndex = ((gun_index==2) ? 1: 0);
  3489. }
  3490. else
  3491. {
  3492. tempIndex = gun_index;
  3493. }
  3494. for (int index = 0; index < CCS_QUANTITY; index++)
  3495. {
  3496. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3497. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3498. {
  3499. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3500. {
  3501. reqSampleMeter[gun_index] = 1;
  3502. }
  3503. }
  3504. } // End for CCS
  3505. }
  3506. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3507. {
  3508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3509. {
  3510. tempIndex = ((gun_index==2) ? 1: 0);
  3511. }
  3512. else
  3513. {
  3514. tempIndex = gun_index;
  3515. }
  3516. for (int index = 0; index < GB_QUANTITY; index++)
  3517. {
  3518. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3519. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3520. {
  3521. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3522. {
  3523. reqSampleMeter[gun_index] = 1;
  3524. }
  3525. }
  3526. }// End for GB
  3527. }
  3528. else if(gunType[gun_index] == GUN_TYPE_DO)
  3529. {
  3530. tempIndex = gun_index;
  3531. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3532. {
  3533. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3534. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3535. {
  3536. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3537. {
  3538. reqSampleMeter[gun_index] = 1;
  3539. }
  3540. }
  3541. }
  3542. }
  3543. else
  3544. {
  3545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3546. {
  3547. tempIndex = 2;
  3548. }
  3549. else
  3550. {
  3551. tempIndex = gun_index;
  3552. }
  3553. for (int index = 0; index < AC_QUANTITY; index++)
  3554. {
  3555. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3556. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3557. {
  3558. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3559. {
  3560. reqSampleMeter[gun_index] = 1;
  3561. }
  3562. }
  3563. }//End for AC
  3564. }
  3565. if(reqSampleMeter[gun_index] == 1)
  3566. {
  3567. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3568. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3569. storeTempStopTransaction(gun_index);
  3570. }
  3571. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3572. }
  3573. //==============================================
  3574. // Check Connector reserved
  3575. //==============================================
  3576. //===============================
  3577. // Check if Reserve is expired
  3578. //===============================
  3579. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3580. {
  3581. double diff_t;
  3582. struct tm tp;
  3583. // current time
  3584. time_t t = time(NULL);
  3585. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3586. tp.tm_isdst = -1;
  3587. time_t utc = mktime(&tp);
  3588. diff_t = difftime(utc, t);
  3589. if(diff_t <= 0)
  3590. {
  3591. DEBUG_INFO("reserve expired.\n");
  3592. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3593. }
  3594. }//END OF Check if Reserve is expired
  3595. //==========================================
  3596. // csu trigger FirmwareStatusNotificationReq
  3597. //==========================================
  3598. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3599. {
  3600. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3601. }
  3602. //==========================================
  3603. // csu trigger DiagnosticsStatusNotificationReq
  3604. //==========================================
  3605. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3606. {
  3607. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3608. }
  3609. //==========================================
  3610. // csu trigger CancelReservationConf
  3611. //==========================================
  3612. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3613. {
  3614. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3615. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3616. }
  3617. //==========================================
  3618. // csu trigger ChangeAvailabilityConf
  3619. //==========================================
  3620. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3621. {
  3622. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3623. }
  3624. //==========================================
  3625. // csu trigger UnlockConnectorConf
  3626. //==========================================
  3627. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3628. {
  3629. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3630. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3631. }
  3632. //==========================================
  3633. // csu trigger ReserveNowConf
  3634. //==========================================
  3635. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3636. {
  3637. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3638. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3639. }
  3640. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3641. {
  3642. sendSignCertificateRequest();
  3643. }
  3644. }
  3645. }
  3646. //==========================================
  3647. // send request routine
  3648. //==========================================
  3649. int sendAuthorizeRequest(int gun_index)
  3650. {
  3651. mtrace();
  3652. int result = FAIL;
  3653. char message[100]={0};
  3654. char guid[37];
  3655. char tempdata[65]={0};
  3656. DEBUG_INFO("sendAuthorizeRequest...\n");
  3657. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3658. //Local Authorize
  3659. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3660. {
  3661. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3662. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3663. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3664. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3665. result = PASS;
  3666. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3667. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3668. authorizeRetryTimes = 0;
  3669. return result;
  3670. }
  3671. else if(((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16DataPH->OcppConnStatus == 0))||
  3672. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3673. {
  3674. // Query from cache
  3675. DEBUG_INFO("Authorize from cache.\n");
  3676. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3677. // Query from list
  3678. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3679. {
  3680. DEBUG_INFO("Authorize from list.\n");
  3681. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3682. }
  3683. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3684. {
  3685. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3686. {
  3687. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3688. }
  3689. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3690. {
  3691. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3692. }
  3693. if(!GetOcppConnStatus())
  3694. {
  3695. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3696. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3697. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3698. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3699. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3700. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3701. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3702. authorizeRetryTimes = 0;
  3703. return result;
  3704. }
  3705. }
  3706. else
  3707. {
  3708. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3709. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3710. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3711. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3712. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3713. else
  3714. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3715. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3716. result = PASS;
  3717. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3718. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3719. authorizeRetryTimes = 0;
  3720. return result;
  3721. }
  3722. }
  3723. //initialize struct Authorize
  3724. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3725. //get data from shared memory
  3726. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3727. random_uuid(guid);
  3728. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3729. LWS_Send(message);
  3730. sprintf(tempdata, "Authorize,%d", gun_index);
  3731. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3732. {
  3733. result = PASS;
  3734. DEBUG_INFO("Authorize mapItem pass\n");
  3735. }
  3736. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3737. return result;
  3738. }
  3739. int sendBootNotificationRequest(void)
  3740. {
  3741. mtrace();
  3742. int result = FAIL;
  3743. char message[500]={0}, payload[700]={0};
  3744. char guid[37]={0};
  3745. char tempdata[65]={0};
  3746. // Fill BootNotification fields
  3747. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3748. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3749. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3750. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3751. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3752. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3753. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3754. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3755. ShmOCPP16DataPH->ChargeBoxId
  3756. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3757. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3758. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3759. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3760. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3761. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3762. random_uuid(guid);
  3763. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3764. LWS_Send(message);
  3765. sprintf(tempdata, "BootNotification,0");
  3766. 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*/)
  3767. {
  3768. result = PASS;
  3769. }
  3770. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3771. strcpy(queuedata,message);
  3772. return result;
  3773. }
  3774. int sendDataTransferRequest(int gun_index)
  3775. {
  3776. mtrace();
  3777. char message[1000]={0};
  3778. char guid[37]={0};
  3779. char tempdata[65]={0};
  3780. int result = FAIL;
  3781. random_uuid(guid);
  3782. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3783. MESSAGE_TYPE_CALL,
  3784. guid,
  3785. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  3786. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  3787. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  3788. LWS_Send(message);
  3789. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3790. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3791. {
  3792. result = PASS;
  3793. DEBUG_INFO("DataTransfer mapItem pass\n");
  3794. }
  3795. return result;
  3796. }
  3797. int sendDiagnosticsStatusNotificationRequest(char *status)
  3798. {
  3799. mtrace();
  3800. int result = FAIL;
  3801. char message[110]={0};
  3802. char guid[37]={0};
  3803. char tempdata[65]={0};
  3804. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3805. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3806. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3807. random_uuid(guid);
  3808. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3809. LWS_SendNow(message);
  3810. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3811. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3812. {
  3813. result = PASS;
  3814. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3815. }
  3816. //#ifdef SystemLogMessage
  3817. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3818. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3819. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3820. //#endif
  3821. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3822. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3823. //record status
  3824. if(strcmp(status,"Idle")==0)
  3825. {
  3826. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3827. }
  3828. else if(strcmp(status,"Uploaded")==0)
  3829. {
  3830. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3831. }
  3832. else if(strcmp(status,"UploadFailed")==0)
  3833. {
  3834. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3835. }
  3836. else if(strcmp(status,"Uploading")==0)
  3837. {
  3838. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3839. }
  3840. return result;
  3841. }
  3842. int sendFirmwareStatusNotificationRequest(char *status)
  3843. {
  3844. mtrace();
  3845. int result = FAIL;
  3846. char message[110]={0};
  3847. char guid[37]={0};
  3848. char tempdata[65]={0};
  3849. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3850. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3851. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3852. random_uuid(guid);
  3853. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3854. LWS_SendNow(message);
  3855. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3856. 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*/)
  3857. {
  3858. result = PASS;
  3859. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3860. }
  3861. //#ifdef SystemLogMessage
  3862. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3863. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3864. //#endif
  3865. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3866. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3867. //record status
  3868. if(strcmp(status,"Downloaded")==0)
  3869. {
  3870. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3871. }
  3872. else if(strcmp(status,"DownloadFailed")==0)
  3873. {
  3874. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3875. }
  3876. else if(strcmp(status,"Downloading")==0)
  3877. {
  3878. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3879. }
  3880. else if(strcmp(status,"Idle")==0)
  3881. {
  3882. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3883. }
  3884. else if(strcmp(status,"InstallationFailed")==0)
  3885. {
  3886. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3887. }
  3888. else if(strcmp(status,"Installing")==0)
  3889. {
  3890. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3891. }
  3892. else if(strcmp(status,"Installed")==0)
  3893. {
  3894. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3895. }
  3896. return result;
  3897. }
  3898. int sendHeartbeatRequest(int gun_index)
  3899. {
  3900. mtrace();
  3901. int result = FAIL;
  3902. char message[80]={0};
  3903. char guid[37]={0};
  3904. char tempdata[65]={0};
  3905. random_uuid(guid);
  3906. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3907. , MESSAGE_TYPE_CALL
  3908. , guid );
  3909. LWS_Send(message);
  3910. sprintf(tempdata, "Heartbeat,%d", 0);
  3911. 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*/)
  3912. {
  3913. result = PASS;
  3914. }
  3915. return result;
  3916. }
  3917. int sendStartTransactionRequest(int gun_index)
  3918. {
  3919. mtrace();
  3920. int result = FAIL;
  3921. char message[250]={0};
  3922. char guid[37]={0};
  3923. struct timeval tmnow;
  3924. struct tm *tm;
  3925. char buf[28];//, usec_buf[6];
  3926. char tempdata[65]={0};
  3927. int tempIndex = 0;
  3928. DEBUG_INFO("sendStartTransactionRequest...\n");
  3929. gettimeofday(&tmnow, NULL);
  3930. time_t t;
  3931. t = time(NULL);
  3932. /*UTC time and date*/
  3933. tm = gmtime(&t);
  3934. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3935. #if 0 // remove temporally
  3936. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3937. strcat(buf,".");
  3938. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3939. strcat(buf,usec_buf);
  3940. #endif
  3941. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3942. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  3943. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3944. // clear StartTransaction Response
  3945. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3946. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3947. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3948. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  3949. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3950. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3951. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3952. {
  3953. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3954. {
  3955. tempIndex = ((gun_index==2) ? 1: 0);
  3956. }
  3957. else
  3958. {
  3959. tempIndex = gun_index;
  3960. }
  3961. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3962. {
  3963. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3964. {
  3965. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3966. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3967. }
  3968. }
  3969. }
  3970. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3971. {
  3972. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3973. {
  3974. tempIndex = ((gun_index==2) ? 1: 0);
  3975. }
  3976. else
  3977. {
  3978. tempIndex = gun_index;
  3979. }
  3980. for (int index = 0; index < CCS_QUANTITY; index++)
  3981. {
  3982. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3983. {
  3984. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3985. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3986. }
  3987. }
  3988. }
  3989. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3990. {
  3991. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3992. {
  3993. tempIndex = ((gun_index==2) ? 1: 0);
  3994. }
  3995. else
  3996. {
  3997. tempIndex = gun_index;
  3998. }
  3999. for (int index = 0; index < GB_QUANTITY; index++)
  4000. {
  4001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4002. {
  4003. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4004. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4005. }
  4006. }
  4007. }
  4008. else if(gunType[gun_index] == GUN_TYPE_DO)
  4009. {
  4010. tempIndex = gun_index;
  4011. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4012. {
  4013. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4014. {
  4015. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4016. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4017. }
  4018. }
  4019. }
  4020. else
  4021. {
  4022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4023. {
  4024. tempIndex = 2;
  4025. }
  4026. else
  4027. {
  4028. tempIndex = gun_index;
  4029. }
  4030. for (int index = 0; index < AC_QUANTITY; index++)
  4031. {
  4032. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4033. {
  4034. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4035. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4036. }
  4037. }
  4038. }
  4039. random_uuid(guid);
  4040. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4041. {
  4042. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4043. , gun_index +1
  4044. , MESSAGE_TYPE_CALL
  4045. , guid
  4046. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4047. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4048. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4049. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4050. }
  4051. else
  4052. {
  4053. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4054. , gun_index +1
  4055. , MESSAGE_TYPE_CALL
  4056. , guid
  4057. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4058. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4059. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4060. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4061. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4062. }
  4063. #if 1
  4064. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4065. 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*/)
  4066. {
  4067. result = PASS;
  4068. }
  4069. #endif
  4070. strcpy(queuedata, message);
  4071. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4072. OCPP_insert_transaction_msg(YES, queuedata);
  4073. return result;
  4074. }
  4075. int sendStatusNotificationRequest(int gun_index)
  4076. {
  4077. mtrace();
  4078. int result = FAIL;
  4079. char message[600]={0};
  4080. char guid[37];
  4081. int currentStatus = 0;
  4082. struct timeval tmnow;
  4083. struct tm *tm;
  4084. char buf[28];//, usec_buf[6];
  4085. char tempdata[65]={0};
  4086. int tempIndex = 0;
  4087. uint8_t isStateChanged = TRUE;
  4088. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4089. gettimeofday(&tmnow, NULL);
  4090. time_t t;
  4091. t = time(NULL);
  4092. /*UTC time and date*/
  4093. tm = gmtime(&t);
  4094. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4095. #if 0 // remove temporally
  4096. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4097. strcat(buf,".");
  4098. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4099. strcat(buf,usec_buf);
  4100. #endif
  4101. //printf("%s",buf);
  4102. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4103. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4104. // it's option
  4105. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4106. /*
  4107. enum _SYSTEM_STATUS
  4108. {
  4109. S_BOOTING = 0,
  4110. S_IDLE, = 1
  4111. S_AUTHORIZING, =2
  4112. S_REASSIGN_CHECK, =3
  4113. S_REASSIGN, =4
  4114. S_PRECHARGE, =5
  4115. S_PREPARING_FOR_EV, =6
  4116. S_PREPARING_FOR_EVSE, =7
  4117. S_CHARGING, =8
  4118. S_TERMINATING, =9
  4119. S_COMPLETE, =10
  4120. S_ALARM, =11
  4121. S_FAULT =12
  4122. }
  4123. */
  4124. //check Transaction active
  4125. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4126. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4127. {
  4128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4129. {
  4130. tempIndex = ((gun_index==2) ? 1: 0);
  4131. }
  4132. else
  4133. {
  4134. tempIndex = gun_index;
  4135. }
  4136. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4137. {
  4138. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4139. {
  4140. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4141. {
  4142. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4143. {
  4144. currentStatus = Preparing; //OCPP Status: Preparing
  4145. }
  4146. else
  4147. {
  4148. currentStatus = Available; //OCPP Status: Available
  4149. }
  4150. }
  4151. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4152. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4153. ) //S_PRECHARGE
  4154. {
  4155. currentStatus = Preparing; //OCPP Status: Preparing
  4156. }
  4157. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4158. {
  4159. currentStatus = Charging; //OCPP Status: Charging
  4160. }
  4161. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4162. {
  4163. currentStatus = Finishing; //OCPP Status: Finishing
  4164. }
  4165. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4166. {
  4167. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4168. }
  4169. 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
  4170. {
  4171. currentStatus = Unavailable; //OCPP Status: Unavailable
  4172. }
  4173. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4174. {
  4175. currentStatus = Faulted; //OCPP Status: Faulted
  4176. }
  4177. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4178. {
  4179. currentStatus = Reserved; //OCPP Status: Reserved
  4180. }
  4181. } //end of the same index
  4182. }//end of for CHAdeMO_QUANTITY
  4183. }
  4184. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4185. {
  4186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4187. {
  4188. tempIndex = ((gun_index==2) ? 1: 0);
  4189. }
  4190. else
  4191. {
  4192. tempIndex = gun_index;
  4193. }
  4194. for (int index = 0; index < CCS_QUANTITY; index++)
  4195. {
  4196. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4197. {
  4198. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4199. {
  4200. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4201. {
  4202. currentStatus = Preparing; //OCPP Status: Preparing
  4203. }
  4204. else
  4205. {
  4206. currentStatus = Available; //OCPP Status: Available
  4207. }
  4208. }
  4209. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4210. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4211. ) //S_PRECHARGE
  4212. {
  4213. currentStatus = Preparing; //OCPP Status: Preparing
  4214. }
  4215. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4216. {
  4217. currentStatus = Charging; //OCPP Status: Charging
  4218. }
  4219. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4220. {
  4221. currentStatus = Finishing; //OCPP Status: Finishing
  4222. }
  4223. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4224. {
  4225. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4226. }
  4227. 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
  4228. {
  4229. currentStatus = Unavailable; //OCPP Status : Unavailable
  4230. }
  4231. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4232. {
  4233. currentStatus = Faulted; //OCPP Status: Faulted
  4234. }
  4235. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4236. {
  4237. currentStatus = Reserved; //OCPP Status: Reserved
  4238. }
  4239. } //end of the same index
  4240. } // end of for CCS_QUANTITY
  4241. }
  4242. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4243. {
  4244. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4245. {
  4246. tempIndex = ((gun_index==2) ? 1: 0);
  4247. }
  4248. else
  4249. {
  4250. tempIndex = gun_index;
  4251. }
  4252. for (int index = 0; index < GB_QUANTITY; index++)
  4253. {
  4254. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4255. {
  4256. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4257. {
  4258. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4259. {
  4260. currentStatus = Preparing; //OCPP Status: Preparing
  4261. }
  4262. else
  4263. {
  4264. currentStatus = Available; //OCPP Status: Available
  4265. }
  4266. }
  4267. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4268. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4269. ) //S_PRECHARGE
  4270. {
  4271. currentStatus = Preparing; //OCPP Status: Preparing
  4272. }
  4273. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4274. {
  4275. currentStatus = Charging; //OCPP Status: Charging
  4276. }
  4277. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4278. {
  4279. currentStatus = Finishing; //OCPP Status: Finishing
  4280. }
  4281. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4282. {
  4283. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4284. }
  4285. 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
  4286. {
  4287. currentStatus = Unavailable; //OCPP Status: Unavailable
  4288. }
  4289. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4290. {
  4291. currentStatus = Faulted; //OCPP Status: Faulted
  4292. }
  4293. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4294. {
  4295. currentStatus = Reserved; //OCPP Status: Reserved
  4296. }
  4297. } //end of the same index
  4298. } // end of for GB_QUANTITY
  4299. }
  4300. else if(gunType[gun_index] == GUN_TYPE_DO)
  4301. {
  4302. tempIndex = gun_index;
  4303. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4304. {
  4305. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4306. {
  4307. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4308. {
  4309. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4310. {
  4311. currentStatus = Preparing; //OCPP Status: Preparing
  4312. }
  4313. else
  4314. {
  4315. currentStatus = Available; //OCPP Status: Available
  4316. }
  4317. }
  4318. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4319. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4320. ) //S_PRECHARGE
  4321. {
  4322. currentStatus = Preparing; //OCPP Status: Preparing
  4323. }
  4324. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4325. {
  4326. currentStatus = Charging; //OCPP Status: Charging
  4327. }
  4328. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4329. {
  4330. currentStatus = Finishing; //OCPP Status: Finishing
  4331. }
  4332. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4333. {
  4334. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4335. }
  4336. 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
  4337. {
  4338. currentStatus = Unavailable; //OCPP Status: Unavailable
  4339. }
  4340. 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
  4341. {
  4342. currentStatus = Faulted; //OCPP Status: Faulted
  4343. }
  4344. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4345. {
  4346. currentStatus = Reserved; //OCPP Status: Reserved
  4347. }
  4348. } //end of the same index
  4349. }
  4350. }
  4351. else
  4352. {
  4353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4354. {
  4355. tempIndex = 2;
  4356. }
  4357. else
  4358. {
  4359. tempIndex = gun_index;
  4360. }
  4361. for (int index = 0; index < AC_QUANTITY; index++)
  4362. {
  4363. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4364. {
  4365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4366. {
  4367. 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))
  4368. {
  4369. currentStatus = Preparing; //OCPP Status: Preparing
  4370. }
  4371. else
  4372. {
  4373. currentStatus = Available; //OCPP Status: Available
  4374. }
  4375. }
  4376. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4377. {
  4378. currentStatus = Preparing; //OCPP Status: Preparing
  4379. }
  4380. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4381. {
  4382. currentStatus = Charging; //OCPP Status: Charging
  4383. }
  4384. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4385. {
  4386. currentStatus = Finishing; //OCPP Status: Finishing
  4387. }
  4388. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4389. {
  4390. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4391. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4392. else
  4393. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4394. }
  4395. 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
  4396. {
  4397. currentStatus = Unavailable; //OCPP Status: Unavailable
  4398. }
  4399. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4400. {
  4401. currentStatus = Faulted; //OCPP Status: Faulted
  4402. }
  4403. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4404. {
  4405. currentStatus = Reserved; //OCPP Status: Reserved
  4406. }
  4407. }//end of the same index
  4408. }//end of for AC_QUANTITY
  4409. }
  4410. //it's option
  4411. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4412. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4413. {
  4414. isStateChanged = FALSE;
  4415. }
  4416. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4417. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4418. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4419. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4420. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4421. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4422. random_uuid(guid);
  4423. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4424. , MESSAGE_TYPE_CALL
  4425. , guid
  4426. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4427. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4428. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4429. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4430. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4431. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4432. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4433. if((server_sign == TRUE) && isStateChanged)
  4434. {
  4435. LWS_Send(message);
  4436. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4437. 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*/)
  4438. {
  4439. //DEBUG_ERROR("statusNotification mapitem pass");
  4440. result = PASS;
  4441. }
  4442. }
  4443. else
  4444. {
  4445. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4446. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4447. result = PASS;
  4448. }
  4449. return result;
  4450. }
  4451. int sendStopTransactionRequest(int gun_index)
  4452. {
  4453. mtrace();
  4454. int result = FAIL;
  4455. //char message[1500]={0};
  4456. char guid[37]={0};
  4457. char tempdata[65]={0};
  4458. int tempIndex = 0;
  4459. char TempStopTransaction[256];
  4460. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4461. //int idx_sample=0;
  4462. DEBUG_INFO("sendStopTransactionRequest \n");
  4463. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4464. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4465. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4466. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4467. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4468. {
  4469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4470. {
  4471. tempIndex = ((gun_index==2) ? 1: 0);
  4472. }
  4473. else
  4474. {
  4475. tempIndex = gun_index;
  4476. }
  4477. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4480. {
  4481. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4482. }
  4483. }// END OF CHAdeMO_QUANTITY
  4484. }
  4485. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4486. {
  4487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4488. {
  4489. tempIndex = ((gun_index==2) ? 1: 0);
  4490. }
  4491. else
  4492. {
  4493. tempIndex = gun_index;
  4494. }
  4495. for (int index = 0; index < CCS_QUANTITY; index++)
  4496. {
  4497. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4498. {
  4499. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4500. }
  4501. }// END OF CCS_QUANTITY
  4502. }
  4503. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4504. {
  4505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4506. {
  4507. tempIndex = ((gun_index==2) ? 1: 0);
  4508. }
  4509. else
  4510. {
  4511. tempIndex = gun_index;
  4512. }
  4513. for (int index = 0; index < GB_QUANTITY; index++)
  4514. {
  4515. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4516. {
  4517. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4518. }
  4519. }// END OF GB_QUANTITY
  4520. }
  4521. else if(gunType[gun_index] == GUN_TYPE_DO)
  4522. {
  4523. tempIndex = gun_index;
  4524. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4525. {
  4526. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4527. {
  4528. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4529. }
  4530. }// END OF GB_QUANTITY
  4531. }
  4532. else
  4533. {
  4534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4535. {
  4536. tempIndex = 2;
  4537. }
  4538. else
  4539. {
  4540. tempIndex = gun_index;
  4541. }
  4542. for (int index = 0; index < AC_QUANTITY; index++)
  4543. {
  4544. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4545. {
  4546. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4547. }
  4548. }// END OF AC_QUANTITY
  4549. }
  4550. //====================================== Stop Transaction Time =====================================================
  4551. struct timeval tmnow;
  4552. struct tm *tm;
  4553. char buf[28];//, usec_buf[6];
  4554. gettimeofday(&tmnow, NULL);
  4555. time_t t;
  4556. t = time(NULL);
  4557. /*UTC time and date*/
  4558. tm = gmtime(&t);
  4559. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4560. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4561. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4562. random_uuid(guid);
  4563. /***********************************transactionData******************************************************/
  4564. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4565. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4566. //=================================
  4567. // Transaction_Begin
  4568. //=================================
  4569. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4570. {
  4571. //============================================ Energy.Active.Import.Interval ================================
  4572. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4573. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4574. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4575. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  4576. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4577. 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))
  4578. {
  4579. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4580. }
  4581. else
  4582. {
  4583. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4584. }
  4585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4586. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4587. }
  4588. //=================================
  4589. // Transaction_End
  4590. //=================================
  4591. // ================================= Current.Import L1 ===============================================
  4592. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4593. {
  4594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4595. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4596. {
  4597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4598. {
  4599. tempIndex = ((gun_index==2) ? 1: 0);
  4600. }
  4601. else
  4602. {
  4603. tempIndex = gun_index;
  4604. }
  4605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4606. {
  4607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4608. {
  4609. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4610. }
  4611. }// End of for CHAdeMO_QUANTITY
  4612. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4613. }
  4614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4615. {
  4616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4617. {
  4618. tempIndex = ((gun_index==2) ? 1: 0);
  4619. }
  4620. else
  4621. {
  4622. tempIndex = gun_index;
  4623. }
  4624. for (int index = 0; index < CCS_QUANTITY; index++)
  4625. {
  4626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4627. {
  4628. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4629. }
  4630. }// End of for CCS_QUANTITY
  4631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4632. }
  4633. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4634. {
  4635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4636. {
  4637. tempIndex = ((gun_index==2) ? 1: 0);
  4638. }
  4639. else
  4640. {
  4641. tempIndex = gun_index;
  4642. }
  4643. for (int index = 0; index < GB_QUANTITY; index++)
  4644. {
  4645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4646. {
  4647. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4648. }
  4649. }// End of for GB_QUANTITY
  4650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4651. }
  4652. else if(gunType[gun_index] == GUN_TYPE_DO)
  4653. {
  4654. tempIndex = gun_index;
  4655. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4656. {
  4657. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4658. {
  4659. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4660. }
  4661. }
  4662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4663. }
  4664. else
  4665. {
  4666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4667. {
  4668. tempIndex = 2;
  4669. }
  4670. else
  4671. {
  4672. tempIndex = gun_index;
  4673. }
  4674. for (int index = 0; index < AC_QUANTITY; index++)
  4675. {
  4676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4677. {
  4678. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4679. }
  4680. }// End of for AC_QUANTITY
  4681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4682. }
  4683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4688. }
  4689. // ================================= Energy.Active.Import.Interval ==============================================
  4690. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4691. {
  4692. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4693. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4694. {
  4695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4696. {
  4697. tempIndex = ((gun_index==2) ? 1: 0);
  4698. }
  4699. else
  4700. {
  4701. tempIndex = gun_index;
  4702. }
  4703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4704. {
  4705. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4706. {
  4707. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4708. }
  4709. }// END OF CHAdeMO_QUANTITY
  4710. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4711. }
  4712. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4713. {
  4714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4715. {
  4716. tempIndex = ((gun_index==2) ? 1: 0);
  4717. }
  4718. else
  4719. {
  4720. tempIndex = gun_index;
  4721. }
  4722. for (int index = 0; index < CCS_QUANTITY; index++)
  4723. {
  4724. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4725. {
  4726. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4727. }
  4728. }// END OF CCS_QUANTITY
  4729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4730. }
  4731. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4732. {
  4733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4734. {
  4735. tempIndex = ((gun_index==2) ? 1: 0);
  4736. }
  4737. else
  4738. {
  4739. tempIndex = gun_index;
  4740. }
  4741. for (int index = 0; index < GB_QUANTITY; index++)
  4742. {
  4743. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4744. {
  4745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4746. }
  4747. }// END OF GB_QUANTITY
  4748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4749. }
  4750. else if(gunType[gun_index] == GUN_TYPE_DO)
  4751. {
  4752. tempIndex = gun_index;
  4753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4754. {
  4755. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4756. {
  4757. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4758. }
  4759. }
  4760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4761. }
  4762. else
  4763. {
  4764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4765. {
  4766. tempIndex = 2;
  4767. }
  4768. else
  4769. {
  4770. tempIndex = gun_index;
  4771. }
  4772. for (int index = 0; index < AC_QUANTITY; index++)
  4773. {
  4774. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4775. {
  4776. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4777. }
  4778. }// END OF AC_QUANTITY
  4779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4780. }
  4781. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4784. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4786. }
  4787. //=================================== Power.Active.Import ==================================================
  4788. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4789. {
  4790. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4792. {
  4793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4794. {
  4795. tempIndex = ((gun_index==2) ? 1: 0);
  4796. }
  4797. else
  4798. {
  4799. tempIndex = gun_index;
  4800. }
  4801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4802. {
  4803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4804. {
  4805. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4806. }
  4807. } // End for CHAdeMO_QUANTITY
  4808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4809. }
  4810. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4811. {
  4812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4813. {
  4814. tempIndex = ((gun_index==2) ? 1: 0);
  4815. }
  4816. else
  4817. {
  4818. tempIndex = gun_index;
  4819. }
  4820. for (int index = 0; index < CCS_QUANTITY; index++)
  4821. {
  4822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4823. {
  4824. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4825. }
  4826. } // END for CCS_QUANTITY
  4827. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4828. }
  4829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4830. {
  4831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4832. {
  4833. tempIndex = ((gun_index==2) ? 1: 0);
  4834. }
  4835. else
  4836. {
  4837. tempIndex = gun_index;
  4838. }
  4839. for (int index = 0; index < GB_QUANTITY; index++)
  4840. {
  4841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4842. {
  4843. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4844. }
  4845. }// END for GB_QUANTITY
  4846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4847. }
  4848. else if(gunType[gun_index] == GUN_TYPE_DO)
  4849. {
  4850. tempIndex = gun_index;
  4851. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4852. {
  4853. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4854. {
  4855. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4856. }
  4857. }
  4858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4859. }
  4860. else
  4861. {
  4862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4863. {
  4864. tempIndex = 2;
  4865. }
  4866. else
  4867. {
  4868. tempIndex = gun_index;
  4869. }
  4870. for (int index = 0; index < AC_QUANTITY; index++)
  4871. {
  4872. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4873. {
  4874. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4875. }
  4876. } // END for AC_QUANTITY
  4877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4878. }
  4879. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4880. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4881. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4882. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4883. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4884. }
  4885. //============================ Voltage L1 ====================================
  4886. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4887. {
  4888. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4889. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4890. {
  4891. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4892. {
  4893. tempIndex = ((gun_index==2) ? 1: 0);
  4894. }
  4895. else
  4896. {
  4897. tempIndex = gun_index;
  4898. }
  4899. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4900. {
  4901. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4902. {
  4903. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4904. }
  4905. } // END OF FOR CHAdeMO_QUANTITY
  4906. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4907. }
  4908. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4909. {
  4910. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4911. {
  4912. tempIndex = ((gun_index==2) ? 1: 0);
  4913. }
  4914. else
  4915. {
  4916. tempIndex = gun_index;
  4917. }
  4918. for (int index = 0; index < CCS_QUANTITY; index++)
  4919. {
  4920. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4921. {
  4922. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4923. }
  4924. } // END OF FOR CCS_QUANTITY
  4925. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4926. }
  4927. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4928. {
  4929. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4930. {
  4931. tempIndex = ((gun_index==2) ? 1: 0);
  4932. }
  4933. else
  4934. {
  4935. tempIndex = gun_index;
  4936. }
  4937. for (int index = 0; index < GB_QUANTITY; index++)
  4938. {
  4939. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4940. {
  4941. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4942. }
  4943. } // END OF FOR GB_QUANTITY
  4944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4945. }
  4946. else if(gunType[gun_index] == GUN_TYPE_DO)
  4947. {
  4948. tempIndex = gun_index;
  4949. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4950. {
  4951. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4952. {
  4953. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4954. }
  4955. }
  4956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4957. }
  4958. else
  4959. {
  4960. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4961. {
  4962. tempIndex = 2;
  4963. }
  4964. else
  4965. {
  4966. tempIndex = gun_index;
  4967. }
  4968. for (int index = 0; index < AC_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4973. }
  4974. } // END OF FOR AC_QUANTITY
  4975. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4976. }
  4977. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4978. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4979. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4980. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4981. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4982. }
  4983. //====================== End SoC ================================
  4984. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4985. {
  4986. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4987. 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))
  4988. {
  4989. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4990. {
  4991. tempIndex = ((gun_index==2) ? 1: 0);
  4992. }
  4993. else
  4994. {
  4995. tempIndex = gun_index;
  4996. }
  4997. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4998. {
  4999. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5002. {
  5003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5004. }
  5005. }
  5006. }
  5007. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5008. {
  5009. for (int index = 0; index < CCS_QUANTITY; index++)
  5010. {
  5011. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5012. {
  5013. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5014. }
  5015. }
  5016. }
  5017. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5018. {
  5019. for (int index = 0; index < GB_QUANTITY; index++)
  5020. {
  5021. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5022. {
  5023. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5024. }
  5025. }
  5026. }
  5027. else if(gunType[gun_index] == GUN_TYPE_DO)
  5028. {
  5029. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5030. {
  5031. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5032. {
  5033. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5034. }
  5035. }
  5036. }
  5037. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5038. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5039. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5040. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5041. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5043. } // END FOR DC CASE
  5044. }
  5045. // ================================= Current.Import L2 ===============================================
  5046. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5047. {
  5048. // AC 3 phse L2 current
  5049. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5050. {
  5051. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5052. {
  5053. tempIndex = 2;
  5054. }
  5055. else
  5056. {
  5057. tempIndex = gun_index;
  5058. }
  5059. for (int index = 0; index < AC_QUANTITY; index++)
  5060. {
  5061. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5062. {
  5063. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5064. }
  5065. }// End of for AC_QUANTITY
  5066. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5067. }
  5068. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5069. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5070. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5071. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5072. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5073. }
  5074. // ================================= Current.Import L3 ===============================================
  5075. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5076. {
  5077. // AC 3 phse L3 current
  5078. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5079. {
  5080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5081. {
  5082. tempIndex = 2;
  5083. }
  5084. else
  5085. {
  5086. tempIndex = gun_index;
  5087. }
  5088. for (int index = 0; index < AC_QUANTITY; index++)
  5089. {
  5090. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5091. {
  5092. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5093. }
  5094. }// End of for AC_QUANTITY
  5095. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5096. }
  5097. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5098. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5099. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5100. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5101. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5102. }
  5103. //============================ Voltage L2 ====================================
  5104. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5105. {
  5106. // AC 3 phse L2 voltage
  5107. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5108. {
  5109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5110. {
  5111. tempIndex = 2;
  5112. }
  5113. else
  5114. {
  5115. tempIndex = gun_index;
  5116. }
  5117. for (int index = 0; index < AC_QUANTITY; index++)
  5118. {
  5119. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5120. {
  5121. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5122. }
  5123. } // END OF FOR AC_QUANTITY
  5124. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5125. }
  5126. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5127. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5128. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5129. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5130. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5131. }
  5132. //============================ Voltage L3 ====================================
  5133. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5134. {
  5135. // AC 3 phse L3 voltage
  5136. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5137. {
  5138. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5139. {
  5140. tempIndex = 2;
  5141. }
  5142. else
  5143. {
  5144. tempIndex = gun_index;
  5145. }
  5146. for (int index = 0; index < AC_QUANTITY; index++)
  5147. {
  5148. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5149. {
  5150. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  5151. }
  5152. } // END OF FOR AC_QUANTITY
  5153. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5154. }
  5155. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5156. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5157. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5158. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5160. }
  5161. //====================== Start SoC ================================
  5162. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  5163. {
  5164. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5165. 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))
  5166. {
  5167. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5168. {
  5169. tempIndex = ((gun_index==2) ? 1: 0);
  5170. }
  5171. else
  5172. {
  5173. tempIndex = gun_index;
  5174. }
  5175. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5176. {
  5177. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5178. {
  5179. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5180. {
  5181. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5182. }
  5183. }
  5184. }
  5185. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5186. {
  5187. for (int index = 0; index < CCS_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5190. {
  5191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5192. }
  5193. }
  5194. }
  5195. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5196. {
  5197. for (int index = 0; index < GB_QUANTITY; index++)
  5198. {
  5199. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5200. {
  5201. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5202. }
  5203. }
  5204. }
  5205. else if(gunType[gun_index] == GUN_TYPE_DO)
  5206. {
  5207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5208. {
  5209. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5210. {
  5211. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5212. }
  5213. }
  5214. }
  5215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5221. } // END FOR DC CASE
  5222. }
  5223. //================================================ Message create ====================================================
  5224. json_object *StopTransaction = json_object_new_object();
  5225. json_object *transactionDatas = json_object_new_array();
  5226. json_object *sampledValues = json_object_new_array();
  5227. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5228. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5229. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5230. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5231. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5232. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5233. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5234. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5235. {
  5236. json_object *transactionData = json_object_new_object();
  5237. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5238. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5239. {
  5240. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5241. {
  5242. json_object *sampledValue = json_object_new_object();
  5243. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5244. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5245. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5246. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5247. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5248. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5249. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5250. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5251. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5252. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5253. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5254. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5255. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5256. json_object_array_add(sampledValues, sampledValue);
  5257. }
  5258. }
  5259. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5260. json_object_array_add(transactionDatas, transactionData);
  5261. }
  5262. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5263. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5264. ,MESSAGE_TYPE_CALL
  5265. ,guid
  5266. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5267. json_object_put(StopTransaction);
  5268. #if 1 // for TempStopTransaction
  5269. //Delete TempStopTransaction
  5270. if((access(TempStopTransaction,F_OK))!=-1)
  5271. {
  5272. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5273. }
  5274. #endif
  5275. #if 1
  5276. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5277. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5278. {
  5279. result = PASS;
  5280. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5281. }
  5282. #endif
  5283. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5284. OCPP_insert_transaction_msg(NO, queuedata);
  5285. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5286. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5287. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5288. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5289. {
  5290. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5291. }
  5292. //for test
  5293. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5294. return result;
  5295. }
  5296. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5297. {
  5298. mtrace();
  5299. int result = FAIL;
  5300. char guid[37]={0};
  5301. char tempdata[65]={0};
  5302. int tempIndex = 0;
  5303. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5304. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5305. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5306. //set value
  5307. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5308. ShmOCPP16DataPH->MeterValues[gun_index].TransactionId = (((strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Charging") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEV") != NULL) || (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "SuspendedEVSE") != NULL) )?
  5309. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5310. -1);
  5311. random_uuid(guid);
  5312. //UTC Date time
  5313. struct timeval tmnow;
  5314. struct tm *tm;
  5315. char buf[28];//, usec_buf[6];
  5316. gettimeofday(&tmnow, NULL);
  5317. time_t t;
  5318. t = time(NULL);
  5319. /*UTC time and date*/
  5320. tm = gmtime(&t);
  5321. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5322. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5323. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5324. //********************************(1)Current.Import L1************************************************/
  5325. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5326. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5327. (dataType == ReadingContext_Trigger))
  5328. {
  5329. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5330. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5331. {
  5332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5333. {
  5334. tempIndex = ((gun_index==2) ? 1: 0);
  5335. }
  5336. else
  5337. {
  5338. tempIndex = gun_index;
  5339. }
  5340. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5341. {
  5342. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5343. {
  5344. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5345. }
  5346. }
  5347. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5348. }
  5349. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5350. {
  5351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5352. {
  5353. tempIndex = ((gun_index==2) ? 1: 0);
  5354. }
  5355. else
  5356. {
  5357. tempIndex = gun_index;
  5358. }
  5359. for (int index = 0; index < CCS_QUANTITY; index++)
  5360. {
  5361. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5362. {
  5363. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5364. }
  5365. }
  5366. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5367. }
  5368. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5369. {
  5370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5371. {
  5372. tempIndex = ((gun_index==2) ? 1: 0);
  5373. }
  5374. else
  5375. {
  5376. tempIndex = gun_index;
  5377. }
  5378. for (int index = 0; index < GB_QUANTITY; index++)
  5379. {
  5380. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5381. {
  5382. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5383. }
  5384. }
  5385. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5386. }
  5387. else if(gunType[gun_index] == GUN_TYPE_DO)
  5388. {
  5389. tempIndex = gun_index;
  5390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5391. {
  5392. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5393. {
  5394. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5395. }
  5396. }
  5397. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5398. }
  5399. else
  5400. {
  5401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5402. {
  5403. tempIndex = 2;
  5404. }
  5405. else
  5406. {
  5407. tempIndex = gun_index;
  5408. }
  5409. for (int index = 0; index < AC_QUANTITY; index++)
  5410. {
  5411. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5412. {
  5413. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5414. }
  5415. }
  5416. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5417. }
  5418. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5419. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5422. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5423. }
  5424. //********************************(2)Energy.Active.Import.Register ************************************************/
  5425. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5426. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  5427. (dataType == ReadingContext_Trigger))
  5428. {
  5429. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5430. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5431. {
  5432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5433. {
  5434. tempIndex = ((gun_index==2) ? 1: 0);
  5435. }
  5436. else
  5437. {
  5438. tempIndex = gun_index;
  5439. }
  5440. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5441. {
  5442. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5443. {
  5444. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5445. }
  5446. }
  5447. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5448. }
  5449. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5450. {
  5451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5452. {
  5453. tempIndex = ((gun_index==2) ? 1: 0);
  5454. }
  5455. else
  5456. {
  5457. tempIndex = gun_index;
  5458. }
  5459. for (int index = 0; index < CCS_QUANTITY; index++)
  5460. {
  5461. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5462. {
  5463. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5464. }
  5465. }
  5466. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5467. }
  5468. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5469. {
  5470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5471. {
  5472. tempIndex = ((gun_index==2) ? 1: 0);
  5473. }
  5474. else
  5475. {
  5476. tempIndex = gun_index;
  5477. }
  5478. for (int index = 0; index < GB_QUANTITY; index++)
  5479. {
  5480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5481. {
  5482. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5483. }
  5484. }
  5485. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5486. }
  5487. else if(gunType[gun_index] == GUN_TYPE_DO)
  5488. {
  5489. tempIndex = gun_index;
  5490. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5491. {
  5492. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5493. {
  5494. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5495. }
  5496. }
  5497. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5498. }
  5499. else
  5500. {
  5501. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5502. {
  5503. tempIndex = 2;
  5504. }
  5505. else
  5506. {
  5507. tempIndex = gun_index;
  5508. }
  5509. for (int index = 0; index < AC_QUANTITY; index++)
  5510. {
  5511. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5512. {
  5513. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5514. }
  5515. }
  5516. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5517. }
  5518. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5519. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5520. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5521. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5522. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5523. }
  5524. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5525. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5526. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5527. (dataType == ReadingContext_Trigger))
  5528. {
  5529. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5530. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5531. {
  5532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5533. {
  5534. tempIndex = ((gun_index==2) ? 1: 0);
  5535. }
  5536. else
  5537. {
  5538. tempIndex = gun_index;
  5539. }
  5540. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5541. {
  5542. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5543. {
  5544. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5545. }
  5546. } // END OF FOR CHAdeMO_QUANTITY
  5547. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5548. }
  5549. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5550. {
  5551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5552. {
  5553. tempIndex = ((gun_index==2) ? 1: 0);
  5554. }
  5555. else
  5556. {
  5557. tempIndex = gun_index;
  5558. }
  5559. for (int index = 0; index < CCS_QUANTITY; index++)
  5560. {
  5561. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5562. {
  5563. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5564. }
  5565. } // END OF CCS_QUANTITY
  5566. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5567. }
  5568. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5569. {
  5570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5571. {
  5572. tempIndex = ((gun_index==2) ? 1: 0);
  5573. }
  5574. else
  5575. {
  5576. tempIndex = gun_index;
  5577. }
  5578. for (int index = 0; index < GB_QUANTITY; index++)
  5579. {
  5580. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5581. {
  5582. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5583. }
  5584. } // END OF GB_QUANTITY
  5585. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5586. }
  5587. else if(gunType[gun_index] == GUN_TYPE_DO)
  5588. {
  5589. tempIndex = gun_index;
  5590. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5591. {
  5592. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5593. {
  5594. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5595. }
  5596. }
  5597. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5598. }
  5599. else
  5600. {
  5601. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5602. {
  5603. tempIndex = 2;
  5604. }
  5605. else
  5606. {
  5607. tempIndex = gun_index;
  5608. }
  5609. for (int index = 0; index < AC_QUANTITY; index++)
  5610. {
  5611. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5612. {
  5613. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5614. }
  5615. }
  5616. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5617. }
  5618. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5619. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5620. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5621. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5622. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5623. }
  5624. //********************************(4)Power.Active.Import************************************************/
  5625. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5626. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5627. (dataType == ReadingContext_Trigger))
  5628. {
  5629. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5630. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5631. {
  5632. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5633. {
  5634. tempIndex = ((gun_index==2) ? 1: 0);
  5635. }
  5636. else
  5637. {
  5638. tempIndex = gun_index;
  5639. }
  5640. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5641. {
  5642. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5643. {
  5644. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5645. }
  5646. } // END OF FOR
  5647. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5648. }
  5649. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5650. {
  5651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5652. {
  5653. tempIndex = ((gun_index==2) ? 1: 0);
  5654. }
  5655. else
  5656. {
  5657. tempIndex = gun_index;
  5658. }
  5659. for (int index = 0; index < CCS_QUANTITY; index++)
  5660. {
  5661. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5662. {
  5663. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5664. }
  5665. }
  5666. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5667. }
  5668. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5669. {
  5670. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5671. {
  5672. tempIndex = ((gun_index==2) ? 1: 0);
  5673. }
  5674. else
  5675. {
  5676. tempIndex = gun_index;
  5677. }
  5678. for (int index = 0; index < GB_QUANTITY; index++)
  5679. {
  5680. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5681. {
  5682. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5683. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5684. }
  5685. }
  5686. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5687. }
  5688. else if(gunType[gun_index] == GUN_TYPE_DO)
  5689. {
  5690. tempIndex = gun_index;
  5691. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5692. {
  5693. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5694. {
  5695. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5696. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5697. }
  5698. }
  5699. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5700. }
  5701. else
  5702. {
  5703. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5704. {
  5705. tempIndex = 2;
  5706. }
  5707. else
  5708. {
  5709. tempIndex = gun_index;
  5710. }
  5711. for (int index = 0; index < AC_QUANTITY; index++)
  5712. {
  5713. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5714. {
  5715. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5716. }
  5717. }
  5718. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5719. }
  5720. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5721. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5722. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5723. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5724. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5725. }
  5726. //***********************************************(5)VOLTAGE L1******************************************************/
  5727. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5728. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5729. (dataType == ReadingContext_Trigger))
  5730. {
  5731. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5732. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5733. {
  5734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5735. {
  5736. tempIndex = ((gun_index==2) ? 1: 0);
  5737. }
  5738. else
  5739. {
  5740. tempIndex = gun_index;
  5741. }
  5742. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5743. {
  5744. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5745. {
  5746. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5747. }
  5748. }
  5749. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5750. }
  5751. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5752. {
  5753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5754. {
  5755. tempIndex = ((gun_index==2) ? 1: 0);
  5756. }
  5757. else
  5758. {
  5759. tempIndex = gun_index;
  5760. }
  5761. for (int index = 0; index < CCS_QUANTITY; index++)
  5762. {
  5763. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5764. {
  5765. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5766. }
  5767. }
  5768. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5769. }
  5770. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5771. {
  5772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5773. {
  5774. tempIndex = ((gun_index==2) ? 1: 0);
  5775. }
  5776. else
  5777. {
  5778. tempIndex = gun_index;
  5779. }
  5780. for (int index = 0; index < GB_QUANTITY; index++)
  5781. {
  5782. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5783. {
  5784. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5785. }
  5786. }
  5787. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5788. }
  5789. else if(gunType[gun_index] == GUN_TYPE_DO)
  5790. {
  5791. tempIndex = gun_index;
  5792. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5793. {
  5794. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5795. {
  5796. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5797. }
  5798. }
  5799. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5800. }
  5801. else
  5802. {
  5803. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5804. {
  5805. tempIndex = 2;
  5806. }
  5807. else
  5808. {
  5809. tempIndex = gun_index;
  5810. }
  5811. for (int index = 0; index < AC_QUANTITY; index++)
  5812. {
  5813. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5814. {
  5815. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5816. }
  5817. }
  5818. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5819. }
  5820. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5821. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5822. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5823. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5824. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5825. }
  5826. //***********************************************(6)SOC******************************************************/
  5827. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5828. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5829. (dataType == ReadingContext_Trigger))
  5830. {
  5831. 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))
  5832. {
  5833. //idx_sample=5;
  5834. //sampledValue = NULL;
  5835. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5836. {
  5837. tempIndex = ((gun_index==2) ? 1: 0);
  5838. }
  5839. else
  5840. {
  5841. tempIndex = gun_index;
  5842. }
  5843. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5844. {
  5845. //tempIndex = ((gun_index==2) ? 1: 0);
  5846. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5847. {
  5848. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5849. {
  5850. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5851. }
  5852. }
  5853. }
  5854. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5855. {
  5856. //tempIndex = ((gun_index==2) ? 1: 0);
  5857. for (int index = 0; index < CCS_QUANTITY; index++)
  5858. {
  5859. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5860. {
  5861. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5862. }
  5863. }
  5864. }
  5865. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5866. {
  5867. //tempIndex = ((gun_index==2) ? 1: 0);
  5868. for (int index = 0; index < GB_QUANTITY; index++)
  5869. {
  5870. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5871. {
  5872. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5873. }
  5874. }
  5875. }
  5876. else if(gunType[gun_index] == GUN_TYPE_DO)
  5877. {
  5878. //tempIndex = ((gun_index==2) ? 1: 0);
  5879. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5880. {
  5881. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5882. {
  5883. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5884. }
  5885. }
  5886. }
  5887. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5888. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5889. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5890. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5891. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5892. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5893. }
  5894. }
  5895. //********************************(7)Current.Import L2************************************************/
  5896. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5897. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5898. (dataType == ReadingContext_Trigger))
  5899. {
  5900. // Only for AC 3 phase
  5901. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5902. {
  5903. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5904. {
  5905. tempIndex = 2;
  5906. }
  5907. else
  5908. {
  5909. tempIndex = gun_index;
  5910. }
  5911. for (int index = 0; index < AC_QUANTITY; index++)
  5912. {
  5913. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5914. {
  5915. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5916. }
  5917. }
  5918. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5919. }
  5920. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5921. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5922. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5923. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5924. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5925. }
  5926. //********************************(8)Current.Import L3************************************************/
  5927. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5928. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5929. (dataType == ReadingContext_Trigger))
  5930. {
  5931. // Only for AC 3 phase
  5932. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5933. {
  5934. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5935. {
  5936. tempIndex = 2;
  5937. }
  5938. else
  5939. {
  5940. tempIndex = gun_index;
  5941. }
  5942. for (int index = 0; index < AC_QUANTITY; index++)
  5943. {
  5944. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5945. {
  5946. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5947. }
  5948. }
  5949. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5950. }
  5951. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5952. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5953. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5954. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5955. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5956. }
  5957. //***********************************************(9)VOLTAGE L2******************************************************/
  5958. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5959. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5960. (dataType == ReadingContext_Trigger))
  5961. {
  5962. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5963. {
  5964. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5965. {
  5966. tempIndex = 2;
  5967. }
  5968. else
  5969. {
  5970. tempIndex = gun_index;
  5971. }
  5972. for (int index = 0; index < AC_QUANTITY; index++)
  5973. {
  5974. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5975. {
  5976. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5977. }
  5978. }
  5979. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5980. }
  5981. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5982. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5983. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5984. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5986. }
  5987. //***********************************************(10)VOLTAGE L3******************************************************/
  5988. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5989. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5990. (dataType == ReadingContext_Trigger))
  5991. {
  5992. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5993. {
  5994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5995. {
  5996. tempIndex = 2;
  5997. }
  5998. else
  5999. {
  6000. tempIndex = gun_index;
  6001. }
  6002. for (int index = 0; index < AC_QUANTITY; index++)
  6003. {
  6004. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6005. {
  6006. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6007. }
  6008. }
  6009. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6010. }
  6011. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6012. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6013. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6014. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6015. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6016. }
  6017. // Message create ====================================================================================================
  6018. if(TRUE)
  6019. {
  6020. json_object *MeterValueReq = json_object_new_object();
  6021. json_object *MeterValues = json_object_new_array();
  6022. json_object *sampledValues = json_object_new_array();
  6023. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6024. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6025. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6026. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6027. {
  6028. json_object *MeterValue = json_object_new_object();
  6029. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6030. {
  6031. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6032. {
  6033. json_object *sampledValue = json_object_new_object();
  6034. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6035. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6036. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6037. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6038. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6039. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6040. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6041. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6042. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6043. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6044. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6045. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6046. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6047. json_object_array_add(sampledValues, sampledValue);
  6048. }
  6049. }
  6050. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6051. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6052. json_object_array_add(MeterValues, MeterValue);
  6053. }
  6054. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6055. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6056. ,gun_index + 1
  6057. ,MESSAGE_TYPE_CALL
  6058. ,guid
  6059. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6060. json_object_put(MeterValueReq);
  6061. }
  6062. // Put request guid to hash map
  6063. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6064. 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*/)
  6065. {
  6066. result = PASS;
  6067. //DEBUG_INFO("MeterValues mapitem pass\n");
  6068. }
  6069. if((dataType != ReadingContext_Trigger) &&
  6070. (dataType != ReadingContext_Sample_Clock) &&
  6071. (ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1))
  6072. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6073. else
  6074. {
  6075. if(FirstHeartBeat)
  6076. LWS_Send(queuedata +2);
  6077. }
  6078. return result;
  6079. }
  6080. int sendLogStatusNotificationRequest(char *status)
  6081. {
  6082. mtrace();
  6083. int result = PASS;
  6084. char message[4096]={0};
  6085. char guid[37]={0};
  6086. char tempdata[128]={0};
  6087. json_object *LogStatusNotification = json_object_new_object();
  6088. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6089. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6090. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6091. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6092. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6093. random_uuid(guid);
  6094. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6095. json_object_put(LogStatusNotification);
  6096. LWS_Send(message);
  6097. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6098. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6099. {
  6100. result = PASS;
  6101. }
  6102. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6103. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6104. return result;
  6105. }
  6106. int sendSecurityEventNotificationRequest()
  6107. {
  6108. mtrace();
  6109. int result = PASS;
  6110. char message[4096]={0};
  6111. char guid[37]={0};
  6112. char tempdata[128]={0};
  6113. json_object *SecurityEventNotification = json_object_new_object();
  6114. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6115. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6116. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6117. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6118. random_uuid(guid);
  6119. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6120. json_object_put(SecurityEventNotification);
  6121. LWS_Send(message);
  6122. sprintf(tempdata, "SecurityEventNotification,0");
  6123. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6124. {
  6125. result = PASS;
  6126. }
  6127. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6128. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6129. return result;
  6130. }
  6131. int sendSignCertificateRequest()
  6132. {
  6133. mtrace();
  6134. int result = PASS;
  6135. char message[4096]={0};
  6136. char guid[37]={0};
  6137. char tempdata[128]={0};
  6138. json_object *SignCertificate = json_object_new_object();
  6139. DEBUG_INFO("sendSignCertificateRequest...\n");
  6140. // Read csr file content
  6141. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6142. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6143. char *line = NULL;
  6144. size_t len = 0;
  6145. while(getline(&line, &len, fp) != -1)
  6146. {
  6147. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6148. {
  6149. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6150. }
  6151. }
  6152. fclose(fp);
  6153. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6154. random_uuid(guid);
  6155. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6156. json_object_put(SignCertificate);
  6157. LWS_Send(message);
  6158. sprintf(tempdata, "SignCertificate,0");
  6159. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6160. {
  6161. result = PASS;
  6162. }
  6163. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6164. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6165. return result;
  6166. }
  6167. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6168. {
  6169. mtrace();
  6170. int result = PASS;
  6171. char message[110]={0};
  6172. char guid[37]={0};
  6173. char tempdata[65]={0};
  6174. json_object *FirmwareStatusNotification = json_object_new_object();
  6175. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6176. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6177. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6178. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6179. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6180. random_uuid(guid);
  6181. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6182. json_object_put(FirmwareStatusNotification);
  6183. LWS_Send(message);
  6184. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6185. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6186. {
  6187. result = PASS;
  6188. }
  6189. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6190. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6191. return result;
  6192. }
  6193. //==========================================
  6194. // send confirm routine
  6195. //==========================================
  6196. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6197. {
  6198. mtrace();
  6199. int result = FAIL;
  6200. char message[100]={0};
  6201. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6202. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6203. LWS_Send(message);
  6204. result = TRUE;
  6205. return result;
  6206. }
  6207. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6208. {
  6209. mtrace();
  6210. int result = FAIL;
  6211. char message[100]={0};
  6212. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6213. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6214. LWS_Send(message);
  6215. result = TRUE;
  6216. return result;
  6217. }
  6218. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6219. {
  6220. mtrace();
  6221. int result = FAIL;
  6222. char message[100]={0};
  6223. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6224. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6225. LWS_Send(message);
  6226. result = TRUE;
  6227. return result;
  6228. }
  6229. int sendClearCacheConfirmation(char *uuid,char *payload)
  6230. {
  6231. mtrace();
  6232. int result = FAIL;
  6233. char message[500]={0};
  6234. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6235. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6236. LWS_Send(message);
  6237. return result;
  6238. }
  6239. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6240. {
  6241. mtrace();
  6242. int result = FAIL;
  6243. char message[500]={0};
  6244. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6245. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6246. LWS_Send(message);
  6247. return result;
  6248. }
  6249. int sendDataTransferConfirmation(char *uuid,char *payload)
  6250. {
  6251. mtrace();
  6252. char statusStr[20]={0};
  6253. char dataStr[10]={0};
  6254. char sstr[20]={0};
  6255. int c = 0;
  6256. char *loc;
  6257. int result = FAIL;
  6258. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6259. /**********************status**************************/
  6260. loc = strstr(payload, "status");
  6261. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6262. c = 0;
  6263. while (loc[3+strlen("status")+c] != '\"')
  6264. {
  6265. sstr[c] = loc[3+strlen("status")+c];
  6266. c++;
  6267. }
  6268. sstr[c] = '\0';
  6269. strcpy(statusStr, sstr);
  6270. /**********************data**************************/
  6271. loc = strstr(payload, "data");
  6272. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6273. c = 0;
  6274. while (loc[3+strlen("data")+c] != '\"')
  6275. {
  6276. sstr[c] = loc[3+strlen("data")+c];
  6277. c++;
  6278. }
  6279. sstr[c] = '\0';
  6280. strcpy(dataStr, sstr);
  6281. return result;
  6282. }
  6283. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6284. {
  6285. mtrace();
  6286. int result = FAIL;
  6287. char message[1000]={0};
  6288. int CompositeScheduleIndex = 0;
  6289. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6290. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6291. if(nPeriod == 0)
  6292. {
  6293. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6294. {
  6295. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6296. ,MESSAGE_TYPE_CALLRESULT
  6297. ,uuid
  6298. ,payload
  6299. ,connectorIdInt);
  6300. }
  6301. else
  6302. {
  6303. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6304. ,MESSAGE_TYPE_CALLRESULT
  6305. ,uuid
  6306. ,payload
  6307. ,connectorIdInt
  6308. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6309. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6310. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6311. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6312. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6313. }
  6314. }
  6315. else
  6316. {
  6317. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6318. ,MESSAGE_TYPE_CALLRESULT
  6319. ,uuid
  6320. ,payload
  6321. ,connectorIdInt
  6322. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6323. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6324. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6325. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6326. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6327. {
  6328. if (idx_sample == 0)
  6329. {
  6330. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6331. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6332. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6333. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6334. }
  6335. else
  6336. {
  6337. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6338. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6339. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6340. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6341. }
  6342. }
  6343. sprintf(message + strlen(message), "]}}]");
  6344. }
  6345. LWS_Send(message);
  6346. result = TRUE;
  6347. return result;
  6348. }
  6349. int sendGetConfigurationConfirmation(char *uuid)
  6350. {
  6351. mtrace();
  6352. int result = FAIL;
  6353. int MaxKeySupported = 0;
  6354. int sentConfigurationNumber= 0;
  6355. int sentunConfigurationNumber= 0;
  6356. char message[4000]={0};
  6357. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6358. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6359. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6360. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6361. ,MESSAGE_TYPE_CALLRESULT
  6362. ,uuid );
  6363. //configuration key
  6364. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6365. {
  6366. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6367. {
  6368. if (sentConfigurationNumber == 0)
  6369. {
  6370. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6371. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6372. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6373. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6374. }
  6375. else
  6376. {
  6377. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6378. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6379. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6380. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6381. }
  6382. sentConfigurationNumber = sentConfigurationNumber + 1;
  6383. }
  6384. }
  6385. sprintf(message + strlen(message), "]");
  6386. if(UnknownKeynum != 0)
  6387. {
  6388. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6389. //unkown key
  6390. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6391. {
  6392. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6393. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6394. if(sentunConfigurationNumber == 0)
  6395. {
  6396. sprintf(message + strlen(message), "\"%s\""
  6397. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6398. }
  6399. else
  6400. {
  6401. sprintf(message + strlen(message), ",\"%s\""
  6402. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6403. }
  6404. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6405. }
  6406. sprintf(message + strlen(message), "]");
  6407. }
  6408. sprintf(message + strlen(message), "}]");
  6409. LWS_Send(message);
  6410. return result;
  6411. }
  6412. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6413. {
  6414. mtrace();
  6415. int result = FAIL;
  6416. char message[400]={0};
  6417. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6418. if(strcmp(payload,"")==0)
  6419. {
  6420. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6421. }
  6422. else
  6423. {
  6424. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6425. }
  6426. LWS_Send(message);
  6427. result = TRUE;
  6428. return result;
  6429. }
  6430. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6431. {
  6432. mtrace();
  6433. int result = FAIL;
  6434. char message[80]={0};
  6435. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6436. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  6437. LWS_Send(message);
  6438. result = TRUE;
  6439. return result;
  6440. }
  6441. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6442. {
  6443. mtrace();
  6444. int result = FAIL;
  6445. char message[80]={0};
  6446. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6447. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6448. LWS_Send(message);
  6449. result = TRUE;
  6450. return result;
  6451. }
  6452. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6453. {
  6454. mtrace();
  6455. int result = FAIL;
  6456. char message[80]={0};
  6457. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6458. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6459. LWS_Send(message);
  6460. result = TRUE;
  6461. return result;
  6462. }
  6463. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6464. {
  6465. mtrace();
  6466. int result = FAIL;
  6467. char message[80]={0};
  6468. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6469. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6470. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6471. LWS_Send(message);
  6472. result = TRUE;
  6473. return result;
  6474. }
  6475. int sendResetConfirmation(char *uuid,char *payload)
  6476. {
  6477. mtrace();
  6478. int result = FAIL;
  6479. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6480. char message[80]={0};
  6481. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6482. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6483. LWS_Send(message);
  6484. result = TRUE;
  6485. return result;
  6486. }
  6487. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6488. {
  6489. mtrace();
  6490. int result = FAIL;
  6491. char message[500]={0};
  6492. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6493. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6494. LWS_Send(message);
  6495. result = TRUE;
  6496. return result;
  6497. }
  6498. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6499. {
  6500. mtrace();
  6501. int result = FAIL;
  6502. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6503. char message[80]={0};
  6504. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6505. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6506. LWS_Send(message);
  6507. result = TRUE;
  6508. return result;
  6509. }
  6510. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6511. {
  6512. mtrace();
  6513. int result = FAIL;
  6514. char message[80]={0};
  6515. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6516. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6517. LWS_Send(message);
  6518. result = TRUE;
  6519. return result;
  6520. }
  6521. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6522. {
  6523. mtrace();
  6524. int result = FAIL;
  6525. char message[80]={0};
  6526. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6527. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6528. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6529. LWS_Send(message);
  6530. result = TRUE;
  6531. return result;
  6532. }
  6533. int sendUpdateFirmwareConfirmation(char *uuid)
  6534. {
  6535. mtrace();
  6536. int result = FAIL;
  6537. char message[60]={0};
  6538. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6539. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6540. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6541. LWS_Send(message);
  6542. result = TRUE;
  6543. return result;
  6544. }
  6545. int sendCertificateSignedConfirmation(char *uuid)
  6546. {
  6547. mtrace();
  6548. int result = PASS;
  6549. char message[4096]={0};
  6550. json_object *CertificateSigned = json_object_new_object();
  6551. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6552. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6553. sprintf(message,"[%d,\"%s\",%s]"
  6554. ,MESSAGE_TYPE_CALLRESULT
  6555. ,uuid
  6556. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6557. json_object_put(CertificateSigned);
  6558. LWS_Send(message);
  6559. return result;
  6560. }
  6561. int sendDeleteCertificateConfirmation(char *uuid)
  6562. {
  6563. mtrace();
  6564. int result = PASS;
  6565. char message[4096]={0};
  6566. json_object *DeleteCertificate = json_object_new_object();
  6567. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6568. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6569. sprintf(message,"[%d,\"%s\",%s]"
  6570. ,MESSAGE_TYPE_CALLRESULT
  6571. ,uuid
  6572. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6573. json_object_put(DeleteCertificate);
  6574. LWS_Send(message);
  6575. return result;
  6576. }
  6577. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6578. {
  6579. mtrace();
  6580. int result = PASS;
  6581. char message[4096]={0};
  6582. json_object *ExtendedTriggerMessage = json_object_new_object();
  6583. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6584. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6585. sprintf(message,"[%d,\"%s\",%s]"
  6586. ,MESSAGE_TYPE_CALLRESULT
  6587. ,uuid
  6588. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6589. json_object_put(ExtendedTriggerMessage);
  6590. LWS_Send(message);
  6591. return result;
  6592. }
  6593. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6594. {
  6595. mtrace();
  6596. int result = PASS;
  6597. char message[4096]={0};
  6598. json_object *GetInstalledCertificateIds = json_object_new_object();
  6599. json_object *certificateHashDataDatas = json_object_new_array();
  6600. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6601. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6602. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6603. {
  6604. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6605. {
  6606. json_object *certificateHashData = json_object_new_object();
  6607. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6608. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6609. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6610. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6611. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6612. }
  6613. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6614. }
  6615. else
  6616. {
  6617. json_object_put(certificateHashDataDatas);
  6618. }
  6619. sprintf(message,"[%d,\"%s\",%s]"
  6620. ,MESSAGE_TYPE_CALLRESULT
  6621. ,uuid
  6622. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6623. json_object_put(GetInstalledCertificateIds);
  6624. LWS_Send(message);
  6625. return result;
  6626. }
  6627. int sendGetLogConfirmation(char *uuid)
  6628. {
  6629. mtrace();
  6630. int result = PASS;
  6631. char message[4096]={0};
  6632. json_object *GetLog = json_object_new_object();
  6633. DEBUG_INFO("sendGetLogConfirmation...\n");
  6634. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6635. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6636. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6637. sprintf(message,"[%d,\"%s\",%s]"
  6638. ,MESSAGE_TYPE_CALLRESULT
  6639. ,uuid
  6640. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6641. json_object_put(GetLog);
  6642. LWS_Send(message);
  6643. return result;
  6644. }
  6645. int sendInstallCertificateConfirmation(char *uuid)
  6646. {
  6647. mtrace();
  6648. int result = PASS;
  6649. char message[4096]={0};
  6650. json_object *InstallCertificate = json_object_new_object();
  6651. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6652. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6653. sprintf(message,"[%d,\"%s\",%s]"
  6654. ,MESSAGE_TYPE_CALLRESULT
  6655. ,uuid
  6656. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6657. json_object_put(InstallCertificate);
  6658. LWS_Send(message);
  6659. return result;
  6660. }
  6661. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6662. {
  6663. mtrace();
  6664. int result = PASS;
  6665. char message[4096]={0};
  6666. json_object *SignedUpdateFirmware = json_object_new_object();
  6667. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6668. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  6669. sprintf(message,"[%d,\"%s\",%s]"
  6670. ,MESSAGE_TYPE_CALLRESULT
  6671. ,uuid
  6672. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6673. json_object_put(SignedUpdateFirmware);
  6674. LWS_Send(message);
  6675. return result;
  6676. }
  6677. int sendUnknownConfirmation(char *uuid)
  6678. {
  6679. mtrace();
  6680. int result = PASS;
  6681. char message[256]={0};
  6682. DEBUG_INFO("sendUnknownConfirmation...\n");
  6683. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6684. LWS_Send(message);
  6685. return result;
  6686. }
  6687. //==========================================
  6688. // Handle server request routine Start
  6689. //==========================================
  6690. int handleCancelReservationRequest(char *uuid, char *payload)
  6691. {
  6692. mtrace();
  6693. int result = FAIL;
  6694. int gunNO = 0;
  6695. int reservationIdInt = -1;
  6696. char comfirmstr[20];
  6697. DEBUG_INFO("handleCancelReservationRequest...\n");
  6698. json_object *CancelReservation;
  6699. CancelReservation = json_tokener_parse(payload);
  6700. if(!is_error(CancelReservation))
  6701. {
  6702. // Required data
  6703. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6704. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6705. }
  6706. json_object_put(CancelReservation);
  6707. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6708. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6709. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6710. if(reservationIdInt != -1)
  6711. {
  6712. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6713. //check Transaction active
  6714. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6715. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6716. {
  6717. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6718. {
  6719. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6720. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6721. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6722. {
  6723. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6724. }
  6725. else
  6726. {
  6727. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6728. }
  6729. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6730. goto end;
  6731. }
  6732. }
  6733. for (int index = 0; index < CCS_QUANTITY; index++)
  6734. {
  6735. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6736. {
  6737. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6738. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6739. if(gunType[2] == GUN_TYPE_CCS)
  6740. {
  6741. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6742. }
  6743. else
  6744. {
  6745. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6746. }
  6747. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6748. goto end;
  6749. }
  6750. }
  6751. for (int index = 0; index < GB_QUANTITY; index++)
  6752. {
  6753. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6754. {
  6755. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6756. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6757. if(gunType[2] == GUN_TYPE_GBT)
  6758. {
  6759. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6760. }
  6761. else
  6762. {
  6763. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6764. }
  6765. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6766. goto end;
  6767. }
  6768. }
  6769. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6770. {
  6771. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6772. {
  6773. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6774. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6775. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6776. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6777. goto end;
  6778. }
  6779. }
  6780. for (int index = 0; index < AC_QUANTITY; index++)
  6781. {
  6782. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6783. {
  6784. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6785. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6787. {
  6788. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6789. }
  6790. else
  6791. {
  6792. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6793. }
  6794. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6795. goto end;
  6796. }
  6797. }
  6798. }
  6799. //The reservationId does NOT match the reservationId
  6800. sendCancelReservationConfirmation(uuid, comfirmstr);
  6801. end:
  6802. // Fill in ocpp packet uuid
  6803. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  6804. return result;
  6805. }
  6806. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6807. {
  6808. mtrace();
  6809. int result = FAIL;
  6810. int gunIndex = 0;
  6811. char typeStr[16]={0};
  6812. char comfirmstr[20];
  6813. int specificId = FALSE;
  6814. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6815. json_object *ChangeAvailability;
  6816. ChangeAvailability = json_tokener_parse(payload);
  6817. if(!is_error(ChangeAvailability))
  6818. {
  6819. // Required data
  6820. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6821. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6822. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6823. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6824. }
  6825. json_object_put(ChangeAvailability);
  6826. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6827. {
  6828. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6829. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6830. }
  6831. else if(gunIndex == 0)
  6832. {
  6833. for(int i=0; i < gunTotalNumber; i++)
  6834. {
  6835. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  6836. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  6837. }
  6838. }
  6839. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6840. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6841. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6842. {
  6843. specificId = TRUE;
  6844. }
  6845. if(specificId == FALSE)
  6846. goto end;
  6847. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6848. {
  6849. //----------------------gunIndex is 0 ------------------------------------------------//
  6850. if(gunIndex == 0)
  6851. {
  6852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6853. {
  6854. for(int i=0; i < gunTotalNumber; i++)
  6855. {
  6856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6857. {
  6858. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6859. {
  6860. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6861. {
  6862. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6863. goto end;
  6864. }
  6865. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6866. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6867. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6868. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6869. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6870. {
  6871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6872. goto end;
  6873. }
  6874. }
  6875. }//END FOR CHAdeMO_QUANTITY
  6876. for (int index = 0; index < CCS_QUANTITY; index++)
  6877. {
  6878. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6879. {
  6880. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6881. {
  6882. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6883. goto end;
  6884. }
  6885. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6886. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6887. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6888. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6889. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6890. {
  6891. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6892. goto end;
  6893. }
  6894. }
  6895. }//END FOR CCS_QUANTITY
  6896. for (int index = 0; index < GB_QUANTITY; index++)
  6897. {
  6898. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6899. {
  6900. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6901. {
  6902. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6903. goto end;
  6904. }
  6905. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6906. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6907. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6908. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6909. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6910. {
  6911. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6912. goto end;
  6913. }
  6914. }
  6915. }// END FOR GB_QUANTITY
  6916. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6917. {
  6918. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6919. {
  6920. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6921. {
  6922. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6923. goto end;
  6924. }
  6925. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6926. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6927. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6928. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6929. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6930. {
  6931. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6932. goto end;
  6933. }
  6934. }
  6935. }// END FOR GENERAL_GUN_QUANTITY
  6936. for (int index = 0; index < AC_QUANTITY; index++)
  6937. {
  6938. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6939. {
  6940. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6941. {
  6942. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6943. goto end;
  6944. }
  6945. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6946. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6947. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6948. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6949. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6950. {
  6951. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6952. goto end;
  6953. }
  6954. }
  6955. }//END FOR AC_QUANTITY
  6956. }// END FOR gunTotalNumber
  6957. }
  6958. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6959. {
  6960. for(int i=0; i < gunTotalNumber; i++)
  6961. {
  6962. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6963. {
  6964. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6965. goto end;
  6966. }
  6967. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6968. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6969. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6970. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6971. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6972. {
  6973. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6974. goto end;
  6975. }
  6976. }
  6977. }
  6978. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6979. goto end;
  6980. }
  6981. //----------------------gunIndex is not 0 ------------------------------------------------//
  6982. //check Transaction active
  6983. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6984. {
  6985. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6986. {
  6987. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6988. {
  6989. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6990. goto end;
  6991. }
  6992. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6993. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6994. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6995. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6996. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6997. {
  6998. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6999. goto end;
  7000. }
  7001. else
  7002. {
  7003. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7004. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7005. goto end;
  7006. }
  7007. }
  7008. }//END FOR CHAdeMO_QUANTITY
  7009. for (int index = 0; index < CCS_QUANTITY; index++)
  7010. {
  7011. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7012. {
  7013. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7014. {
  7015. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7016. goto end;
  7017. }
  7018. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7019. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7020. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7021. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7022. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7023. {
  7024. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7025. goto end;
  7026. }
  7027. else
  7028. {
  7029. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7030. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7031. goto end;
  7032. }
  7033. }
  7034. }//END FOR CCS_QUANTITY
  7035. for (int index = 0; index < GB_QUANTITY; index++)
  7036. {
  7037. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7038. {
  7039. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7040. {
  7041. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7042. goto end;
  7043. }
  7044. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7045. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7046. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7047. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7048. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7049. {
  7050. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7051. goto end;
  7052. }
  7053. else
  7054. {
  7055. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7056. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7057. goto end;
  7058. }
  7059. }
  7060. }// END FOR GB_QUANTITY
  7061. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7062. {
  7063. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7064. {
  7065. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7066. {
  7067. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7068. goto end;
  7069. }
  7070. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7071. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7072. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7073. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7074. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7075. {
  7076. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7077. goto end;
  7078. }
  7079. else
  7080. {
  7081. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7082. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7083. goto end;
  7084. }
  7085. }
  7086. }// END FOR GENERAL_GUN_QUANTITY
  7087. for (int index = 0; index < AC_QUANTITY; index++)
  7088. {
  7089. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7090. {
  7091. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7092. {
  7093. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7094. goto end;
  7095. }
  7096. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7097. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7098. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7099. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7100. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7101. {
  7102. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7103. goto end;
  7104. }
  7105. else
  7106. {
  7107. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7108. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7109. goto end;
  7110. }
  7111. }
  7112. }//END FOR AC_QUANTITY
  7113. }//END FOR AvailabilityTypeStr[Inoperative]
  7114. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7115. {
  7116. //----------------------gunIndex is 0 ------------------------------------------------//
  7117. if(gunIndex == 0)
  7118. {
  7119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7120. {
  7121. for(int i=0; i < gunTotalNumber; i++)
  7122. {
  7123. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7124. {
  7125. 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
  7126. {
  7127. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7128. goto end;
  7129. }
  7130. }//END FOR CHAdeMO_QUANTITY
  7131. for (int index = 0; index < CCS_QUANTITY; index++)
  7132. {
  7133. 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
  7134. {
  7135. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7136. goto end;
  7137. }
  7138. }//END FOR CCS_QUANTITY
  7139. for (int index = 0; index < GB_QUANTITY; index++)
  7140. {
  7141. 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
  7142. {
  7143. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7144. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7145. goto end;
  7146. }
  7147. }// END FOR GB_QUANTITY
  7148. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7149. {
  7150. 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
  7151. {
  7152. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7154. goto end;
  7155. }
  7156. }// END FOR GENERAL_GUN_QUANTITY
  7157. for (int index = 0; index < AC_QUANTITY; index++)
  7158. {
  7159. 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
  7160. {
  7161. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7162. goto end;
  7163. }
  7164. }//END FOR CHAdeMO_QUANTITY
  7165. }// END FOR gunTotalNumber
  7166. }
  7167. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7168. {
  7169. for(int i=0; i < gunTotalNumber; i++)
  7170. {
  7171. for (int index = 0; index < AC_QUANTITY; index++)
  7172. {
  7173. 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
  7174. {
  7175. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7176. goto end;
  7177. }
  7178. }//END FOR CHAdeMO_QUANTITY
  7179. } // END FOR gunTotalNumber
  7180. }
  7181. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7182. goto end;
  7183. }
  7184. //----------------------gunIndex is not 0 ------------------------------------------------//
  7185. //check Transaction active
  7186. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7187. {
  7188. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7189. {
  7190. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7191. goto end;
  7192. }
  7193. }//END FOR CHAdeMO_QUANTITY
  7194. for (int index = 0; index < CCS_QUANTITY; index++)
  7195. {
  7196. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7197. {
  7198. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7199. goto end;
  7200. }
  7201. }//END FOR CCS_QUANTITY
  7202. for (int index = 0; index < GB_QUANTITY; index++)
  7203. {
  7204. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7205. {
  7206. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7207. goto end;
  7208. }
  7209. }// END FOR GB_QUANTITY
  7210. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7211. {
  7212. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7213. {
  7214. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7215. goto end;
  7216. }
  7217. }// END FOR GENERAL_GUN_QUANTITY
  7218. for (int index = 0; index < AC_QUANTITY; index++)
  7219. {
  7220. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7221. {
  7222. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7223. goto end;
  7224. }
  7225. }//END FOR AC_QUANTITY
  7226. }//END FOR AvailabilityTypeStr[Operative]
  7227. end:
  7228. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7229. {
  7230. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7231. }
  7232. else
  7233. {
  7234. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7235. }
  7236. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7237. {
  7238. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7239. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7240. }
  7241. else if(gunIndex == 0)
  7242. {
  7243. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7244. {
  7245. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7246. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7247. }
  7248. }
  7249. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7250. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7251. return result;
  7252. }
  7253. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7254. {
  7255. mtrace();
  7256. int result = FAIL;
  7257. char keystr[40]={0};
  7258. char valuestr[256]={0};
  7259. char comfirmstr[20]={0};
  7260. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7261. json_object *ChangeConfiguration;
  7262. ChangeConfiguration = json_tokener_parse(payload);
  7263. if(!is_error(ChangeConfiguration))
  7264. {
  7265. // Required data
  7266. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7267. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7268. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7269. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7270. }
  7271. json_object_put(ChangeConfiguration);
  7272. if((uuid==NULL) || (payload ==NULL) )
  7273. {
  7274. DEBUG_ERROR("Payload is null\n");
  7275. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7276. }
  7277. else
  7278. {
  7279. int status = setKeyValue(keystr, valuestr);
  7280. switch(status)
  7281. {
  7282. case ConfigurationStatus_Accepted:
  7283. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7284. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7285. StoreConfigurationTable();
  7286. break;
  7287. case RebootRequired:
  7288. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7289. StoreConfigurationTable();
  7290. break;
  7291. case NotSupported:
  7292. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7293. break;
  7294. case ConfigurationStatus_Rejected:
  7295. default:
  7296. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7297. break;
  7298. }
  7299. }
  7300. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7301. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7302. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7303. {
  7304. ChageWebSocketPingInterval(atoi(valuestr));
  7305. }
  7306. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7307. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7308. {
  7309. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7310. SetOcppConnStatus(FALSE);
  7311. }
  7312. return result;
  7313. }
  7314. int handleClearCacheRequest(char *uuid, char *payload)
  7315. {
  7316. mtrace();
  7317. int result = FAIL;
  7318. char comfirmstr[20];
  7319. char rmFileCmd[100]={0};
  7320. struct stat stats;
  7321. DEBUG_INFO("handleClearCacheRequest...\n");
  7322. stat("/Storage/OCPP_PH", &stats);
  7323. // Check for directory existence
  7324. if (S_ISDIR(stats.st_mode) == 1)
  7325. {}
  7326. else
  7327. {
  7328. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7329. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  7330. system(rmFileCmd);
  7331. }
  7332. if(OCPP_cleanLocalCache())
  7333. {
  7334. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7335. }
  7336. else
  7337. {
  7338. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7339. }
  7340. sendClearCacheConfirmation(uuid, comfirmstr);
  7341. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7342. return result;
  7343. }
  7344. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7345. {
  7346. mtrace();
  7347. int result = FAIL;
  7348. int resultRename;
  7349. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7350. char chargingProfilePurposeStr[26]={0};
  7351. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7352. char tempchargingProfilePurposeStr[26]={0};
  7353. char str[100]={0};
  7354. char fname[200]={0};
  7355. char comfirmstr[20]={0};
  7356. char word[1600]={0};
  7357. int clearflag = FALSE;
  7358. int chargingProfileIdIsNULL = FALSE;
  7359. int connectorIsNULL = FALSE;
  7360. int chargingProfilePurposeIsNULL = FALSE;
  7361. int stackLevelIsNULL = FALSE;
  7362. //int GotoEnd = FALSE;
  7363. FILE *fptr1, *fptr2;
  7364. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  7365. int n_chargingProfile=0;
  7366. int isEmptyFile = FALSE;
  7367. char sLineWord[1600]={0};
  7368. char chargingProfiles[10][100]={0};
  7369. int ChargeProfileCount = 0;
  7370. int ch;
  7371. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7372. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7373. json_object *ClearChargingProfile;
  7374. ClearChargingProfile = json_tokener_parse(payload);
  7375. if(!is_error(ClearChargingProfile))
  7376. {
  7377. // Optional data
  7378. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7379. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7380. else
  7381. chargingProfileIdIsNULL = TRUE;
  7382. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7383. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7384. else
  7385. connectorIsNULL = TRUE;
  7386. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7387. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7388. else
  7389. chargingProfilePurposeIsNULL = TRUE;
  7390. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7391. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7392. else
  7393. stackLevelIsNULL = TRUE;
  7394. }
  7395. json_object_put(ClearChargingProfile);
  7396. if(connectorIsNULL == FALSE)
  7397. {
  7398. switch(connectorIdInt)
  7399. {
  7400. case 0:
  7401. if(chargingProfilePurposeIsNULL == TRUE)
  7402. {
  7403. int l = 0;
  7404. strcpy(fname, ChargePointMaxProfile_JSON);
  7405. if((access(fname,F_OK))!=-1)
  7406. {
  7407. strcpy(chargingProfiles[l], fname);
  7408. l = l + 1;
  7409. }
  7410. strcpy(fname, TxDefaultProfile_0_JSON);
  7411. if((access(fname,F_OK))!=-1)
  7412. {
  7413. strcpy(chargingProfiles[l], fname);
  7414. l = l + 1;
  7415. }
  7416. ChargeProfileCount = l;
  7417. }
  7418. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7419. {
  7420. strcpy(fname, ChargePointMaxProfile_JSON);
  7421. if((access(fname,F_OK))!=-1)
  7422. {
  7423. strcpy(chargingProfiles[0], fname);
  7424. ChargeProfileCount = 1;
  7425. }
  7426. }
  7427. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7428. {
  7429. strcpy(fname, TxDefaultProfile_0_JSON);
  7430. if((access(fname,F_OK))!=-1)
  7431. {
  7432. strcpy(chargingProfiles[0], fname);
  7433. ChargeProfileCount = 1;
  7434. }
  7435. }
  7436. break;
  7437. default:
  7438. if(chargingProfilePurposeIsNULL == TRUE)
  7439. {
  7440. int m = 0;
  7441. memset(fname, 0, ARRAY_SIZE(fname));
  7442. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7443. if((access(fname,F_OK))!=-1)
  7444. {
  7445. strcpy(chargingProfiles[m], fname);
  7446. m = m + 1;
  7447. }
  7448. memset(fname, 0, ARRAY_SIZE(fname));
  7449. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7450. if((access(fname,F_OK))!=-1)
  7451. {
  7452. strcpy(chargingProfiles[m], fname);
  7453. m = m + 1;
  7454. }
  7455. ChargeProfileCount = m;
  7456. }
  7457. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7458. {
  7459. //strcpy(fname, TxDefaultProfile_1_JSON);
  7460. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7461. if((access(fname,F_OK))!=-1)
  7462. {
  7463. strcpy(chargingProfiles[0], fname);
  7464. ChargeProfileCount = 1;
  7465. }
  7466. }
  7467. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7468. {
  7469. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7470. if((access(fname,F_OK))!=-1)
  7471. {
  7472. strcpy(chargingProfiles[0], fname);
  7473. ChargeProfileCount = 1;
  7474. }
  7475. //strcpy(fname, TxProfile_1_JSON);
  7476. }
  7477. //strcpy(fname, ChargePointMaxProfile_JSON );
  7478. break;
  7479. }
  7480. }
  7481. else // Check all Charging Profiles
  7482. {
  7483. int i = 0;
  7484. char fnametemp[200]={0};
  7485. ChargeProfileCount = 0;
  7486. //Check ChargePointMaxProfile.json exit
  7487. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7488. {
  7489. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7490. i = i + 1;
  7491. }
  7492. //Check TxDefaultProfile_0.json exit
  7493. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7494. {
  7495. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7496. i = i + 1;
  7497. }
  7498. //Check TxDefaultProfile_%d.json
  7499. for(int j=1; j <= gunTotalNumber; j++)
  7500. {
  7501. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7502. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7503. if((access(fnametemp,F_OK))!=-1)
  7504. {
  7505. strcpy(chargingProfiles[i], fnametemp);
  7506. i = i + 1;
  7507. }
  7508. }
  7509. //Check TxProfile_%d.json
  7510. for(int j=1; j <= gunTotalNumber; j++)
  7511. {
  7512. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7513. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7514. if((access(fnametemp,F_OK))!=-1)
  7515. {
  7516. strcpy(chargingProfiles[i], fnametemp);
  7517. i = i + 1;
  7518. }
  7519. }
  7520. ChargeProfileCount = i;
  7521. }// End connectorIsNULL is TRUE
  7522. if(ChargeProfileCount == 0)
  7523. {
  7524. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7525. goto end;
  7526. }
  7527. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7528. {
  7529. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7530. goto end;
  7531. }
  7532. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7533. {
  7534. memset(str, 0, ARRAY_SIZE(str));
  7535. // clear temp file
  7536. sprintf(str,"rm -f %s",temp);
  7537. system(str);
  7538. for(int k=0; k < ChargeProfileCount; k++)
  7539. {
  7540. memset(str, 0, ARRAY_SIZE(str));
  7541. //clear file in C
  7542. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7543. system(str);
  7544. }
  7545. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7546. goto end;
  7547. }
  7548. else if(connectorIsNULL == TRUE)
  7549. {
  7550. for(int k=0; k < ChargeProfileCount; k++)
  7551. {
  7552. fptr1 = fopen(chargingProfiles[k], "r");
  7553. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7554. //Check Charging Profile Count
  7555. while(fscanf(fptr1, "%s", word) != EOF)
  7556. {
  7557. //DEBUG_INFO("word=%s\n",word);
  7558. if(strstr(word, "chargingProfileId")!= NULL)
  7559. {
  7560. //DEBUG_INFO("test chargingProfileId \n");
  7561. n_chargingProfile = n_chargingProfile + 1;
  7562. //DEBUG_INFO("chargingProfileId Found\n");
  7563. }
  7564. }
  7565. rewind(fptr1);
  7566. //search Charging Profile Element
  7567. //int i= 0;
  7568. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7569. {
  7570. json_object *tmpProfilee;
  7571. tmpProfilee = json_tokener_parse(sLineWord);
  7572. if(!is_error(tmpProfilee))
  7573. {
  7574. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7575. {
  7576. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7577. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7578. }
  7579. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7580. {
  7581. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7582. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7583. }
  7584. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7585. {
  7586. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7587. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7588. }
  7589. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7590. {
  7591. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7592. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7593. }
  7594. }
  7595. json_object_put(tmpProfilee);
  7596. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7597. {
  7598. //------- not write to fptr2-------//
  7599. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7600. //clearflag = TRUE;
  7601. }
  7602. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7603. {
  7604. //------- not write to fptr2-------//
  7605. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7606. }
  7607. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7608. {
  7609. //------- not write to fptr2-------//
  7610. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7611. }
  7612. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7613. {
  7614. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7615. }
  7616. else
  7617. {
  7618. fprintf(fptr2, sLineWord);//writing data into file
  7619. }
  7620. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7621. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7622. if(clearflag == TRUE)
  7623. {
  7624. fclose(fptr1);
  7625. fclose(fptr2);
  7626. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7627. system(str);
  7628. // clear temp file
  7629. sprintf(str,"rm -f %s",temp);
  7630. system(str);
  7631. }
  7632. else
  7633. {
  7634. fclose(fptr1);
  7635. fclose(fptr2);
  7636. memset(str, 0, ARRAY_SIZE(str));
  7637. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7638. system(str);
  7639. resultRename = rename(temp, chargingProfiles[k]);
  7640. if(resultRename == 0)
  7641. {
  7642. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7643. }
  7644. else
  7645. {
  7646. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7647. }
  7648. if(comfirmstr[0]== 0)
  7649. {
  7650. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7651. }
  7652. //Check chargingProfile is empty file
  7653. /*------ Read the file ----------------*/
  7654. fptr1=fopen(chargingProfiles[k],"r");
  7655. ch=fgetc(fptr1);
  7656. rewind(fptr1);
  7657. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7658. if(ch!=EOF)
  7659. {
  7660. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7661. {
  7662. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7663. if(sLineWord[0]=='\0')
  7664. {
  7665. isEmptyFile = TRUE;
  7666. break;
  7667. }
  7668. else
  7669. {
  7670. isEmptyFile = FALSE;
  7671. break;
  7672. }
  7673. }
  7674. }
  7675. else
  7676. isEmptyFile = TRUE;
  7677. fclose(fptr1);
  7678. if(isEmptyFile == TRUE)
  7679. {
  7680. memset(str, 0, ARRAY_SIZE(str));
  7681. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7682. system(str);
  7683. }
  7684. }
  7685. }// End of while(int k=0; k < ChargePointCount; k++)
  7686. }
  7687. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7688. {
  7689. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7690. for(int k=0; k < ChargeProfileCount; k++)
  7691. {
  7692. fptr1 = fopen(chargingProfiles[k], "r");
  7693. fptr2 = fopen(temp, "w+");
  7694. //Check Charging Profile Count
  7695. while(fscanf(fptr1, "%s", word) != EOF)
  7696. {
  7697. //DEBUG_INFO("word=%s\n",word);
  7698. if(strstr(word, "chargingProfileId")!= NULL)
  7699. {
  7700. n_chargingProfile = n_chargingProfile + 1;
  7701. }
  7702. }
  7703. rewind(fptr1);
  7704. //search Charging Profile Element
  7705. //int i= 0;
  7706. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7707. {
  7708. json_object *tmpProfilee;
  7709. tmpProfilee = json_tokener_parse(sLineWord);
  7710. if(!is_error(tmpProfilee))
  7711. {
  7712. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7713. {
  7714. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7715. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7716. }
  7717. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7718. {
  7719. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7720. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7721. }
  7722. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7723. {
  7724. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7725. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7726. }
  7727. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7728. {
  7729. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7730. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7731. }
  7732. }
  7733. json_object_put(tmpProfilee);
  7734. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7735. {
  7736. //------- not write to fptr2-------//
  7737. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7738. //clearflag = TRUE;
  7739. }
  7740. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7741. {
  7742. //------- not write to fptr2-------//
  7743. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7744. }
  7745. else if(stackLevelIsNULL == TRUE)
  7746. {
  7747. //Clear Whole File
  7748. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7749. clearflag = TRUE;
  7750. break;
  7751. }
  7752. else
  7753. {
  7754. fprintf(fptr2, sLineWord);//writing data into file
  7755. }
  7756. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7757. }
  7758. if(clearflag == TRUE)
  7759. {
  7760. fclose(fptr1);
  7761. fclose(fptr2);
  7762. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7763. system(str);
  7764. // clear temp file
  7765. sprintf(str,"rm -f %s",temp);
  7766. system(str);
  7767. }
  7768. else
  7769. {
  7770. fclose(fptr1);
  7771. fclose(fptr2);
  7772. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7773. system(str);
  7774. resultRename = rename(temp, chargingProfiles[k]);
  7775. if(resultRename == 0)
  7776. {
  7777. DEBUG_INFO("File ChargingProfile renamed successfully");
  7778. }
  7779. else
  7780. {
  7781. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7782. }
  7783. if(comfirmstr[0]== 0)
  7784. {
  7785. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7786. }
  7787. //Check chargingProfile is empty file
  7788. /*------ Read the file ----------------*/
  7789. fptr1=fopen(chargingProfiles[k],"r");
  7790. ch=fgetc(fptr1);
  7791. rewind(fptr1);
  7792. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7793. if(ch!=EOF)
  7794. {
  7795. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7796. {
  7797. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7798. if(sLineWord[0]=='\0')
  7799. {
  7800. isEmptyFile = TRUE;
  7801. break;
  7802. }
  7803. else
  7804. {
  7805. isEmptyFile = FALSE;
  7806. break;
  7807. }
  7808. }
  7809. }
  7810. else
  7811. isEmptyFile = TRUE;
  7812. fclose(fptr1);
  7813. if(isEmptyFile == TRUE)
  7814. {
  7815. memset(str, 0, ARRAY_SIZE(str));
  7816. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7817. system(str);
  7818. }
  7819. /*------- End of reading ---------------*/
  7820. }
  7821. } // while(int k=0; k < ChargeProfileCount; k++)
  7822. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7823. end:
  7824. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7825. {
  7826. if(connectorIdInt == 0)
  7827. {
  7828. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7829. {
  7830. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  7831. }
  7832. }
  7833. else
  7834. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  7835. }
  7836. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7837. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7838. return result;
  7839. }
  7840. void createFirmwareVersionByDataTransfer(void)
  7841. {
  7842. json_object *FirmwareDataTransfer = json_object_new_object();
  7843. // AC & DC model
  7844. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7845. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7846. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7847. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7848. // DC model
  7849. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7850. {
  7851. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  7852. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  7853. (gunType[3] != GUN_TYPE_UNKNOWN))
  7854. {
  7855. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7856. }
  7857. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  7858. {
  7859. // DS DM DW
  7860. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7861. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7862. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7863. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7864. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7865. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7866. }
  7867. else
  7868. {
  7869. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7870. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7871. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7872. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7873. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7874. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7875. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7876. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7877. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7878. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7879. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7880. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7881. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7882. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7883. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7884. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7885. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7886. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7887. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7888. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7889. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7890. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7891. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7892. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7893. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7894. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7895. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7896. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7897. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7898. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7899. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7900. }
  7901. }
  7902. // 4G model
  7903. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7904. {
  7905. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7906. }
  7907. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7908. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7909. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7910. json_object_put(FirmwareDataTransfer);
  7911. }
  7912. int handleDataTransferRequest(char *uuid, char *payload)
  7913. {
  7914. mtrace();
  7915. json_object *response = json_object_new_object();
  7916. int result = FAIL;
  7917. char tempvendorId[255]={0};
  7918. char tempmessageId[50]={0};
  7919. char tempdata[512]={0};
  7920. char message[2048]={0};
  7921. DEBUG_INFO("handleDataTransferRequest...\n");
  7922. if((uuid != NULL) && (payload != NULL))
  7923. {
  7924. json_object *DataTransfer;
  7925. DataTransfer = json_tokener_parse(payload);
  7926. if(!is_error(DataTransfer))
  7927. {
  7928. // Required data
  7929. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7930. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7931. // Optional data
  7932. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7933. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7934. if(json_object_object_get(DataTransfer, "data") != NULL)
  7935. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7936. result = PASS;
  7937. }
  7938. json_object_put(DataTransfer);
  7939. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7940. {
  7941. // Send all moudle firmware version on EVSE
  7942. createFirmwareVersionByDataTransfer();
  7943. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7944. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  7945. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7946. json_object_put(response);
  7947. }
  7948. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7949. {
  7950. system("/usr/bin/run_tmate_restart.sh &");
  7951. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7952. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7953. json_object_put(response);
  7954. }
  7955. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7956. {
  7957. json_object *data;
  7958. data = json_tokener_parse(tempdata);
  7959. if(!is_error(data))
  7960. {
  7961. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7962. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7963. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7964. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7965. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7966. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7967. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7968. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7969. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7970. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7971. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7972. }
  7973. else
  7974. {
  7975. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7976. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7977. }
  7978. json_object_put(data);
  7979. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7980. json_object_put(response);
  7981. }
  7982. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7983. {
  7984. json_object *data;
  7985. data = json_tokener_parse(tempdata);
  7986. if(!is_error(data))
  7987. {
  7988. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7989. if(json_object_object_get(data, "idToken") != NULL)
  7990. {
  7991. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7992. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7993. }
  7994. if(json_object_object_get(data, "price") != NULL)
  7995. {
  7996. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7997. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7998. }
  7999. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8000. }
  8001. else
  8002. {
  8003. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8004. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8005. }
  8006. json_object_put(data);
  8007. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8008. json_object_put(response);
  8009. }
  8010. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8011. {
  8012. json_object *data;
  8013. data = json_tokener_parse(tempdata);
  8014. if(!is_error(data))
  8015. {
  8016. if(json_object_object_get(data, "txId") != NULL)
  8017. {
  8018. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8019. for(int idx = 0;idx<gunTotalNumber;idx++)
  8020. {
  8021. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8022. {
  8023. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8024. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8025. if(json_object_object_get(data, "description") != NULL)
  8026. {
  8027. // California pricing V1.0
  8028. DEBUG_INFO("California pricing V1.0\n");
  8029. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8030. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8031. }
  8032. else
  8033. {
  8034. // California pricing V1.1
  8035. DEBUG_INFO("California pricing V1.1\n");
  8036. if(json_object_object_get(data, "timestamp") != NULL)
  8037. {
  8038. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8039. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8040. }
  8041. if(json_object_object_get(data, "meterValue") != NULL)
  8042. {
  8043. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8044. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8045. }
  8046. if(json_object_object_get(data, "cost") != NULL)
  8047. {
  8048. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8049. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8050. }
  8051. if(json_object_object_get(data, "state") != NULL)
  8052. {
  8053. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8054. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8055. }
  8056. if(json_object_object_get(data, "chargingPrice") != NULL)
  8057. {
  8058. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8059. {
  8060. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8061. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8062. }
  8063. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8064. {
  8065. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8066. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8067. }
  8068. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8069. {
  8070. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8071. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8072. }
  8073. }
  8074. if(json_object_object_get(data, "idlePrice") != NULL)
  8075. {
  8076. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8077. {
  8078. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8079. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8080. }
  8081. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8082. {
  8083. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8084. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8085. }
  8086. }
  8087. if(json_object_object_get(data, "nextPeriod") != NULL)
  8088. {
  8089. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8090. {
  8091. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8092. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8093. }
  8094. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8095. {
  8096. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8097. {
  8098. 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")));
  8099. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice"));
  8100. }
  8101. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8102. {
  8103. 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")));
  8104. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice"));
  8105. }
  8106. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8107. {
  8108. 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")));
  8109. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee"));
  8110. }
  8111. }
  8112. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8113. {
  8114. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8115. {
  8116. 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")));
  8117. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes"));
  8118. }
  8119. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8120. {
  8121. 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")));
  8122. ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice"));
  8123. }
  8124. }
  8125. }
  8126. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8127. {
  8128. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8129. {
  8130. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8131. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8132. }
  8133. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8134. {
  8135. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8136. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8137. }
  8138. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8139. {
  8140. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8141. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8142. }
  8143. }
  8144. }
  8145. }
  8146. }
  8147. }
  8148. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8149. }
  8150. else
  8151. {
  8152. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8153. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8154. }
  8155. json_object_put(data);
  8156. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8157. json_object_put(response);
  8158. }
  8159. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8160. {
  8161. json_object *data;
  8162. data = json_tokener_parse(tempdata);
  8163. if(!is_error(data))
  8164. {
  8165. if(json_object_object_get(data, "txId") != NULL)
  8166. {
  8167. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8168. for(int idx = 0;idx<gunTotalNumber;idx++)
  8169. {
  8170. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8171. {
  8172. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8173. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8174. if(json_object_object_get(data, "description") != NULL)
  8175. {
  8176. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8177. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8178. }
  8179. }
  8180. }
  8181. }
  8182. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8183. }
  8184. else
  8185. {
  8186. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8187. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8188. }
  8189. json_object_put(data);
  8190. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8191. json_object_put(response);
  8192. }
  8193. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8194. {
  8195. json_object *data;
  8196. data = json_tokener_parse(tempdata);
  8197. if(!is_error(data))
  8198. {
  8199. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8200. if(json_object_object_get(data, "Content_Type") != NULL)
  8201. {
  8202. 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))
  8203. {
  8204. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8205. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8206. {
  8207. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8208. }
  8209. }
  8210. else
  8211. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8212. }
  8213. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8214. }
  8215. else
  8216. {
  8217. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8218. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8219. }
  8220. json_object_put(data);
  8221. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8222. json_object_put(response);
  8223. }
  8224. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8225. {
  8226. json_object *data;
  8227. data = json_tokener_parse(tempdata);
  8228. if(!is_error(data))
  8229. {
  8230. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8231. if(json_object_object_get(data, "Page_Index") != NULL)
  8232. {
  8233. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8234. }
  8235. if(json_object_object_get(data, "Duration") != NULL)
  8236. {
  8237. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8238. }
  8239. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8240. }
  8241. else
  8242. {
  8243. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8244. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8245. }
  8246. json_object_put(data);
  8247. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8248. json_object_put(response);
  8249. }
  8250. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8251. {
  8252. json_object *data;
  8253. data = json_tokener_parse(tempdata);
  8254. if(!is_error(data))
  8255. {
  8256. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8257. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8258. {
  8259. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8260. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8261. else
  8262. {
  8263. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8264. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8265. }
  8266. }
  8267. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8268. {
  8269. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8270. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8271. else
  8272. {
  8273. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8274. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8275. }
  8276. }
  8277. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8278. {
  8279. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8280. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8281. else
  8282. {
  8283. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8284. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8285. }
  8286. }
  8287. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8288. {
  8289. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8290. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8291. else
  8292. {
  8293. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8294. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8295. }
  8296. }
  8297. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8298. {
  8299. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8300. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8301. else
  8302. {
  8303. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8304. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8305. }
  8306. }
  8307. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8308. {
  8309. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8310. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8311. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8312. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8313. else
  8314. {
  8315. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8316. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8317. }
  8318. }
  8319. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8320. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8321. }
  8322. else
  8323. {
  8324. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8325. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8326. }
  8327. json_object_put(data);
  8328. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8329. json_object_put(response);
  8330. }
  8331. else
  8332. {
  8333. // Can not find valid message id
  8334. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8335. }
  8336. }
  8337. else
  8338. {
  8339. // Payload is null
  8340. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8341. }
  8342. LWS_Send(message);
  8343. return result;
  8344. }
  8345. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8346. {
  8347. mtrace();
  8348. int result = FAIL;
  8349. int connectorIdInt, durationInt;
  8350. char chargingRateUnitStr[4]={0};
  8351. char comfirmstr[20];
  8352. int confirmPeriods = 0;
  8353. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8354. json_object *GetCompositeSchedule;
  8355. GetCompositeSchedule = json_tokener_parse(payload);
  8356. if(!is_error(GetCompositeSchedule))
  8357. {
  8358. // Required data
  8359. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8360. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8361. else
  8362. connectorIdInt = -1;
  8363. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8364. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8365. else
  8366. durationInt = 86400;
  8367. // Optional data
  8368. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8369. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8370. }
  8371. json_object_put(GetCompositeSchedule);
  8372. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8373. if((connectorIdInt == 0) ||
  8374. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8375. {
  8376. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8377. struct StructChargingProfile tmpProfile[1];
  8378. if(strstr(chargingRateUnitStr, "W") != NULL)
  8379. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8380. else
  8381. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8382. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8383. {
  8384. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8385. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8386. }
  8387. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8388. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8389. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8390. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8391. {
  8392. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8393. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8394. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8395. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8396. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8397. {
  8398. confirmPeriods = idx;
  8399. break;
  8400. }
  8401. }
  8402. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8403. {
  8404. confirmPeriods += 1;
  8405. }
  8406. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8407. }
  8408. else
  8409. {
  8410. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8411. }
  8412. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8413. return result;
  8414. }
  8415. int handleGetConfigurationRequest(char *uuid, char *payload)
  8416. {
  8417. mtrace();
  8418. int result = FAIL;
  8419. int MaxKeySupported = 0;
  8420. int n_keys = 0;
  8421. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8422. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8423. json_object *GetConfiguration;
  8424. GetConfiguration = json_tokener_parse(payload);
  8425. if(!is_error(GetConfiguration))
  8426. {
  8427. // Optional data
  8428. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8429. {
  8430. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8431. {
  8432. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8433. n_keys = idx + 1;
  8434. }
  8435. }
  8436. }
  8437. json_object_put(GetConfiguration);
  8438. UnknownKeynum = 0;
  8439. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8440. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8441. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8442. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8443. if(n_keys != 0)
  8444. {
  8445. for(int i=0;i<n_keys;i++)
  8446. {
  8447. getKeyValue(requestKey[i]);
  8448. }
  8449. }
  8450. else
  8451. {
  8452. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8453. getKeyValue("");
  8454. }
  8455. processUnkownKey();
  8456. sendGetConfigurationConfirmation(uuid);
  8457. return result;
  8458. }
  8459. static char fnamePlusPath[100]={0};
  8460. static char fnamePWithNoPath[60]={0};
  8461. void checkUploadLog(void)
  8462. {
  8463. FILE *fp;
  8464. /* Open the command for reading. */
  8465. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8466. if (fp == NULL) {
  8467. DEBUG_WARN("Failed to run command\n" );
  8468. exit(1);
  8469. }
  8470. int ftppathlen = 0;
  8471. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8472. int i = 0;
  8473. /* Read the output a line at a time - output it. */
  8474. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8475. if(i==0)
  8476. {
  8477. ftppathlen = strlen(fnamePlusPath);
  8478. DEBUG_INFO("%s\n", fnamePlusPath);
  8479. fnamePlusPath[ftppathlen]='\0';
  8480. break;
  8481. }
  8482. i= i+1;
  8483. }
  8484. /* close */
  8485. pclose(fp);
  8486. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8487. {
  8488. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8489. {
  8490. fnamePlusPath[k]='\0';
  8491. }
  8492. }
  8493. i=1;
  8494. //char fname[60]={0};
  8495. while(i < ftppathlen)
  8496. {
  8497. int len=ftppathlen-i;
  8498. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8499. {
  8500. DEBUG_INFO("compare '/' all right\n");
  8501. break;
  8502. }
  8503. i=i+1;
  8504. }
  8505. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8506. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8507. fnamePWithNoPath[i+1] = '\0';
  8508. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8509. {
  8510. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8511. {
  8512. fnamePWithNoPath[j]='\0';
  8513. }
  8514. }
  8515. FILE* fp1 = fopen(fnamePlusPath, "r");
  8516. if (fp1)
  8517. {
  8518. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8519. // file exists
  8520. fclose(fp1);
  8521. }
  8522. else
  8523. {
  8524. // file doesn't exist
  8525. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8526. }
  8527. }
  8528. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8529. {
  8530. mtrace();
  8531. int result = FAIL;
  8532. time_t CurrentTime;
  8533. struct tm *tm;
  8534. pthread_t th_Status;
  8535. CurrentTime = time(NULL);
  8536. tm = localtime(&CurrentTime);
  8537. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  8538. sprintf((char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, "%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  8539. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8540. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8541. return result;
  8542. }
  8543. void* GetDiagnosticsProcess(void* data)
  8544. {
  8545. pthread_detach(pthread_self());
  8546. mtrace();
  8547. int retriesInt=0, retryIntervalInt=0;
  8548. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8549. char protocol[10]={0}, user[64]={0},password[128]={0},host[128]={0}, path[512]={0}, ftppath[512]={0},host1[128]={0},path1[512]={0};
  8550. int port=0;
  8551. int isSuccess = FALSE;
  8552. char ftpbuf[200]={0};
  8553. char cmdBuf[2048];
  8554. struct tm *tmNow;
  8555. time_t CurrentTime;
  8556. struct tm tmStart;
  8557. struct tm tmStop;
  8558. CurrentTime = time(NULL);
  8559. tmNow=localtime(&CurrentTime);
  8560. uint16_t targetYear, targetMonth;
  8561. json_object *GetDiagnostics;
  8562. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8563. GetDiagnostics = json_tokener_parse(data);
  8564. if(!is_error(GetDiagnostics))
  8565. {
  8566. // Required data
  8567. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8568. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8569. // Optional data
  8570. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8571. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8572. else
  8573. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8574. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8575. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8576. else
  8577. retryIntervalInt = 30;
  8578. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8579. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8580. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8581. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8582. }
  8583. json_object_put(GetDiagnostics);
  8584. // Pack log to compress file
  8585. 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) &&
  8586. (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))
  8587. {
  8588. // Pack system log
  8589. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8590. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8591. targetYear = tmStart.tm_year;
  8592. targetMonth = tmStart.tm_mon;
  8593. do
  8594. {
  8595. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8596. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8597. if(targetMonth+1>=13)
  8598. {
  8599. targetYear += 1;
  8600. targetMonth = 1;
  8601. }
  8602. else
  8603. {
  8604. targetMonth += 1;
  8605. }
  8606. }while((targetYear < (tmNow->tm_year+1900)) ||
  8607. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8608. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8609. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8610. system(cmdBuf);
  8611. // Pack charging & event log
  8612. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8613. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8614. targetYear = tmStart.tm_year;
  8615. targetMonth = tmStart.tm_mon;
  8616. do
  8617. {
  8618. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8619. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8620. if(targetMonth+1>=13)
  8621. {
  8622. targetYear += 1;
  8623. targetMonth = 1;
  8624. }
  8625. else
  8626. {
  8627. targetMonth += 1;
  8628. }
  8629. }while((targetYear < (tmNow->tm_year+1900)) ||
  8630. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8631. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8632. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8633. system(cmdBuf);
  8634. // Combine log file
  8635. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8636. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8637. }
  8638. else
  8639. {
  8640. system("exec /root/logPackTools 'log' 6");
  8641. }
  8642. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8643. system(cmdBuf);
  8644. checkUploadLog();
  8645. //****************location*******************/
  8646. if(strcmp(locationstr,"")==0)
  8647. {
  8648. DEBUG_INFO("location is <Empty>!\n");
  8649. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8650. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8651. goto end;
  8652. }
  8653. memset(protocol, 0, ARRAY_SIZE(protocol));
  8654. memset(user, 0, ARRAY_SIZE(user) );
  8655. memset(password, 0, ARRAY_SIZE(password));
  8656. memset(host, 0, ARRAY_SIZE(host));
  8657. memset(path, 0, ARRAY_SIZE(path));
  8658. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8659. memset(host1, 0, ARRAY_SIZE(host1));
  8660. memset(path1, 0, ARRAY_SIZE(path1));
  8661. /*location: ftp://user:password@host:port/path*/
  8662. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8663. if((access(fnamePlusPath,F_OK))!=-1)
  8664. {
  8665. DEBUG_INFO("fnamePlusPath exist.\n");
  8666. }
  8667. else
  8668. {
  8669. DEBUG_INFO("fnamePlusPath not exist!\n");
  8670. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8671. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8672. goto end;
  8673. }
  8674. if(strchr(locationstr,'@')==NULL)
  8675. {
  8676. sscanf(locationstr,
  8677. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8678. protocol, host, &port, path);
  8679. strcpy(user,"anonymous");
  8680. strcpy(password,"");
  8681. }
  8682. else
  8683. {
  8684. //DEBUG_INFO("pch=%s\n", pch);
  8685. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8686. protocol, user, password, host, &port, path);
  8687. }
  8688. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8689. {
  8690. DEBUG_INFO("protocol is not ftp/http ! \n");
  8691. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8692. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8693. goto end;
  8694. }
  8695. if(strncmp(locationstr,"http", 4) == 0)
  8696. {
  8697. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8698. sprintf(ftppath,"/%s", path);
  8699. do
  8700. {
  8701. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8702. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8703. sleep(3);
  8704. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8705. if(!isSuccess)
  8706. {
  8707. DEBUG_INFO("Diagnostics fail.\n");
  8708. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8709. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8710. sleep(retryIntervalInt);
  8711. }
  8712. else
  8713. {
  8714. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8715. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8716. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8717. }
  8718. retriesInt--;
  8719. }while((isSuccess == 0)&&(retriesInt >= 0));
  8720. }
  8721. else
  8722. {
  8723. sscanf(host,"%[^/]%s",host1, path1);
  8724. if(strlen(path) > 0)
  8725. sprintf(ftppath,"/%s", path);
  8726. else
  8727. sprintf(ftppath,"/%s", path1);
  8728. int ftppathlen=strlen(ftppath);
  8729. int i=1;
  8730. char filenametemp[50];
  8731. while(i < ftppathlen)
  8732. {
  8733. int len=ftppathlen-i;
  8734. if(ftppath[len]== 47) // '/' ascll code: 47
  8735. {
  8736. DEBUG_INFO("find '/' all right\n");
  8737. break;
  8738. }
  8739. i=i+1;
  8740. }
  8741. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8742. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8743. filenametemp[i+1] = 0;
  8744. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  8745. if(port == 0)
  8746. port = 21;
  8747. do
  8748. {
  8749. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8750. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8751. sleep(3);
  8752. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8753. if(!isSuccess)
  8754. {
  8755. DEBUG_INFO("Diagnostics fail.\n");
  8756. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8757. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8758. sleep(retryIntervalInt);
  8759. }
  8760. else
  8761. {
  8762. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8763. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8764. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8765. }
  8766. retriesInt--;
  8767. }while((!isSuccess)&&(retriesInt >= 0));
  8768. }
  8769. end:
  8770. system("rm -f /mnt/*");
  8771. sleep(5);
  8772. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8773. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8774. pthread_exit(NULL);
  8775. }
  8776. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8777. {
  8778. mtrace();
  8779. int result = FAIL;
  8780. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8781. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8782. {
  8783. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8784. locallistVersion = -1;
  8785. }
  8786. else
  8787. {
  8788. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8789. OCPP_getListVerion();
  8790. }
  8791. //from db.OCPP_getListVerion
  8792. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8793. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  8794. sendGetLocalListVersionConfirmation(uuid,"");
  8795. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  8796. return result;
  8797. }
  8798. int handleRemoteStartRequest(char *uuid, char *payload)
  8799. {
  8800. mtrace();
  8801. int result = FAIL;
  8802. int connectorIdInt=-1;
  8803. int tempIndex = 0;
  8804. int connectorIdIsNULL, chargingProfileIsNULL;
  8805. char comfirmstr[20]={0};
  8806. char cmdBuf[512];
  8807. json_object *RemoteStartTransaction;
  8808. FILE *fp;
  8809. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8810. if(server_pending == TRUE)
  8811. {
  8812. return 0;
  8813. }
  8814. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8815. RemoteStartTransaction = json_tokener_parse(payload);
  8816. if(!is_error(RemoteStartTransaction))
  8817. {
  8818. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8819. {
  8820. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8821. }
  8822. else
  8823. {
  8824. connectorIdIsNULL = TRUE;
  8825. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  8826. {
  8827. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  8828. {
  8829. connectorIdIsNULL = FALSE;
  8830. connectorIdInt = (gun_index+1);
  8831. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  8832. break;
  8833. }
  8834. }
  8835. }
  8836. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt != -1))
  8837. {
  8838. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8839. // Required data
  8840. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8841. // Optional data
  8842. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8843. {
  8844. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8845. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8846. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8847. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8848. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8849. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8850. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8851. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8852. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8853. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8854. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8855. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8856. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8857. {
  8858. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  8859. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8860. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  8861. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8862. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  8863. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8864. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  8865. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8866. {
  8867. 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++)
  8868. {
  8869. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  8870. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  8871. 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)
  8872. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  8873. }
  8874. }
  8875. }
  8876. }
  8877. else
  8878. {
  8879. chargingProfileIsNULL = TRUE;
  8880. }
  8881. }
  8882. }
  8883. else
  8884. {
  8885. connectorIdIsNULL = TRUE;
  8886. }
  8887. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8888. {
  8889. DEBUG_WARN("Connector id is NULL\n.");
  8890. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8891. goto end;
  8892. }
  8893. /*
  8894. enum _SYSTEM_STATUS
  8895. {
  8896. S_BOOTING = 0,
  8897. S_IDLE, = 1
  8898. S_AUTHORIZING, = 2
  8899. S_REASSIGN_CHECK, = 3
  8900. S_REASSIGN, = 4
  8901. S_PRECHARGE, = 5
  8902. S_PREPARING_FOR_EV, = 6
  8903. S_PREPARING_FOR_EVSE, = 7
  8904. S_CHARGING, = 8
  8905. S_TERMINATING, = 9
  8906. S_COMPLETE, = 10
  8907. S_ALARM, = 11
  8908. S_FAULT = 12
  8909. }
  8910. */
  8911. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8912. {
  8913. //check Transaction active
  8914. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8915. {
  8916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8917. {
  8918. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8919. }
  8920. else
  8921. {
  8922. tempIndex = connectorIdInt -1;
  8923. }
  8924. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8925. {
  8926. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8927. {
  8928. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8929. {
  8930. //Reserved
  8931. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8932. }
  8933. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8934. {
  8935. //Reserved
  8936. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8937. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8938. goto end;
  8939. }
  8940. else
  8941. {
  8942. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8943. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8944. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8945. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8946. {
  8947. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8948. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8949. goto end;
  8950. }
  8951. }//END FOR ELSE
  8952. }
  8953. }// END FOR CHAdeMO_QUANTITY
  8954. }
  8955. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8956. {
  8957. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8958. {
  8959. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8960. }
  8961. else
  8962. {
  8963. tempIndex = connectorIdInt -1;
  8964. }
  8965. for (int index = 0; index < CCS_QUANTITY; index++)
  8966. {
  8967. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8968. {
  8969. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  8970. {
  8971. //Reserved
  8972. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8973. }
  8974. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  8975. {
  8976. //Reserved
  8977. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8978. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8979. goto end;
  8980. }
  8981. else
  8982. {
  8983. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8984. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8985. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8986. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8987. {
  8988. DEBUG_WARN("CCS connector not allow start\n.");
  8989. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8990. goto end;
  8991. }
  8992. }// END FOR ELSE
  8993. }
  8994. }// END FOR CCS_QUANTITY
  8995. }
  8996. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8997. {
  8998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8999. {
  9000. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9001. }
  9002. else
  9003. {
  9004. tempIndex = connectorIdInt -1;
  9005. }
  9006. for (int index = 0; index < GB_QUANTITY; index++)
  9007. {
  9008. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9009. {
  9010. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9011. {
  9012. //Reserved
  9013. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9014. }
  9015. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9016. {
  9017. //Reserved
  9018. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9019. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9020. goto end;
  9021. }
  9022. else
  9023. {
  9024. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9025. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9026. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9027. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9028. {
  9029. DEBUG_WARN("GB connector not allow start\n.");
  9030. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9031. goto end;
  9032. }
  9033. }// END FOR ELSE
  9034. }
  9035. } // END FOR GB_QUANTITY
  9036. }
  9037. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9038. {
  9039. tempIndex = connectorIdInt -1;
  9040. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9041. {
  9042. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9043. {
  9044. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9045. {
  9046. //Reserved
  9047. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9048. }
  9049. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9050. {
  9051. //Reserved
  9052. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9053. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9054. goto end;
  9055. }
  9056. else
  9057. {
  9058. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9059. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9060. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9061. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9062. {
  9063. DEBUG_WARN("GB connector not allow start\n.");
  9064. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9065. goto end;
  9066. }
  9067. }// END FOR ELSE
  9068. }
  9069. } // END FOR GB_QUANTITY
  9070. }
  9071. else
  9072. {
  9073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9074. {
  9075. tempIndex = 2;
  9076. }
  9077. else
  9078. {
  9079. tempIndex = connectorIdInt -1;
  9080. }
  9081. for (int index = 0; index < AC_QUANTITY; index++)
  9082. {
  9083. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9084. {
  9085. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  9086. {
  9087. //Reserved
  9088. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9089. }
  9090. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16DataPH->ReserveNow[index].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  9091. {
  9092. //Reserved
  9093. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9094. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9095. goto end;
  9096. }
  9097. else
  9098. {
  9099. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9100. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9101. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9102. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9103. {
  9104. DEBUG_WARN("AC connector not allow start\n.");
  9105. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9106. goto end;
  9107. }
  9108. }//END FOR ELSE
  9109. }
  9110. }// END FOR AC_QUANTITY
  9111. }
  9112. if(chargingProfileIsNULL == FALSE)
  9113. {
  9114. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9115. {
  9116. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9117. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9118. //memset idTag
  9119. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9120. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9121. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9122. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9123. // Save profile to file
  9124. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9125. system(cmdBuf);
  9126. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9127. fp = fopen(cmdBuf, "w");
  9128. 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));
  9129. fclose(fp);
  9130. }
  9131. else
  9132. {
  9133. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9134. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9135. }
  9136. }
  9137. else
  9138. {
  9139. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9140. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9141. //memset idTag
  9142. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9143. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9144. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9145. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9146. }
  9147. }
  9148. else
  9149. {
  9150. DEBUG_WARN("Connector id over\n.");
  9151. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9152. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9153. }
  9154. end:
  9155. json_object_put(RemoteStartTransaction);
  9156. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9157. {
  9158. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9159. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9160. }
  9161. //OCPP send RemoteStartConfirmation by first.
  9162. sendRemoteStartConfirmation(uuid, comfirmstr);
  9163. return result;
  9164. }
  9165. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9166. {
  9167. mtrace();
  9168. int result = FAIL;
  9169. int match = FALSE;
  9170. int GunNO = 0;
  9171. int tempIndex = 0;
  9172. int transactionIdInt=0;
  9173. int transactionIdIsNULL= TRUE;
  9174. char comfirmstr[20];
  9175. json_object *RemoteStopTransaction;
  9176. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9177. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9178. if(server_pending == TRUE)
  9179. {
  9180. return 0;
  9181. }
  9182. RemoteStopTransaction = json_tokener_parse(payload);
  9183. if(!is_error(RemoteStopTransaction))
  9184. {
  9185. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9186. {
  9187. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9188. transactionIdIsNULL = FALSE;
  9189. }
  9190. }
  9191. json_object_put(RemoteStopTransaction);
  9192. if(transactionIdIsNULL == FALSE)
  9193. {
  9194. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9195. {
  9196. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9197. {
  9198. //check Transaction active
  9199. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9200. {
  9201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9202. {
  9203. tempIndex = ((gun_index==2) ? 1: 0);
  9204. }
  9205. else
  9206. {
  9207. tempIndex = gun_index;
  9208. }
  9209. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9210. {
  9211. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9212. {
  9213. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9214. {
  9215. match = TRUE;
  9216. GunNO = gun_index;
  9217. }
  9218. }
  9219. }// END FOR CHAdeMO_QUANTITY
  9220. }
  9221. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9222. {
  9223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9224. {
  9225. tempIndex = ((gun_index==2) ? 1: 0);
  9226. }
  9227. else
  9228. {
  9229. tempIndex = gun_index;
  9230. }
  9231. for (int index = 0; index < CCS_QUANTITY; index++)
  9232. {
  9233. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9234. {
  9235. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9236. {
  9237. match = TRUE;
  9238. GunNO = gun_index;
  9239. }
  9240. }
  9241. }// END FOR CCS_QUANTITY
  9242. }
  9243. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9244. {
  9245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9246. {
  9247. tempIndex = ((gun_index==2) ? 1: 0);
  9248. }
  9249. else
  9250. {
  9251. tempIndex = gun_index;
  9252. }
  9253. for (int index = 0; index < GB_QUANTITY; index++)
  9254. {
  9255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9256. {
  9257. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9258. {
  9259. match = TRUE;
  9260. GunNO = gun_index;
  9261. }
  9262. }
  9263. }// END FOR GB_QUANTITY
  9264. }
  9265. else if(gunType[gun_index] == GUN_TYPE_DO)
  9266. {
  9267. tempIndex = gun_index;
  9268. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9269. {
  9270. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9271. {
  9272. 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
  9273. {
  9274. match = TRUE;
  9275. GunNO = gun_index;
  9276. }
  9277. }
  9278. }// END FOR GB_QUANTITY
  9279. }
  9280. else
  9281. {
  9282. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9283. {
  9284. tempIndex = 2;
  9285. }
  9286. else
  9287. {
  9288. tempIndex = gun_index;
  9289. }
  9290. for (int index = 0; index < AC_QUANTITY; index++)
  9291. {
  9292. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9293. {
  9294. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9295. {
  9296. match = TRUE;
  9297. GunNO = gun_index;
  9298. }
  9299. }
  9300. }// END FOR CHAdeMO_QUANTITY
  9301. } // END FOR AC ELSE
  9302. }// CHECK IF ResponseTransactionId == transactionIdInt
  9303. }//END FOR
  9304. if( match == TRUE)
  9305. {
  9306. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9307. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9308. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9309. }
  9310. else
  9311. {
  9312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9313. }
  9314. }
  9315. else
  9316. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9317. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9318. return result;
  9319. }
  9320. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9321. {
  9322. mtrace();
  9323. int result = FAIL;
  9324. int connectorIdInt=0, reservationIdInt=0;
  9325. int tempIndex = 0;
  9326. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9327. char comfirmstr[20]={0};
  9328. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9329. int c = 0;
  9330. char *loc;
  9331. //char *ptr;
  9332. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9333. strcpy(sstrtemp, stringtrimspace(payload));
  9334. //***(1)connectorId ****/
  9335. c=0;
  9336. loc = strstr(sstrtemp, "connectorId");
  9337. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9338. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9339. {
  9340. sstr[c] = loc[strlen("connectorId")+2+c];
  9341. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9342. c++;
  9343. }
  9344. sstr[c] = '\0';
  9345. connectorIdInt = atoi(sstr);
  9346. //***(2)expiryDate ****/
  9347. loc = strstr(sstrtemp, "expiryDate");
  9348. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9349. c = 0;
  9350. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9351. {
  9352. sstr[c] = loc[3+strlen("expiryDate")+c];
  9353. c++;
  9354. }
  9355. sstr[c] = '\0';
  9356. strcpy(expiryDatestr, sstr);
  9357. //***(3)idTag ****/
  9358. loc = strstr(sstrtemp, "idTag");
  9359. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9360. c = 0;
  9361. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9362. {
  9363. sstr[c] = loc[3+strlen("idTag")+c];
  9364. c++;
  9365. }
  9366. sstr[c] = '\0';
  9367. strcpy(idTagstr, sstr);
  9368. //***(4)parentIdTag ****/
  9369. loc = strstr(sstrtemp, "parentIdTag");
  9370. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9371. c = 0;
  9372. if(loc == NULL)
  9373. {
  9374. strcpy(parentIdTagstr, "");
  9375. }
  9376. else
  9377. {
  9378. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9379. {
  9380. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9381. c++;
  9382. }
  9383. sstr[c] = '\0';
  9384. strcpy(parentIdTagstr, sstr);
  9385. }
  9386. //***(5)reservationId ****/
  9387. c=0;
  9388. loc = strstr(sstrtemp, "reservationId");
  9389. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9390. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9391. {
  9392. sstr[c] = loc[strlen("reservationId")+2+c];
  9393. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9394. c++;
  9395. }
  9396. sstr[c] = '\0';
  9397. reservationIdInt = atoi(sstr);
  9398. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9399. /*
  9400. enum SYSTEM_STATUS
  9401. {
  9402. SYS_MODE_BOOTING = 0,
  9403. SYS_MODE_IDLE = 1,
  9404. SYS_MODE_AUTHORIZING = 2,
  9405. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9406. SYS_MODE_REASSIGN = 4,
  9407. SYS_MODE_PREPARING = 5,
  9408. SYS_MODE_PREPARE_FOR_EV = 6,
  9409. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9410. SYS_MODE_CHARGING = 8,
  9411. SYS_MODE_TERMINATING = 9,
  9412. SYS_MODE_COMPLETE = 10,
  9413. SYS_MODE_ALARM = 11,
  9414. SYS_MODE_FAULT = 12,
  9415. SYS_MODE_RESERVATION = 13,
  9416. SYS_MODE_BOOKING = 14,
  9417. SYS_MODE_MAINTAIN = 15,
  9418. SYS_MODE_DEBUG = 16,
  9419. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9420. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9421. SYS_MODE_UPDATE = 19
  9422. };
  9423. */
  9424. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9425. {
  9426. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9427. goto end;
  9428. }
  9429. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9430. {
  9431. //check Transaction active
  9432. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  9443. {
  9444. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9445. {
  9446. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9447. {
  9448. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9449. {
  9450. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9451. {
  9452. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9454. }
  9455. 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'))
  9456. {
  9457. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9458. }
  9459. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9460. {
  9461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9462. }
  9463. else
  9464. {
  9465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9466. }
  9467. }
  9468. 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
  9469. {
  9470. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9471. }
  9472. }
  9473. else
  9474. {
  9475. //replace reservation
  9476. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9478. }
  9479. }
  9480. } // END FOR CHAdeMO_QUANTITY
  9481. }
  9482. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9483. {
  9484. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9485. {
  9486. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9487. }
  9488. else
  9489. {
  9490. tempIndex = connectorIdInt -1;
  9491. }
  9492. for (int index = 0; index < CCS_QUANTITY; index++)
  9493. {
  9494. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9495. {
  9496. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9497. {
  9498. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9499. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9500. {
  9501. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9502. {
  9503. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9504. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9505. }
  9506. 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'))
  9507. {
  9508. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9509. }
  9510. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9511. {
  9512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9513. }
  9514. else
  9515. {
  9516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9517. }
  9518. }
  9519. 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
  9520. {
  9521. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9522. }
  9523. }
  9524. else
  9525. {
  9526. //replace reservation
  9527. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9528. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9529. }
  9530. }
  9531. } // END FOR CCS_QUANTITY
  9532. }
  9533. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9534. {
  9535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9536. {
  9537. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9538. }
  9539. else
  9540. {
  9541. tempIndex = connectorIdInt -1;
  9542. }
  9543. for (int index = 0; index < GB_QUANTITY; index++)
  9544. {
  9545. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9546. {
  9547. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9548. {
  9549. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9550. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9551. {
  9552. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9553. {
  9554. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9556. }
  9557. 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'))
  9558. {
  9559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9560. }
  9561. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9562. {
  9563. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9564. }
  9565. else
  9566. {
  9567. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9568. }
  9569. }
  9570. 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
  9571. {
  9572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9573. }
  9574. }
  9575. else
  9576. {
  9577. //replace reservation
  9578. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9579. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9580. }
  9581. }
  9582. }// END FOR GB_QUANTITY
  9583. }
  9584. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9585. {
  9586. tempIndex = connectorIdInt -1;
  9587. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9588. {
  9589. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9590. {
  9591. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9592. {
  9593. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9594. 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
  9595. {
  9596. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9597. {
  9598. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9600. }
  9601. 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'))
  9602. {
  9603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9604. }
  9605. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9606. {
  9607. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9608. }
  9609. else
  9610. {
  9611. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9612. }
  9613. }
  9614. 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
  9615. {
  9616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9617. }
  9618. }
  9619. else
  9620. {
  9621. //replace reservation
  9622. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9624. }
  9625. }
  9626. }// END FOR GB_QUANTITY
  9627. }
  9628. else
  9629. {
  9630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9631. {
  9632. tempIndex = 2;
  9633. }
  9634. else
  9635. {
  9636. tempIndex = (connectorIdInt -1);
  9637. }
  9638. for (int index = 0; index < AC_QUANTITY; index++)
  9639. {
  9640. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9641. {
  9642. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9643. {
  9644. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9645. {
  9646. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9647. {
  9648. 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))
  9649. {
  9650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9651. }
  9652. else
  9653. {
  9654. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9656. }
  9657. }
  9658. 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'))
  9659. {
  9660. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9661. }
  9662. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9663. {
  9664. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9665. }
  9666. else
  9667. {
  9668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9669. }
  9670. }
  9671. 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
  9672. {
  9673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9674. }
  9675. }
  9676. else
  9677. {
  9678. //replace reservation
  9679. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9681. }
  9682. }
  9683. } // END FOR AC_QUANTITY
  9684. }
  9685. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9686. }
  9687. else if(connectorIdInt == 0)
  9688. {
  9689. //check Transaction active
  9690. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9691. {
  9692. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9693. {
  9694. 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'))
  9695. {
  9696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9697. goto end;
  9698. }
  9699. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9700. {
  9701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9702. goto end;
  9703. }
  9704. 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
  9705. {
  9706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9707. goto end;
  9708. }
  9709. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9710. {
  9711. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9712. goto end;
  9713. }
  9714. }
  9715. }// END FOR CHAdeMO_QUANTITY
  9716. for (int index = 0; index < CCS_QUANTITY; index++)
  9717. {
  9718. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9719. {
  9720. 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'))
  9721. {
  9722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9723. goto end;
  9724. }
  9725. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9726. {
  9727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9728. goto end;
  9729. }
  9730. 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
  9731. {
  9732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9733. goto end;
  9734. }
  9735. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9736. {
  9737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9738. goto end;
  9739. }
  9740. }
  9741. } // END FOR CCS_QUANTITY
  9742. for (int index = 0; index < GB_QUANTITY; index++)
  9743. {
  9744. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9745. {
  9746. 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'))
  9747. {
  9748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9749. goto end;
  9750. }
  9751. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9752. {
  9753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9754. goto end;
  9755. }
  9756. 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
  9757. {
  9758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9759. goto end;
  9760. }
  9761. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9762. {
  9763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9764. goto end;
  9765. }
  9766. }
  9767. } // END FOR GB_QUANTITY
  9768. for (int index = 0; index < AC_QUANTITY; index++)
  9769. {
  9770. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9771. {
  9772. 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'))
  9773. {
  9774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9775. goto end;
  9776. }
  9777. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9778. {
  9779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9780. goto end;
  9781. }
  9782. 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
  9783. {
  9784. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9785. goto end;
  9786. }
  9787. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9788. {
  9789. 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))
  9790. {
  9791. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9792. goto end;
  9793. }
  9794. }
  9795. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9796. {
  9797. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9798. goto end;
  9799. }
  9800. }
  9801. }// END FOR AC_QUANTITY
  9802. //The connectorId is 0
  9803. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  9804. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9805. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9806. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  9807. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9808. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  9809. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9810. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  9811. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  9812. result = TRUE;
  9813. return result;
  9814. }
  9815. else
  9816. {
  9817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9818. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9819. }
  9820. if(strcmp(comfirmstr,"Accepted") == 0)
  9821. {
  9822. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9823. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9824. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9825. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9826. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9827. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  9828. result = TRUE;
  9829. return result;
  9830. }
  9831. end:
  9832. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9833. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9834. return result;
  9835. }
  9836. int handleResetRequest(char *uuid, char *payload)
  9837. {
  9838. mtrace();
  9839. int result = FAIL;
  9840. char sstr[10]={0},sstrtemp[30]={ 0 };
  9841. char typestr[10]={0};
  9842. char comfirmstr[20]={0};
  9843. int c = 0;
  9844. char *loc;
  9845. DEBUG_INFO("handleResetRequest...\n");
  9846. strcpy(sstrtemp, stringtrimspace(payload));
  9847. loc = strstr(sstrtemp, "type");
  9848. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9849. c = 0;
  9850. while (loc[3+strlen("type")+c] != '\"')
  9851. {
  9852. sstr[c] = loc[3+strlen("type")+c];
  9853. c++;
  9854. }
  9855. sstr[c] = '\0';
  9856. strcpy(typestr,sstr);
  9857. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  9858. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9859. {
  9860. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  9861. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  9862. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9863. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9864. }
  9865. else
  9866. {
  9867. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9868. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9869. result = PASS;
  9870. }
  9871. sendResetConfirmation(uuid, comfirmstr);
  9872. return result;
  9873. }
  9874. int handleSendLocalListRequest(char *uuid, char *payload)
  9875. {
  9876. mtrace();
  9877. int result = FAIL;
  9878. char comfirmstr[20];
  9879. int checkState_Faulted = FALSE;
  9880. json_object *SendLocalList;
  9881. DEBUG_INFO("handleSendLocalListRequest...\n");
  9882. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9883. {
  9884. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9885. goto end;
  9886. }
  9887. //check Charge Point state
  9888. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9889. {
  9890. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9891. {
  9892. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9893. }
  9894. }
  9895. for (int index = 0; index < CCS_QUANTITY; index++)
  9896. {
  9897. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9898. {
  9899. checkState_Faulted = TRUE; //OCPP Status
  9900. }
  9901. }
  9902. for (int index = 0; index < GB_QUANTITY; index++)
  9903. {
  9904. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9905. {
  9906. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9907. }
  9908. }
  9909. //check Charge Point state
  9910. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9911. {
  9912. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9913. {
  9914. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9915. }
  9916. }
  9917. //check Charge Point state
  9918. for (int index = 0; index < AC_QUANTITY; index++)
  9919. {
  9920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9921. {
  9922. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9923. }
  9924. }
  9925. if(checkState_Faulted == TRUE)
  9926. {
  9927. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9928. goto end;
  9929. }
  9930. // Parsing payload
  9931. SendLocalList = json_tokener_parse(payload);
  9932. if(!is_error(SendLocalList))
  9933. {
  9934. // Required data
  9935. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9936. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9937. // Optional data
  9938. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9939. {
  9940. //Check UpdateType
  9941. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9942. {
  9943. //Local list full update
  9944. DEBUG_INFO("Local list full update.\n");
  9945. OCPP_getListVerion();
  9946. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9947. {
  9948. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9949. goto end;
  9950. }
  9951. OCPP_cleanLocalList();
  9952. }
  9953. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9954. {
  9955. //Local list different update
  9956. DEBUG_INFO("Local list different update.\n");
  9957. OCPP_getListVerion();
  9958. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9959. {
  9960. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9961. goto end;
  9962. }
  9963. }
  9964. else
  9965. {
  9966. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9967. goto end;
  9968. }
  9969. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9970. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9971. {
  9972. sprintf((char*)ShmOCPP16DataPH->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")));
  9973. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9974. {
  9975. sprintf((char*)ShmOCPP16DataPH->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")));
  9976. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9977. sprintf((char*)ShmOCPP16DataPH->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")));
  9978. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9979. sprintf((char*)ShmOCPP16DataPH->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")));
  9980. }
  9981. // Add to db
  9982. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9983. {
  9984. //Local list full update
  9985. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9986. idx,
  9987. ShmOCPP16DataPH->SendLocalList.ListVersion,
  9988. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9989. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9990. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9991. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9992. // update list
  9993. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  9994. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9995. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9996. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9997. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9998. }
  9999. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10000. {
  10001. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10002. idx,
  10003. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10004. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10005. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10006. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10007. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10008. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10009. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  10010. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  10011. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  10012. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  10013. }
  10014. }
  10015. }
  10016. else
  10017. {
  10018. //Check UpdateType
  10019. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10020. {
  10021. //Local list full update
  10022. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10023. OCPP_cleanLocalList();
  10024. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10025. goto end;
  10026. }
  10027. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10028. {
  10029. //Local list different update
  10030. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10031. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10032. goto end;
  10033. }
  10034. }
  10035. result = PASS;
  10036. }
  10037. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10038. end:
  10039. json_object_put(SendLocalList);
  10040. sendSendLocalListConfirmation(uuid, comfirmstr);
  10041. return result;
  10042. }
  10043. #define MAX 200
  10044. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10045. {
  10046. mtrace();
  10047. int result = FAIL;
  10048. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  10049. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  10050. char chargingProfilePurposeStr[30]={0};
  10051. char chargingProfileKindStr[16]={0};
  10052. char recurrencyKindStr[10]={0};
  10053. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  10054. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  10055. int chargingSchedulePeriodCount = 0;
  10056. char comfirmstr[20]={0};
  10057. int meet= FALSE;
  10058. FILE *fptr1;
  10059. char filename[MAX]={0};
  10060. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  10061. char rmFileCmd[50]={0};
  10062. char tempchargingProfilePurposeStr[30]={0};
  10063. char word[1600]={0};
  10064. int n_chargingProfile = 0;
  10065. json_object *SetChargingProfile;
  10066. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10067. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  10068. SetChargingProfile = json_tokener_parse(payload);
  10069. if(!is_error(SetChargingProfile))
  10070. {
  10071. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10072. {
  10073. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10074. if(connectorIdInt == 0)
  10075. {
  10076. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  10077. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  10078. }
  10079. else
  10080. {
  10081. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  10082. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  10083. }
  10084. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  10085. }
  10086. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10087. {
  10088. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10089. {
  10090. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10091. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10092. {
  10093. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10094. }
  10095. else
  10096. {
  10097. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  10098. }
  10099. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  10100. }
  10101. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10102. {
  10103. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10104. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10105. {
  10106. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  10107. }
  10108. else
  10109. {
  10110. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  10111. }
  10112. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  10113. }
  10114. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10115. {
  10116. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10117. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10118. {
  10119. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10120. }
  10121. else
  10122. {
  10123. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  10124. }
  10125. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  10126. }
  10127. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10128. {
  10129. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10130. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10131. {
  10132. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10133. }
  10134. else
  10135. {
  10136. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  10137. }
  10138. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  10139. }
  10140. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10141. {
  10142. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10143. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10144. {
  10145. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  10146. }
  10147. else
  10148. {
  10149. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  10150. }
  10151. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  10152. }
  10153. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10154. {
  10155. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10156. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10157. {
  10158. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10159. }
  10160. else
  10161. {
  10162. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  10163. }
  10164. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  10165. }
  10166. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10167. {
  10168. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10169. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10170. {
  10171. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  10172. }
  10173. else
  10174. {
  10175. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  10176. }
  10177. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  10178. }
  10179. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10180. {
  10181. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10182. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10183. {
  10184. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  10185. }
  10186. else
  10187. {
  10188. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  10189. }
  10190. //DEBUG_INFO("validToStr: %s\n", validToStr);
  10191. }
  10192. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10193. {
  10194. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10195. {
  10196. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10197. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10198. {
  10199. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10200. }
  10201. else
  10202. {
  10203. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  10204. }
  10205. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  10206. }
  10207. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10208. {
  10209. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10210. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10211. {
  10212. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10213. }
  10214. else
  10215. {
  10216. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  10217. }
  10218. //DEBUG_INFO("durationInt: %d\n", durationInt);
  10219. }
  10220. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10221. {
  10222. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10223. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10224. {
  10225. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10226. }
  10227. else
  10228. {
  10229. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  10230. }
  10231. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  10232. }
  10233. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10234. {
  10235. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10236. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10237. {
  10238. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10239. }
  10240. else
  10241. {
  10242. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  10243. }
  10244. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  10245. }
  10246. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10247. {
  10248. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10249. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  10250. if(chargingSchedulePeriodCount <= 10)
  10251. {
  10252. 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++)
  10253. {
  10254. 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)
  10255. {
  10256. 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"));
  10257. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10258. {
  10259. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10260. }
  10261. else
  10262. {
  10263. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  10264. }
  10265. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  10266. }
  10267. 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)
  10268. {
  10269. 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"));
  10270. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10271. {
  10272. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10273. }
  10274. else
  10275. {
  10276. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  10277. }
  10278. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  10279. }
  10280. 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)
  10281. {
  10282. 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"));
  10283. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  10284. {
  10285. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10286. }
  10287. else
  10288. {
  10289. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  10290. }
  10291. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  10292. }
  10293. }
  10294. }
  10295. }
  10296. }
  10297. }
  10298. }
  10299. json_object_put(SetChargingProfile);
  10300. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10301. {
  10302. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10303. goto end;
  10304. }
  10305. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10306. {
  10307. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  10308. if(connectorIdInt != 0)
  10309. {
  10310. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10311. goto end;
  10312. }
  10313. strcpy(filename, ChargePointMaxProfile_JSON );
  10314. fptr1 = fopen(filename, "r");
  10315. if (!fptr1)
  10316. {
  10317. //file not exist
  10318. DEBUG_INFO("Unable to open the input file!!\n");
  10319. fptr1 = fopen(filename, "w+");
  10320. }
  10321. else
  10322. {
  10323. //Check Charging Profile Count
  10324. while(fscanf(fptr1, "%s", word) != EOF)
  10325. {
  10326. //DEBUG_INFO("word=%s\n",word);
  10327. if(strstr(word, "chargingProfileId")!= NULL)
  10328. {
  10329. //DEBUG_INFO("test chargingProfileId \n");
  10330. n_chargingProfile = n_chargingProfile + 1;
  10331. //DEBUG_INFO("chargingProfileId Found\n");
  10332. }
  10333. }
  10334. }
  10335. fclose(fptr1);
  10336. }
  10337. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10338. {
  10339. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  10340. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10341. {
  10342. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10343. goto end;
  10344. }
  10345. memset(filename, 0, ARRAY_SIZE(filename));
  10346. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  10347. fptr1 = fopen(filename, "r");
  10348. if (!fptr1)
  10349. {
  10350. //file not exist
  10351. //DEBUG_INFO("Unable to open the input file!!\n");
  10352. fptr1 = fopen(filename, "w+");
  10353. }
  10354. else
  10355. {
  10356. //Check Charging Profile Count
  10357. while(fscanf(fptr1, "%s", word) != EOF)
  10358. {
  10359. //DEBUG_INFO("word=%s\n",word);
  10360. if(strstr(word, "chargingProfileId")!= NULL)
  10361. {
  10362. //DEBUG_INFO("test chargingProfileId \n");
  10363. n_chargingProfile = n_chargingProfile + 1;
  10364. //DEBUG_INFO("chargingProfileId Found\n");
  10365. }
  10366. }
  10367. }
  10368. fclose(fptr1);
  10369. }
  10370. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10371. {
  10372. //printf("set chargingProfile 1-4\n");
  10373. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  10374. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10375. if(connectorIdInt == 0)
  10376. {
  10377. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10378. goto end;
  10379. }
  10380. int tempIndex = 0;
  10381. //check Transaction active
  10382. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  10383. {
  10384. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10385. {
  10386. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10387. }
  10388. else
  10389. {
  10390. tempIndex = connectorIdInt -1;
  10391. }
  10392. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10393. {
  10394. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10395. {
  10396. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10397. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10398. {
  10399. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10400. {
  10401. meet = TRUE;
  10402. break;
  10403. }
  10404. }
  10405. }
  10406. }
  10407. }
  10408. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  10409. {
  10410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10411. {
  10412. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10413. }
  10414. else
  10415. {
  10416. tempIndex = connectorIdInt -1;
  10417. }
  10418. for (int index = 0; index < CCS_QUANTITY; index++)
  10419. {
  10420. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10421. {
  10422. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10423. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10424. {
  10425. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10426. {
  10427. meet = TRUE;
  10428. break;
  10429. }
  10430. }
  10431. }
  10432. }
  10433. }
  10434. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  10435. {
  10436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10437. {
  10438. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10439. }
  10440. else
  10441. {
  10442. tempIndex = connectorIdInt -1;
  10443. }
  10444. for (int index = 0; index < GB_QUANTITY; index++)
  10445. {
  10446. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10447. {
  10448. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10449. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10450. {
  10451. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10452. {
  10453. meet = TRUE;
  10454. break;
  10455. }
  10456. }
  10457. }
  10458. }
  10459. }
  10460. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  10461. {
  10462. tempIndex = connectorIdInt -1;
  10463. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10464. {
  10465. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10466. {
  10467. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10468. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10469. {
  10470. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10471. {
  10472. meet = TRUE;
  10473. break;
  10474. }
  10475. }
  10476. }
  10477. }
  10478. }
  10479. else
  10480. {
  10481. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10482. {
  10483. tempIndex = 2;
  10484. }
  10485. else
  10486. {
  10487. tempIndex = (connectorIdInt -1);
  10488. }
  10489. for (int index = 0; index < AC_QUANTITY; index++)
  10490. {
  10491. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10492. {
  10493. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10494. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10495. {
  10496. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  10497. {
  10498. meet = TRUE;
  10499. break;
  10500. }
  10501. }
  10502. }
  10503. }
  10504. }
  10505. //check Transaction active
  10506. if(meet == FALSE)
  10507. {
  10508. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10509. goto end;
  10510. }
  10511. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10512. {
  10513. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10514. goto end;
  10515. }
  10516. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10517. fptr1 = fopen(filename, "r");
  10518. if (!fptr1)
  10519. {
  10520. //file not exist
  10521. DEBUG_INFO("Unable to open the input file!!\n");
  10522. fptr1 = fopen(filename, "w+");
  10523. }
  10524. else
  10525. {
  10526. //Check Charging Profile Count
  10527. while(fscanf(fptr1, "%s", word) != EOF)
  10528. {
  10529. //DEBUG_INFO("word=%s\n",word);
  10530. if(strstr(word, "chargingProfileId")!= NULL)
  10531. {
  10532. //DEBUG_INFO("test chargingProfileId \n");
  10533. n_chargingProfile = n_chargingProfile + 1;
  10534. //DEBUG_INFO("chargingProfileId Found\n");
  10535. }
  10536. }
  10537. }
  10538. fclose(fptr1);
  10539. }
  10540. // Check ChargeProfileMaxStackLevel
  10541. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10542. {
  10543. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10544. goto end;
  10545. }
  10546. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10547. {
  10548. int i = 0;
  10549. char fnametemp[200]={0};
  10550. n_chargingProfile = 0;
  10551. //Check ChargePointMaxProfile.json exit
  10552. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  10553. {
  10554. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  10555. //Check Charging Profile Count
  10556. while(fscanf(fptr1, "%s", word) != EOF)
  10557. {
  10558. //DEBUG_INFO("word=%s\n",word);
  10559. if(strstr(word, "chargingProfileId")!= NULL)
  10560. {
  10561. //DEBUG_INFO("test chargingProfileId \n");
  10562. n_chargingProfile = n_chargingProfile + 1;
  10563. i = i + 1;
  10564. //DEBUG_INFO("chargingProfileId Found\n");
  10565. }
  10566. memset(word, 0, ARRAY_SIZE(word));
  10567. }
  10568. fclose(fptr1);
  10569. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10570. }
  10571. //Check TxDefaultProfile_0.json exit
  10572. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  10573. {
  10574. i = 0;
  10575. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  10576. //Check Charging Profile Count
  10577. while(fscanf(fptr1, "%s", word) != EOF)
  10578. {
  10579. //DEBUG_INFO("word=%s\n",word);
  10580. if(strstr(word, "chargingProfileId")!= NULL)
  10581. {
  10582. //DEBUG_INFO("test chargingProfileId \n");
  10583. n_chargingProfile = n_chargingProfile + 1;
  10584. i = i + 1;
  10585. //DEBUG_INFO("chargingProfileId Found\n");
  10586. }
  10587. memset(word, 0, ARRAY_SIZE(word));
  10588. }
  10589. fclose(fptr1);
  10590. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10591. }
  10592. //Check TxDefaultProfile_%d.json
  10593. for(int j=1; j <= gunTotalNumber; j++)
  10594. {
  10595. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10596. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  10597. if((access(fnametemp,F_OK))!=-1)
  10598. {
  10599. i = 0;
  10600. fptr1 = fopen(fnametemp, "r");
  10601. //Check Charging Profile Count
  10602. while(fscanf(fptr1, "%s", word) != EOF)
  10603. {
  10604. //DEBUG_INFO("word=%s\n",word);
  10605. if(strstr(word, "chargingProfileId")!= NULL)
  10606. {
  10607. //DEBUG_INFO("test chargingProfileId \n");
  10608. n_chargingProfile = n_chargingProfile + 1;
  10609. i = i + 1;
  10610. //DEBUG_INFO("chargingProfileId Found\n");
  10611. }
  10612. memset(word, 0, ARRAY_SIZE(word));
  10613. }
  10614. fclose(fptr1);
  10615. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10616. }
  10617. }
  10618. //Check TxProfile_%d.json
  10619. for(int j=1; j <= gunTotalNumber; j++)
  10620. {
  10621. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10622. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10623. if((access(fnametemp,F_OK))!=-1)
  10624. {
  10625. i = 0;
  10626. fptr1 = fopen(fnametemp, "r");
  10627. //Check Charging Profile Count
  10628. while(fscanf(fptr1, "%s", word) != EOF)
  10629. {
  10630. //DEBUG_INFO("word=%s\n",word);
  10631. if(strstr(word, "chargingProfileId")!= NULL)
  10632. {
  10633. //DEBUG_INFO("test chargingProfileId \n");
  10634. n_chargingProfile = n_chargingProfile + 1;
  10635. i = i + 1;
  10636. //DEBUG_INFO("chargingProfileId Found\n");
  10637. }
  10638. memset(word, 0, ARRAY_SIZE(word));
  10639. }
  10640. fclose(fptr1);
  10641. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10642. }
  10643. }
  10644. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10645. {
  10646. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10647. goto end;
  10648. }
  10649. }
  10650. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10651. //**********************************Write to File********************************************************/
  10652. FILE *infile;
  10653. FILE *outfile;
  10654. infile = fopen (filename, "r");
  10655. outfile = fopen (tempfile, "w");
  10656. int d =0;
  10657. d = fgetc(infile);
  10658. rewind(infile);
  10659. if(d == EOF)
  10660. {
  10661. // Profile is empty
  10662. fprintf(outfile,"%s\n",payload);
  10663. fclose(infile);
  10664. fclose(outfile);
  10665. sprintf(rmFileCmd,"rm -f %s",filename);
  10666. system(rmFileCmd);
  10667. rename(tempfile, filename);
  10668. }
  10669. else
  10670. {
  10671. // Profile is not empty
  10672. char buf[2048]={0};
  10673. int ChargingProfileAdded = FALSE;
  10674. while (fgets(buf, sizeof(buf), infile) != NULL)
  10675. {
  10676. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10677. json_object *tmpChargingProfile;
  10678. tmpChargingProfile = json_tokener_parse(buf);
  10679. if(!is_error(SetChargingProfile))
  10680. {
  10681. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10682. {
  10683. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10684. }
  10685. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10686. {
  10687. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10688. {
  10689. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10690. }
  10691. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10692. {
  10693. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10694. }
  10695. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10696. {
  10697. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10698. }
  10699. }
  10700. }
  10701. json_object_put(tmpChargingProfile);
  10702. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10703. {
  10704. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10705. {
  10706. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10707. if(ChargingProfileAdded == FALSE)
  10708. {
  10709. fprintf(outfile,"%s\n",payload);
  10710. ChargingProfileAdded = TRUE;
  10711. }
  10712. }
  10713. else
  10714. {
  10715. if(tempstackLevelInt < stackLevelInt)
  10716. {
  10717. if(ChargingProfileAdded == FALSE)
  10718. {
  10719. fprintf(outfile,"%s\n",buf);
  10720. fprintf(outfile,"%s\n",payload);
  10721. ChargingProfileAdded = TRUE;
  10722. }
  10723. else
  10724. {
  10725. fprintf(outfile,"%s\n",buf);
  10726. }
  10727. }
  10728. else
  10729. {
  10730. if(ChargingProfileAdded == FALSE)
  10731. {
  10732. fprintf(outfile,"%s\n",buf);
  10733. fprintf(outfile,"%s\n",payload);
  10734. ChargingProfileAdded = TRUE;
  10735. }
  10736. else
  10737. {
  10738. fprintf(outfile,"%s\n",buf);
  10739. }
  10740. }
  10741. }
  10742. }
  10743. else
  10744. {
  10745. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10746. {
  10747. if(ChargingProfileAdded == FALSE)
  10748. {
  10749. fprintf(outfile,"%s\n",buf);
  10750. fprintf(outfile,"%s\n",payload);
  10751. ChargingProfileAdded = TRUE;
  10752. }
  10753. else
  10754. {
  10755. fprintf(outfile,"%s\n",buf);
  10756. }
  10757. }
  10758. else if(tempstackLevelInt < stackLevelInt)
  10759. {
  10760. if(ChargingProfileAdded == FALSE)
  10761. {
  10762. fprintf(outfile,"%s\n",buf);
  10763. fprintf(outfile,"%s\n",payload);
  10764. ChargingProfileAdded = TRUE;
  10765. }
  10766. else
  10767. {
  10768. fprintf(outfile,"%s\n",buf);
  10769. }
  10770. }
  10771. else
  10772. {
  10773. if(ChargingProfileAdded == FALSE)
  10774. {
  10775. fprintf(outfile,"%s\n",buf);
  10776. fprintf(outfile,"%s\n",payload);
  10777. ChargingProfileAdded = TRUE;
  10778. }
  10779. else
  10780. {
  10781. fprintf(outfile,"%s\n",buf);
  10782. }
  10783. }
  10784. }
  10785. } // end of while loop
  10786. fclose(infile);
  10787. fclose(outfile);
  10788. sprintf(rmFileCmd,"rm -f %s",filename);
  10789. system(rmFileCmd);
  10790. rename(tempfile, filename);
  10791. }
  10792. sleep(1);
  10793. result = TRUE;
  10794. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10795. end:
  10796. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10797. {
  10798. if(connectorIdInt == 0)
  10799. {
  10800. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10801. {
  10802. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10803. }
  10804. }
  10805. else
  10806. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  10807. }
  10808. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10809. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10810. return result;
  10811. }
  10812. int handleTriggerMessageRequest(char *uuid, char *payload)
  10813. {
  10814. mtrace();
  10815. int result = FAIL;
  10816. int connectorIdIsNULL = FALSE;
  10817. int connectorIdInt =0;
  10818. char sstr[40]={0},sstrtemp[100]={ 0 };
  10819. char requestedMessagestr[40]={0};
  10820. char comfirmstr[20]={0};
  10821. int c = 0;
  10822. char *loc;
  10823. DEBUG_INFO("handleTriggerMessageRequest\n");
  10824. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10825. strcpy(sstrtemp, stringtrimspace(payload));
  10826. c = 0;
  10827. loc = strstr(sstrtemp, "requestedMessage");
  10828. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10829. {
  10830. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10831. c++;
  10832. }
  10833. sstr[c] = '\0';
  10834. strcpy(requestedMessagestr, sstr);
  10835. c = 0;
  10836. loc = strstr(sstrtemp, "connectorId");
  10837. if(loc == NULL)
  10838. {
  10839. connectorIdIsNULL = TRUE;
  10840. }
  10841. else
  10842. {
  10843. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10844. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10845. {
  10846. sstr[c] = loc[strlen("connectorId")+2+c];
  10847. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10848. c++;
  10849. }
  10850. sstr[c] = '\0';
  10851. connectorIdInt = atoi(sstr);
  10852. }
  10853. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10854. {
  10855. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10856. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10857. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10858. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10859. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10860. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10861. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10862. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10863. {
  10864. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10865. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10866. return TRUE;
  10867. }
  10868. else
  10869. {
  10870. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10871. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10872. }
  10873. }
  10874. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10875. {
  10876. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10877. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10878. return TRUE;
  10879. }
  10880. //==========================
  10881. // Trigger message
  10882. //==========================
  10883. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10884. {
  10885. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10886. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10887. {
  10888. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10889. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10890. }
  10891. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10892. }
  10893. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10894. {
  10895. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  10896. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10897. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10898. }
  10899. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10900. {
  10901. //sendBootNotificationRequest();
  10902. server_sign = FALSE;
  10903. }
  10904. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10905. {
  10906. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10907. }
  10908. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10909. {
  10910. if(connectorIdIsNULL == FALSE)
  10911. {
  10912. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10913. {
  10914. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10915. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10916. }
  10917. }
  10918. else
  10919. {
  10920. for(int idx=0;idx< gunTotalNumber;idx++)
  10921. {
  10922. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10923. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10924. }
  10925. }
  10926. }
  10927. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10928. {
  10929. if(connectorIdIsNULL == FALSE)
  10930. {
  10931. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10932. {
  10933. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10934. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  10935. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10936. }
  10937. }
  10938. else
  10939. {
  10940. for(int idx=0;idx< gunTotalNumber;idx++)
  10941. {
  10942. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  10943. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10944. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10945. }
  10946. }
  10947. }
  10948. return result;
  10949. }
  10950. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10951. {
  10952. mtrace();
  10953. int result = FAIL;
  10954. int connectorIdInt =0;
  10955. char comfirmstr[20]={0};
  10956. int tempIndex = 0;
  10957. json_object *UnlockConnector;
  10958. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10959. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10960. UnlockConnector = json_tokener_parse(payload);
  10961. if(!is_error(UnlockConnector))
  10962. {
  10963. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10964. {
  10965. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10966. }
  10967. }
  10968. json_object_put(UnlockConnector);
  10969. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10970. if(gunTotalNumber == 0)
  10971. {
  10972. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10973. goto end;
  10974. }
  10975. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10976. {
  10977. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10978. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10979. goto end;
  10980. }
  10981. else
  10982. {
  10983. //check Transaction active
  10984. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10985. {
  10986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10987. {
  10988. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10989. }
  10990. else
  10991. {
  10992. tempIndex = connectorIdInt -1;
  10993. }
  10994. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10995. {
  10996. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10997. {
  10998. //stop Transaction
  10999. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11000. }
  11001. }
  11002. }
  11003. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11004. {
  11005. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11006. {
  11007. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11008. }
  11009. else
  11010. {
  11011. tempIndex = connectorIdInt -1;
  11012. }
  11013. for (int index = 0; index < CCS_QUANTITY; index++)
  11014. {
  11015. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11016. {
  11017. //stop Transaction
  11018. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11019. }
  11020. }
  11021. }
  11022. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11023. {
  11024. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11025. {
  11026. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11027. }
  11028. else
  11029. {
  11030. tempIndex = connectorIdInt -1;
  11031. }
  11032. for (int index = 0; index < GB_QUANTITY; index++)
  11033. {
  11034. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11035. {
  11036. //stop Transaction
  11037. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11038. }
  11039. }
  11040. }
  11041. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11042. {
  11043. tempIndex = connectorIdInt -1;
  11044. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11045. {
  11046. 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)))
  11047. {
  11048. //stop Transaction
  11049. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11050. }
  11051. }
  11052. }
  11053. else
  11054. {
  11055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11056. {
  11057. tempIndex = 2;
  11058. }
  11059. else
  11060. {
  11061. tempIndex = connectorIdInt-1;
  11062. }
  11063. for (int index = 0; index < AC_QUANTITY; index++)
  11064. {
  11065. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11066. {
  11067. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11068. }
  11069. }
  11070. }
  11071. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11072. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  11073. result = TRUE;
  11074. return result;
  11075. }
  11076. end:
  11077. //json_object_put(obj); --- remove temporally
  11078. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11079. return result;
  11080. }
  11081. static char UpdateFirmwarepayloadData[300]={0};
  11082. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11083. {
  11084. mtrace();
  11085. int result = FAIL;
  11086. pthread_t t;
  11087. sendUpdateFirmwareConfirmation(uuid);
  11088. memset(UpdateFirmwarepayloadData, 0, 300);
  11089. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11090. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11091. ////pthread_join(t, NULL); //
  11092. //pthread_detach(t);
  11093. //sendUpdateFirmwareConfirmation(uuid);
  11094. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  11095. return result;
  11096. }
  11097. void *UpdateFirmwareProcess(void *data)
  11098. {
  11099. pthread_detach(pthread_self());
  11100. mtrace();
  11101. int retriesInt =0, retryIntervalInt=0;
  11102. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  11103. int port=0;
  11104. char locationstr[512]={0}, retrieveDatestr[36]={0};
  11105. int isSuccess = 0;
  11106. char ftpbuf[512];
  11107. char temp[100];
  11108. char * pch;
  11109. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11110. json_object *UpdateFirmware;
  11111. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11112. if(!is_error(UpdateFirmware))
  11113. {
  11114. // Required data
  11115. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11116. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11117. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11118. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11119. // Optional data
  11120. if(json_object_object_get(UpdateFirmware, "retries"))
  11121. {
  11122. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11123. }
  11124. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11125. {
  11126. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11127. }
  11128. }
  11129. json_object_put(UpdateFirmware);
  11130. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11131. memset(path, 0, ARRAY_SIZE(path));
  11132. // Wait retrieveData
  11133. if(strlen(retrieveDatestr) > 10)
  11134. {
  11135. do
  11136. {
  11137. sleep(1);
  11138. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11139. }
  11140. // Ready to download
  11141. system("rm -f /mnt/*");
  11142. if(strncmp(locationstr,"http", 4) == 0)
  11143. {
  11144. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11145. sprintf(ftppath,"/%s", path);
  11146. DEBUG_INFO("locationstr: %s\n", locationstr);
  11147. DEBUG_INFO("protocol: %s\n",protocol);
  11148. DEBUG_INFO("host: %s\n",host);
  11149. DEBUG_INFO("path: %s\n",path);
  11150. DEBUG_INFO("ftppath: %s\n",ftppath);
  11151. int ftppathlen=strlen(ftppath);
  11152. int i=1;
  11153. char filenametemp[50];
  11154. while(i < ftppathlen)
  11155. {
  11156. int len=ftppathlen-i;
  11157. if(ftppath[len]== 47) // '/' ascll code: 47
  11158. {
  11159. DEBUG_INFO("compare '/' all right\n");
  11160. break;
  11161. }
  11162. i=i+1;
  11163. }
  11164. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11165. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11166. filenametemp[i+1] = 0;
  11167. do
  11168. {
  11169. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11170. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11171. sleep(1);
  11172. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11173. if(!isSuccess)
  11174. {
  11175. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11176. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11177. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11178. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11179. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11180. }
  11181. else
  11182. {
  11183. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11184. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11185. }
  11186. retriesInt--;
  11187. }while((isSuccess == 0)&&(retriesInt >= 0));
  11188. }
  11189. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11190. {
  11191. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11192. memset(temp, 0, ARRAY_SIZE(temp));
  11193. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11194. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11195. int ftppathlen=strlen(ftpbuf);
  11196. int i=1;
  11197. char filenametemp[50];
  11198. while(i < ftppathlen)
  11199. {
  11200. int len=ftppathlen-i;
  11201. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11202. {
  11203. DEBUG_INFO(" compare '/' all right\n");
  11204. break;
  11205. }
  11206. i=i+1;
  11207. }
  11208. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11209. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11210. filenametemp[i+1] = 0;
  11211. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11212. pch=strchr(temp,'@');
  11213. if(pch==NULL)
  11214. {
  11215. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11216. protocol, host, &port, path);
  11217. strcpy(user,"anonymous");
  11218. strcpy(password,"");
  11219. }
  11220. else
  11221. {
  11222. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11223. protocol, user, password, host, &port, path);
  11224. }
  11225. sscanf(host,"%[^/]%s",host1, path1);
  11226. sprintf(ftppath,"%s", path1);
  11227. //DEBUG_INFO("protocol =%s\n",protocol);
  11228. //DEBUG_INFO("user =%s\n",user);
  11229. //DEBUG_INFO("password =%s\n",password);
  11230. //DEBUG_INFO("host1 =%s\n",host1);
  11231. //DEBUG_INFO("port =%d\n",port);
  11232. //DEBUG_INFO("path1 =%s\n",path1);
  11233. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11234. //ftpFile(host, user, password, port, ftppath, fname);
  11235. //download firmware pthred
  11236. if(port == 0)
  11237. {
  11238. port = 21;
  11239. }
  11240. do
  11241. {
  11242. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11243. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11244. sleep(1);
  11245. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11246. if(!isSuccess)
  11247. {
  11248. //BulldogUtil.sleepMs(interval*1000);
  11249. DEBUG_INFO("Update firmware request and download file fail.\n");
  11250. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11251. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11252. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11253. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11254. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11255. }
  11256. else
  11257. {
  11258. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11259. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11260. }
  11261. retriesInt--;
  11262. }while((!isSuccess)&&(retriesInt >= 0));
  11263. }
  11264. else
  11265. {
  11266. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11267. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11268. sleep(1);
  11269. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11270. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11271. }
  11272. // OCPPPH only, must announce CSU upgrade firmware
  11273. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  11274. pthread_exit(NULL);
  11275. }
  11276. int handleCertificateSignedRequest(char *uuid, char *payload)
  11277. {
  11278. mtrace();
  11279. int result = PASS;
  11280. json_object *CertificateSigned;
  11281. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11282. CertificateSigned = json_tokener_parse(payload);
  11283. if(!is_error(CertificateSigned))
  11284. {
  11285. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11286. }
  11287. json_object_put(CertificateSigned);
  11288. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  11289. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  11290. fclose(fp);
  11291. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11292. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  11293. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  11294. sendCertificateSignedConfirmation(uuid);
  11295. return result;
  11296. }
  11297. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11298. {
  11299. mtrace();
  11300. int result = PASS;
  11301. json_object *DeleteCertificate;
  11302. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11303. DeleteCertificate = json_tokener_parse(payload);
  11304. if(!is_error(DeleteCertificate))
  11305. {
  11306. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11307. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11308. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11309. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11310. }
  11311. json_object_put(DeleteCertificate);
  11312. /*
  11313. * TODO: Delete certificateSigned process
  11314. */
  11315. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  11316. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  11317. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  11318. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  11319. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  11320. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  11321. sendDeleteCertificateConfirmation(uuid);
  11322. return result;
  11323. }
  11324. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11325. {
  11326. mtrace();
  11327. int result = PASS;
  11328. json_object *ExtendedTriggerMessage;
  11329. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11330. ExtendedTriggerMessage = json_tokener_parse(payload);
  11331. if(!is_error(ExtendedTriggerMessage))
  11332. {
  11333. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11334. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11335. {
  11336. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11337. }
  11338. else
  11339. {
  11340. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  11341. }
  11342. }
  11343. json_object_put(ExtendedTriggerMessage);
  11344. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  11345. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  11346. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11347. {
  11348. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11349. }
  11350. else
  11351. {
  11352. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11353. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11354. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11355. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11356. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11357. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11358. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11359. {
  11360. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11361. }
  11362. else
  11363. {
  11364. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11365. }
  11366. }
  11367. sendExtendedTriggerMessageConfirmation(uuid);
  11368. //==========================
  11369. // Trigger message
  11370. //==========================
  11371. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11372. {
  11373. //sendBootNotificationRequest();
  11374. server_sign = FALSE;
  11375. }
  11376. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11377. {
  11378. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  11379. }
  11380. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11381. {
  11382. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11383. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11384. {
  11385. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11386. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11387. }
  11388. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11389. }
  11390. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11391. {
  11392. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11393. }
  11394. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11395. {
  11396. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11397. {
  11398. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11399. }
  11400. else
  11401. {
  11402. for(int idx=0;idx< gunTotalNumber;idx++)
  11403. {
  11404. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11405. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11406. }
  11407. }
  11408. }
  11409. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11410. {
  11411. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  11412. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  11413. {
  11414. system("openssl req -newkey rsa:2048 -out /Storage/OCPP_PH/certCP.csr -nodes -keyout /Storage/OCPP_PH/certCP.key -subj \"/C=TW/ST=Taiwan/L=Taoyuan/O=Phihong Technology/OU=IT/CN=phihong.com\" &");
  11415. }
  11416. }
  11417. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11418. {
  11419. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11420. {
  11421. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11422. }
  11423. else
  11424. {
  11425. for(int idx=0;idx< gunTotalNumber;idx++)
  11426. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11427. }
  11428. }
  11429. return result;
  11430. }
  11431. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11432. {
  11433. mtrace();
  11434. int result = PASS;
  11435. json_object *GetInstalledCertificateIds;
  11436. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11437. GetInstalledCertificateIds = json_tokener_parse(payload);
  11438. if(!is_error(GetInstalledCertificateIds))
  11439. {
  11440. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11441. }
  11442. json_object_put(GetInstalledCertificateIds);
  11443. /*
  11444. * TODO: Return installed certificate process
  11445. */
  11446. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11447. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  11448. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11449. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  11450. sendGetInstalledCertificateIdsConfirmation(uuid);
  11451. return result;
  11452. }
  11453. int handleGetLogRequest(char *uuid, char *payload)
  11454. {
  11455. mtrace();
  11456. int result = PASS;
  11457. json_object *GetLog;
  11458. DEBUG_INFO("handleGetLogRequest...\n");
  11459. GetLog = json_tokener_parse(payload);
  11460. if(!is_error(GetLog))
  11461. {
  11462. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11463. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11464. if(json_object_object_get(GetLog, "retries") != NULL)
  11465. {
  11466. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11467. }
  11468. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11469. {
  11470. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11471. }
  11472. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11473. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11474. {
  11475. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11476. }
  11477. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11478. {
  11479. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11480. }
  11481. }
  11482. json_object_put(GetLog);
  11483. /*
  11484. * TODO: Upload log process
  11485. */
  11486. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  11487. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  11488. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  11489. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  11490. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  11491. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  11492. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  11493. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  11494. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  11495. sendGetLogConfirmation(uuid);
  11496. return result;
  11497. }
  11498. int handleInstallCertificateRequest(char *uuid, char *payload)
  11499. {
  11500. mtrace();
  11501. int result = PASS;
  11502. json_object *InstallCertificate;
  11503. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11504. InstallCertificate = json_tokener_parse(payload);
  11505. if(!is_error(InstallCertificate))
  11506. {
  11507. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11508. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11509. /*
  11510. * TODO: Install certificate process
  11511. */
  11512. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11513. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11514. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11515. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11516. sendInstallCertificateConfirmation(uuid);
  11517. }
  11518. json_object_put(InstallCertificate);
  11519. return result;
  11520. }
  11521. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11522. {
  11523. mtrace();
  11524. int result = PASS;
  11525. json_object *SignedUpdateFirmware;
  11526. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11527. SignedUpdateFirmware = json_tokener_parse(payload);
  11528. if(!is_error(SignedUpdateFirmware))
  11529. {
  11530. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11531. {
  11532. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11533. }
  11534. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11535. {
  11536. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11537. }
  11538. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11539. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11540. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11541. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11542. {
  11543. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11544. }
  11545. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11546. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11547. }
  11548. json_object_put(SignedUpdateFirmware);
  11549. /*
  11550. * TODO: Upgrade firmware process
  11551. */
  11552. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11553. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11554. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11555. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11556. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11557. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11558. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11559. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11560. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11561. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11562. sendInstallCertificateConfirmation(uuid);
  11563. return result;
  11564. }
  11565. int handleUnknownRequest(char *uuid, char *payload)
  11566. {
  11567. mtrace();
  11568. int result = PASS;
  11569. DEBUG_INFO("handleUnknownRequest...\n");
  11570. sendUnknownConfirmation(uuid);
  11571. result = PASS;
  11572. return result;
  11573. }
  11574. //==========================================
  11575. // Handle server response routine
  11576. //==========================================
  11577. void handleAuthorizeResponse(char *payload, int gun_index)
  11578. {
  11579. mtrace();
  11580. char expiryDatestr[30]={0};
  11581. char parentIdTagstr[20]={0};
  11582. char statusstr[20]={0};
  11583. int expiryDateISNULL=FALSE;
  11584. int parentIdTagISNULL=FALSE;
  11585. DEBUG_INFO("handleAuthorizeResponse...\n");
  11586. json_object *Authorize;
  11587. Authorize = json_tokener_parse(payload);
  11588. if(!is_error(Authorize))
  11589. {
  11590. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11591. {
  11592. // Required data
  11593. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11594. // Optional data
  11595. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11596. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11597. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11598. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11599. }
  11600. }
  11601. json_object_put(Authorize);
  11602. if(expiryDateISNULL == FALSE)
  11603. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11604. if(parentIdTagISNULL == FALSE)
  11605. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11606. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11607. //Update idTag information to authorization cache if supproted
  11608. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11609. {
  11610. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11611. }
  11612. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11613. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11614. authorizeRetryTimes = 0;
  11615. }
  11616. void handleBootNotificationResponse(char *payload, int gun_index)
  11617. {
  11618. mtrace();
  11619. char statusStr[12]={0};
  11620. char currentTimeStr[30]={0};
  11621. int intervalInt = 0;
  11622. DEBUG_INFO("handleBootNotificationResponse...\n");
  11623. json_object *BootNotification;
  11624. BootNotification = json_tokener_parse(payload);
  11625. if(!is_error(BootNotification))
  11626. {
  11627. // Required data
  11628. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11629. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11630. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11631. }
  11632. json_object_put(BootNotification);
  11633. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11634. BootNotificationInterval = intervalInt;
  11635. HeartBeatWaitTime = intervalInt;
  11636. //write back to ShmOCPP16DataPH->BootNotification
  11637. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11638. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11639. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11640. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11641. {
  11642. server_sign = TRUE;
  11643. server_pending =FALSE;
  11644. }
  11645. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11646. {
  11647. server_pending = TRUE;
  11648. }
  11649. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11650. srand(time(NULL));
  11651. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11652. SetOcppConnStatus(TRUE);
  11653. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11654. }
  11655. void handleDataTransferResponse(char *payload, int gun_index)
  11656. {
  11657. char sstr[160]={0};//sstr[200]={ 0 };
  11658. int c = 0;
  11659. char *loc;
  11660. DEBUG_INFO("handleDataTransferResponse ...\n");
  11661. loc = strstr(payload, "status");
  11662. c = 0;
  11663. while (loc[3+strlen("status")+c] != '\"')
  11664. {
  11665. sstr[c] = loc[3+strlen("status")+c];
  11666. c++;
  11667. }
  11668. sstr[c] = '\0';
  11669. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11670. }
  11671. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11672. {
  11673. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11674. //struct json_object *obj;
  11675. // obj = json_tokener_parse(payload);
  11676. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11677. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11678. //No fields are defined.
  11679. }
  11680. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11681. {
  11682. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11683. //struct json_object *obj;
  11684. // obj = json_tokener_parse(payload);
  11685. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11686. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11687. //No fields are defined.
  11688. }
  11689. void handleHeartbeatResponse(char *payload, int gun_index)
  11690. {
  11691. mtrace();
  11692. DEBUG_INFO("handleHeartbeatResponse...\n");
  11693. json_object *Heartbeat;
  11694. Heartbeat = json_tokener_parse(payload);
  11695. if(!is_error(Heartbeat))
  11696. {
  11697. // Required data
  11698. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11699. }
  11700. json_object_put(Heartbeat);
  11701. if(FirstHeartBeat == 0)
  11702. {
  11703. FirstHeartBeat = 1;
  11704. DEBUG_INFO("FirstHeartBeat \n");
  11705. }
  11706. HeartBeatWithNOResponse = 0;
  11707. clientTime.Heartbeat=time((time_t*)NULL);
  11708. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11709. }
  11710. void handleMeterValuesResponse(char *payload, int gun_index)
  11711. {
  11712. mtrace();
  11713. DEBUG_INFO("handleMeterValuesResponse...\n");
  11714. }
  11715. void handleStartTransactionResponse(char *payload, int gun_index)
  11716. {
  11717. mtrace();
  11718. //int transactionIdInt = 0;
  11719. FILE *outfile;
  11720. char data[100]={0};
  11721. DEBUG_INFO("handleStartTransactionResponse...\n");
  11722. json_object *StartTransaction;
  11723. StartTransaction = json_tokener_parse(payload);
  11724. if(!is_error(StartTransaction))
  11725. {
  11726. // Required data
  11727. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11728. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11729. // Optional data
  11730. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11731. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11732. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11733. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11734. }
  11735. json_object_put(StartTransaction);
  11736. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11737. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11738. //-----------Start : write to the Queue TransactionId file -----------------//
  11739. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11740. {}
  11741. else
  11742. {
  11743. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11744. if(log == NULL)
  11745. {
  11746. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11747. return ;
  11748. }
  11749. else
  11750. {
  11751. fclose(log);
  11752. }
  11753. }
  11754. // open file for writing
  11755. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11756. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11757. {
  11758. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11759. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11760. fputs(data, outfile);
  11761. fclose (outfile);
  11762. }
  11763. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11764. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11765. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11766. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11767. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11768. }
  11769. void handleStatusNotificationResponse(char *payload, int gun_index)
  11770. {
  11771. mtrace();
  11772. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11773. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11774. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11775. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11776. }
  11777. void handleStopTransactionnResponse(char *payload, int gun_index)
  11778. {
  11779. mtrace();
  11780. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11781. json_object *StopTransaction;
  11782. StopTransaction = json_tokener_parse(payload);
  11783. if(!is_error(StopTransaction))
  11784. {
  11785. // Optional data
  11786. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11787. {
  11788. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11789. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11790. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11791. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11792. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11793. }
  11794. }
  11795. json_object_put(StopTransaction);
  11796. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11797. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11798. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11799. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11800. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11801. }
  11802. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11803. {
  11804. mtrace();
  11805. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11806. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11807. }
  11808. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11809. {
  11810. mtrace();
  11811. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11812. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11813. }
  11814. void handleSignCertificateResponse(char *payload, int gun_index)
  11815. {
  11816. mtrace();
  11817. DEBUG_INFO("handleSignCertificateResponse...\n");
  11818. json_object *SignCertificate;
  11819. SignCertificate = json_tokener_parse(payload);
  11820. if(!is_error(SignCertificate))
  11821. {
  11822. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11823. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11824. }
  11825. json_object_put(SignCertificate);
  11826. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11827. }
  11828. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11829. {
  11830. mtrace();
  11831. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11832. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11833. }
  11834. //==========================================
  11835. // Handle Error routine
  11836. //==========================================
  11837. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11838. {
  11839. mtrace();
  11840. #ifdef SystemLogMessage
  11841. DEBUG_INFO("errorCode: %s\n", errorCode);
  11842. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11843. DEBUG_INFO("errorDetails: %s\n", payload);
  11844. #endif
  11845. }
  11846. //===============================================
  11847. // Common routine
  11848. //===============================================
  11849. int initialConfigurationTable(void)
  11850. {
  11851. //clock_t start_t, end_t, total_t;
  11852. FILE *fp;
  11853. FILE *outfile;
  11854. char str[512]={0};
  11855. char sstr[256]={0};
  11856. int c = 0;
  11857. char *loc;
  11858. int confVersion = 3;
  11859. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11860. //start_t = clock();
  11861. //printf("Starting of the program, start_t = %ld\n", start_t);
  11862. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11863. // Check configuration file size is correct
  11864. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  11865. {
  11866. struct stat st;
  11867. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  11868. if(st.st_size < 3100)
  11869. {
  11870. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  11871. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11872. }
  11873. }
  11874. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  11875. {
  11876. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11877. if(outfile == NULL)
  11878. {
  11879. DEBUG_INFO("Error opening file\n");
  11880. return FALSE;
  11881. }
  11882. /*Core Profile*/
  11883. //AllowOfflineTxForUnknownId
  11884. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11885. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11887. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11888. //AuthorizationCacheEnabled
  11889. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11893. //AuthorizeRemoteTxRequests
  11894. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11895. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11896. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11898. //BlinkRepeat
  11899. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11903. //ClockAlignedDataInterval
  11904. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11906. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11908. //ConnectionTimeOut
  11909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11910. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11913. //GetConfigurationMaxKeys
  11914. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11916. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11918. // HeartbeatInterval
  11919. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11920. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11923. // LightIntensity
  11924. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11928. // LocalAuthorizeOffline
  11929. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11930. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11931. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11933. // LocalPreAuthorize
  11934. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11938. // MaxEnergyOnInvalidId
  11939. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11941. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11943. // MeterValuesAlignedData
  11944. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11945. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11946. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11948. else
  11949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11950. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11951. // MeterValuesAlignedDataMaxLength
  11952. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11953. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11954. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11955. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11956. else
  11957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11959. // MeterValuesSampledData
  11960. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11964. else
  11965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11967. // MeterValuesSampledDataMaxLength
  11968. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11969. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11970. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11972. else
  11973. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11975. // MeterValueSampleInterval
  11976. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11980. // MinimumStatusDuration
  11981. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11982. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11984. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11986. // NumberOfConnectors
  11987. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11988. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11989. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11990. {
  11991. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11992. }
  11993. else
  11994. {
  11995. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11996. }
  11997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11998. // ResetRetries
  11999. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12001. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12003. // ConnectorPhaseRotation
  12004. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12008. // ConnectorPhaseRotationMaxLength
  12009. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12010. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12013. // StopTransactionOnEVSideDisconnect
  12014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12018. // StopTransactionOnInvalidId
  12019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12023. // StopTxnAlignedData
  12024. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12025. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12026. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12028. // StopTxnAlignedDataMaxLength
  12029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12033. // StopTxnSampledData
  12034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12036. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  12038. else
  12039. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12041. // StopTxnSampledDataMaxLength
  12042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12044. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12045. {
  12046. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12047. }
  12048. else
  12049. {
  12050. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12051. }
  12052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12053. // SupportedFeatureProfiles
  12054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12058. // SupportedFeatureProfilesMaxLength
  12059. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12060. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12063. // TransactionMessageAttempts
  12064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12067. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12069. // TransactionMessageRetryInterval
  12070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12073. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12075. // UnlockConnectorOnEVSideDisconnect
  12076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12079. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12080. // WebSocketPingInterval
  12081. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12084. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12085. // QueueOffLineStartTransactionMessage
  12086. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  12087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12088. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12089. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12090. // AuthorizationKey
  12091. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  12094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12095. // SecurityProfile
  12096. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12098. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12100. // DefaultPrice
  12101. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12105. // CustomDisplayCostAndPrice
  12106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12110. // CustomIdleFeeAfterStop
  12111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12114. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12115. // Configuration Version
  12116. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12117. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12118. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12120. //* Local Auth List Management Profile*/
  12121. #if 0
  12122. //For OCTT Test Case
  12123. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12125. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12126. #endif
  12127. #if 1
  12128. //LocalAuthListEnabled
  12129. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12133. #endif
  12134. //LocalAuthListMaxLength
  12135. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12137. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12139. //SendLocalListMaxLength
  12140. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12144. //ReserveConnectorZeroSupported
  12145. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12149. //* Smart Charging Profile */
  12150. //ChargeProfileMaxStackLevel
  12151. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12152. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12153. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12155. // ChargingScheduleAllowedChargingRateUnit
  12156. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12157. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12158. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12160. // ChargingScheduleMaxPeriods
  12161. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12165. // ConnectorSwitch3to1PhaseSupported
  12166. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12170. // MaxChargingProfilesInstalled
  12171. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12173. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12175. fclose(outfile);
  12176. }
  12177. else
  12178. {
  12179. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  12180. char keystr[60]={0};
  12181. char readonlystr[10]={0};
  12182. char valuestr[256]={0};
  12183. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  12184. if(fp == NULL) {
  12185. DEBUG_INFO("Error opening file");
  12186. return FALSE;
  12187. }
  12188. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12189. {
  12190. //DEBUG_INFO("Get Configuration \n");
  12191. if(strlen(str) > 0)
  12192. {
  12193. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12194. //*************************key*********************************/
  12195. if(strstr(str, "key") != NULL)
  12196. {
  12197. loc = strstr(str, "key");
  12198. c = 0;
  12199. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12200. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12201. {
  12202. sstr[c] = loc[strlen("key")+3+c];
  12203. c++;
  12204. }
  12205. sstr[c] = '\0';
  12206. strcpy(keystr,sstr);
  12207. }
  12208. //*************************readonly*********************************/
  12209. if(strstr(str, "readonly") != NULL)
  12210. {
  12211. loc = strstr(str, "readonly");
  12212. c = 0;
  12213. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12214. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12215. {
  12216. sstr[c] = loc[strlen("readonly")+2+c];
  12217. c++;
  12218. }
  12219. sstr[c] = '\0';
  12220. strcpy(readonlystr,sstr);
  12221. }
  12222. //*************************value*********************************/
  12223. if(strstr(str, "value") != NULL)
  12224. {
  12225. loc = strstr(str, "value");
  12226. c = 0;
  12227. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12228. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12229. {
  12230. sstr[c] = loc[strlen("value")+3+c];
  12231. c++;
  12232. }
  12233. sstr[c] = '\0';
  12234. strcpy(valuestr,sstr);
  12235. }
  12236. // DEBUG_INFO("keystr=%s\n",keystr);
  12237. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12238. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12239. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12240. {
  12241. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12242. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12243. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12244. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12245. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12246. }
  12247. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12248. {
  12249. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12250. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12251. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12252. }
  12253. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12254. {
  12255. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12256. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12257. }
  12258. if(strcmp(keystr, "BlinkRepeat") == 0)
  12259. {
  12260. //Charger.BlinkRepeat = Integer.parseInt(value);
  12261. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12262. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12263. }
  12264. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12265. {
  12266. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12267. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12268. }
  12269. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12270. {
  12271. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12272. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12273. }
  12274. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12275. {
  12276. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12277. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12278. }
  12279. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12280. {
  12281. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12282. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12283. HeartBeatWaitTime = atoi(valuestr);
  12284. }
  12285. if(strcmp(keystr, "LightIntensity") == 0)
  12286. {
  12287. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12289. }
  12290. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12291. {
  12292. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12294. }
  12295. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12296. {
  12297. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12298. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12299. }
  12300. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12301. {
  12302. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12303. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12304. }
  12305. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12306. {
  12307. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12308. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12309. }
  12310. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12311. {
  12312. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12314. }
  12315. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12316. {
  12317. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12318. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12319. }
  12320. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12321. {
  12322. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12324. }
  12325. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12326. {
  12327. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12328. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12329. }
  12330. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12331. {
  12332. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12333. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12334. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12335. }
  12336. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12337. {
  12338. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12339. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12340. }
  12341. if(strcmp(keystr, "ResetRetries") == 0)
  12342. {
  12343. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12344. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12345. }
  12346. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12347. {
  12348. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12349. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12350. }
  12351. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12352. {
  12353. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12354. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12355. }
  12356. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12357. {
  12358. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12359. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12360. }
  12361. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12362. {
  12363. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12364. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12365. }
  12366. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12367. {
  12368. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12369. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12370. }
  12371. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12372. {
  12373. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12374. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12375. }
  12376. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12377. {
  12378. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12379. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12380. }
  12381. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12382. {
  12383. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12384. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12385. }
  12386. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12387. {
  12388. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12389. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12390. }
  12391. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12392. {
  12393. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12394. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12395. }
  12396. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12397. {
  12398. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12399. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12400. TransactionMessageAttemptsValue = atoi(valuestr);
  12401. }
  12402. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12403. {
  12404. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12405. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12406. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12407. }
  12408. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12409. {
  12410. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12411. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12412. }
  12413. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12414. {
  12415. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12416. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12417. }
  12418. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  12419. {
  12420. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12421. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  12422. }
  12423. if(strcmp(keystr, "AuthorizationKey") == 0)
  12424. {
  12425. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12426. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12427. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12428. }
  12429. if(strcmp(keystr, "SecurityProfile") == 0)
  12430. {
  12431. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12432. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  12433. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12434. }
  12435. if(strcmp(keystr, "DefaultPrice") == 0)
  12436. {
  12437. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12438. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12439. }
  12440. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12441. {
  12442. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12443. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12444. }
  12445. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12446. {
  12447. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12449. }
  12450. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12451. {
  12452. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12453. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12454. }
  12455. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12456. {
  12457. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12458. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12459. }
  12460. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12461. {
  12462. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12463. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12464. }
  12465. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12466. {
  12467. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12468. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12469. }
  12470. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12471. {
  12472. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12473. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12474. }
  12475. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12476. {
  12477. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12479. }
  12480. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12481. {
  12482. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12483. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12484. }
  12485. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12486. {
  12487. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12488. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12489. }
  12490. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12491. {
  12492. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12493. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12494. }
  12495. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12496. {
  12497. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12498. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12499. }
  12500. }
  12501. }
  12502. fclose(fp);
  12503. }
  12504. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12505. {
  12506. return PASS;
  12507. }
  12508. else
  12509. {
  12510. return FAIL;
  12511. }
  12512. }
  12513. void StoreConfigurationTable(void)
  12514. {
  12515. FILE *outfile;
  12516. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12517. if(outfile == NULL)
  12518. {
  12519. DEBUG_INFO("Error opening file");
  12520. return ;
  12521. }
  12522. /*Core Profile*/
  12523. //AllowOfflineTxForUnknownId
  12524. /*
  12525. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12526. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12527. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12528. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12529. */
  12530. //DEBUG_INFO("data=%s\n",data);
  12531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12532. //AuthorizationCacheEnabled
  12533. /*
  12534. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12535. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12536. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12537. */
  12538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12539. //AuthorizeRemoteTxRequests
  12540. /*
  12541. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12542. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12543. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12544. */
  12545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12546. //BlinkRepeat
  12547. /*
  12548. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12549. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12550. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12551. */
  12552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12553. //ClockAlignedDataInterval
  12554. /*
  12555. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12556. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12557. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12558. */
  12559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12560. //ConnectionTimeOut
  12561. /*
  12562. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12563. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12565. */
  12566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12567. //GetConfigurationMaxKeys
  12568. /*
  12569. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12570. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12572. */
  12573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12574. // HeartbeatInterval
  12575. /*
  12576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12577. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12578. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12579. */
  12580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12581. // LightIntensity
  12582. /*
  12583. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12584. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12585. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12586. */
  12587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12588. // LocalAuthorizeOffline
  12589. /*
  12590. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12591. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12592. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12593. */
  12594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12595. // LocalPreAuthorize
  12596. /*
  12597. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12598. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12599. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12600. */
  12601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12602. // MaxEnergyOnInvalidId
  12603. /*
  12604. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12605. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12607. */
  12608. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12610. // MeterValuesAlignedData
  12611. /*
  12612. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12613. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12614. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12615. */
  12616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12617. // MeterValuesAlignedDataMaxLength
  12618. /*
  12619. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12620. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12621. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12622. */
  12623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12624. // MeterValuesSampledData
  12625. /*
  12626. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12627. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12628. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12629. */
  12630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12631. // MeterValuesSampledDataMaxLength
  12632. /*
  12633. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12634. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12635. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12636. */
  12637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12638. // MeterValueSampleInterval
  12639. /*
  12640. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12641. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12642. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12643. */
  12644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12645. // MinimumStatusDuration
  12646. /*
  12647. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12648. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12649. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12650. */
  12651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12652. // NumberOfConnectors
  12653. /*
  12654. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12655. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12656. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12657. {
  12658. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12659. }
  12660. else
  12661. {
  12662. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12663. }
  12664. */
  12665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12666. // ResetRetries
  12667. /*
  12668. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12669. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12670. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12671. */
  12672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12673. // ConnectorPhaseRotation
  12674. /*
  12675. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12676. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12677. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12678. */
  12679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12680. // ConnectorPhaseRotationMaxLength
  12681. /*
  12682. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12683. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12684. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12685. */
  12686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12687. // StopTransactionOnEVSideDisconnect
  12688. /*
  12689. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12690. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12691. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12692. */
  12693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12694. // StopTransactionOnInvalidId
  12695. /*
  12696. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12697. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12698. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12699. */
  12700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12701. // StopTxnAlignedData
  12702. /*
  12703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12705. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12706. */
  12707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12708. // StopTxnAlignedDataMaxLength
  12709. /*
  12710. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12711. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12712. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12713. */
  12714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12715. // StopTxnSampledData
  12716. /*
  12717. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12718. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12719. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12720. */
  12721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12722. // StopTxnSampledDataMaxLength
  12723. /*
  12724. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12725. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12726. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12727. */
  12728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12729. // SupportedFeatureProfiles
  12730. /*
  12731. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12732. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12733. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12734. */
  12735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12736. // SupportedFeatureProfilesMaxLength
  12737. /*
  12738. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12739. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12740. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12741. */
  12742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12743. // TransactionMessageAttempts
  12744. /*
  12745. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12746. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12747. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12748. */
  12749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12750. // TransactionMessageRetryInterval
  12751. /*
  12752. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12753. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12754. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12755. */
  12756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12757. // UnlockConnectorOnEVSideDisconnect
  12758. /*
  12759. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12760. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12761. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12762. */
  12763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12764. // WebSocketPingInterval
  12765. /*
  12766. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12767. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12768. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12769. */
  12770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12771. // QueueOffLineStartTransactionMessage
  12772. /*
  12773. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12774. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12775. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12776. */
  12777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12778. // AuthorizationKey
  12779. /*
  12780. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12781. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12782. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12783. */
  12784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12785. // SecurityProfile
  12786. /*
  12787. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12788. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12790. */
  12791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12792. // DefaultPrice
  12793. /*
  12794. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12796. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12797. */
  12798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12799. // CustomDisplayCostAndPrice
  12800. /*
  12801. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12802. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12803. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12804. */
  12805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12806. // CustomIdleFeeAfterStop
  12807. /*
  12808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12811. */
  12812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12813. // ConfigurationVersion
  12814. /*
  12815. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12817. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12818. */
  12819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12820. //* Local Auth List Management Profile*/
  12821. //LocalAuthListEnabled
  12822. /*
  12823. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12824. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12825. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12826. */
  12827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12828. //LocalAuthListMaxLength
  12829. /*
  12830. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12832. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12833. */
  12834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12835. //SendLocalListMaxLength
  12836. /*
  12837. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12839. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12840. */
  12841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12842. //ReserveConnectorZeroSupported
  12843. /*
  12844. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12846. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12847. */
  12848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12849. //* Smart Charging Profile */
  12850. //ChargeProfileMaxStackLevel
  12851. /*
  12852. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12853. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12854. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12855. */
  12856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12857. // ChargingScheduleAllowedChargingRateUnit
  12858. /*
  12859. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12860. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12861. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12862. */
  12863. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12864. // ChargingScheduleMaxPeriods
  12865. /*
  12866. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12867. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12868. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12869. */
  12870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12871. // ConnectorSwitch3to1PhaseSupported
  12872. /*
  12873. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12874. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12875. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12876. */
  12877. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12878. // MaxChargingProfilesInstalled
  12879. /*
  12880. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12881. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12882. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12883. */
  12884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12885. fclose(outfile);
  12886. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12887. }
  12888. void getKeyValue(char *keyReq)
  12889. {
  12890. int isEmpty = FALSE;
  12891. int isKnowKey = FALSE;
  12892. DEBUG_INFO("keyReq = %s\n", keyReq);
  12893. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12894. isEmpty = TRUE;
  12895. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12896. {
  12897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12898. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12899. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12900. {
  12901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12902. }
  12903. else
  12904. {
  12905. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12906. }
  12907. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12908. isKnowKey = TRUE;
  12909. }
  12910. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12911. {
  12912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12913. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12914. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12915. {
  12916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12917. }
  12918. else
  12919. {
  12920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12921. }
  12922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12923. isKnowKey = TRUE;
  12924. }
  12925. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12926. {
  12927. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12929. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12930. {
  12931. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12932. }
  12933. else
  12934. {
  12935. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12936. }
  12937. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12938. isKnowKey = TRUE;
  12939. }
  12940. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12941. {
  12942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12944. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12945. {
  12946. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12947. }
  12948. else
  12949. {
  12950. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12951. }
  12952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12953. isKnowKey = TRUE;
  12954. }
  12955. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12956. {
  12957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12959. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12960. {
  12961. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12962. }
  12963. else
  12964. {
  12965. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12966. }
  12967. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12968. isKnowKey = TRUE;
  12969. }
  12970. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12971. {
  12972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12974. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12975. {
  12976. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12977. }
  12978. else
  12979. {
  12980. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12981. }
  12982. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12983. isKnowKey = TRUE;
  12984. }
  12985. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12986. {
  12987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12989. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12990. {
  12991. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12992. }
  12993. else
  12994. {
  12995. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12996. }
  12997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12998. isKnowKey = TRUE;
  12999. }
  13000. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13001. {
  13002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13004. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13005. {
  13006. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13007. }
  13008. else
  13009. {
  13010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13011. }
  13012. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13013. isKnowKey = TRUE;
  13014. }
  13015. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13016. {
  13017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13018. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13019. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13020. {
  13021. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13022. }
  13023. else
  13024. {
  13025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13026. }
  13027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13028. isKnowKey = TRUE;
  13029. }
  13030. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13031. {
  13032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13034. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13035. {
  13036. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13037. }
  13038. else
  13039. {
  13040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13041. }
  13042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13043. isKnowKey = TRUE;
  13044. }
  13045. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13046. {
  13047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13049. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13050. {
  13051. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13052. }
  13053. else
  13054. {
  13055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13056. }
  13057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13058. isKnowKey = TRUE;
  13059. }
  13060. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13061. {
  13062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13064. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13065. {
  13066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13067. }
  13068. else
  13069. {
  13070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13071. }
  13072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13073. isKnowKey = TRUE;
  13074. }
  13075. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13076. {
  13077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13079. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13080. {
  13081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13082. }
  13083. else
  13084. {
  13085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13086. }
  13087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13088. isKnowKey = TRUE;
  13089. }
  13090. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13091. {
  13092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13094. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13095. {
  13096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13097. }
  13098. else
  13099. {
  13100. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13101. }
  13102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13103. isKnowKey = TRUE;
  13104. }
  13105. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13106. {
  13107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13109. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13110. {
  13111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13112. }
  13113. else
  13114. {
  13115. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13116. }
  13117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13118. isKnowKey = TRUE;
  13119. }
  13120. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13121. {
  13122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13123. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13124. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13125. {
  13126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13127. }
  13128. else
  13129. {
  13130. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13131. }
  13132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13133. isKnowKey = TRUE;
  13134. }
  13135. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13136. {
  13137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13138. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13139. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13140. {
  13141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13142. }
  13143. else
  13144. {
  13145. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13146. }
  13147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13148. isKnowKey = TRUE;
  13149. }
  13150. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13151. {
  13152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13153. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13154. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13155. {
  13156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13157. }
  13158. else
  13159. {
  13160. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13161. }
  13162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  13163. isKnowKey = TRUE;
  13164. }
  13165. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13166. {
  13167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13168. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13169. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13170. {
  13171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13172. }
  13173. else
  13174. {
  13175. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13176. }
  13177. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13179. isKnowKey = TRUE;
  13180. }
  13181. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13182. {
  13183. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13184. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13185. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13186. {
  13187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13188. }
  13189. else
  13190. {
  13191. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13192. }
  13193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13194. isKnowKey = TRUE;
  13195. }
  13196. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13197. {
  13198. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13199. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13200. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13201. {
  13202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13203. }
  13204. else
  13205. {
  13206. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13207. }
  13208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13209. isKnowKey = TRUE;
  13210. }
  13211. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13212. {
  13213. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13214. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13215. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13216. {
  13217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13218. }
  13219. else
  13220. {
  13221. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13222. }
  13223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13224. isKnowKey = TRUE;
  13225. }
  13226. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13227. {
  13228. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13229. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13230. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13231. {
  13232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13233. }
  13234. else
  13235. {
  13236. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13237. }
  13238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13239. isKnowKey = TRUE;
  13240. }
  13241. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13242. {
  13243. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13244. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13245. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13246. {
  13247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13248. }
  13249. else
  13250. {
  13251. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13252. }
  13253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13254. isKnowKey = TRUE;
  13255. }
  13256. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13257. {
  13258. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13259. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13260. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13261. {
  13262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13263. }
  13264. else
  13265. {
  13266. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13267. }
  13268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13269. isKnowKey = TRUE;
  13270. }
  13271. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13272. {
  13273. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13274. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13275. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13276. {
  13277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13278. }
  13279. else
  13280. {
  13281. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13282. }
  13283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13284. isKnowKey = TRUE;
  13285. }
  13286. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13287. {
  13288. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13289. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13290. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13291. {
  13292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13293. }
  13294. else
  13295. {
  13296. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13297. }
  13298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13299. isKnowKey = TRUE;
  13300. }
  13301. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13302. {
  13303. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13304. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13305. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13306. {
  13307. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13308. }
  13309. else
  13310. {
  13311. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13312. }
  13313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13314. isKnowKey = TRUE;
  13315. }
  13316. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13317. {
  13318. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13319. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13320. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13321. {
  13322. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13323. }
  13324. else
  13325. {
  13326. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13327. }
  13328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13329. isKnowKey = TRUE;
  13330. }
  13331. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13332. {
  13333. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13334. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13335. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13336. {
  13337. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13338. }
  13339. else
  13340. {
  13341. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13342. }
  13343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13344. isKnowKey = TRUE;
  13345. }
  13346. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13347. {
  13348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13349. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13350. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13351. {
  13352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13353. }
  13354. else
  13355. {
  13356. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13357. }
  13358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13359. isKnowKey = TRUE;
  13360. }
  13361. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13362. {
  13363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13364. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13365. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13366. {
  13367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13368. }
  13369. else
  13370. {
  13371. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13372. }
  13373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13374. isKnowKey = TRUE;
  13375. }
  13376. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13377. {
  13378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13379. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13380. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13381. {
  13382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13383. }
  13384. else
  13385. {
  13386. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13387. }
  13388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13389. isKnowKey = TRUE;
  13390. }
  13391. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13392. {
  13393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13394. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13395. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13396. {
  13397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13398. }
  13399. else
  13400. {
  13401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13402. }
  13403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13404. isKnowKey = TRUE;
  13405. }
  13406. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  13407. {
  13408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  13409. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  13410. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13411. {
  13412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  13413. }
  13414. else
  13415. {
  13416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  13417. }
  13418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  13419. isKnowKey = TRUE;
  13420. }
  13421. /*
  13422. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13423. {
  13424. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13426. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13427. {
  13428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13429. }
  13430. else
  13431. {
  13432. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13433. }
  13434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13435. isKnowKey = TRUE;
  13436. }*/
  13437. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13438. {
  13439. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13441. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13442. {
  13443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13444. }
  13445. else
  13446. {
  13447. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13448. }
  13449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13450. isKnowKey = TRUE;
  13451. }
  13452. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13453. {
  13454. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13456. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13457. {
  13458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13459. }
  13460. else
  13461. {
  13462. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13463. }
  13464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13465. isKnowKey = TRUE;
  13466. }
  13467. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13468. {
  13469. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13471. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13472. {
  13473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13474. }
  13475. else
  13476. {
  13477. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13478. }
  13479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13480. isKnowKey = TRUE;
  13481. }
  13482. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13483. {
  13484. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13486. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13487. {
  13488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13489. }
  13490. else
  13491. {
  13492. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13493. }
  13494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13495. isKnowKey = TRUE;
  13496. }
  13497. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13498. {
  13499. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13501. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13502. {
  13503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13504. }
  13505. else
  13506. {
  13507. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13508. }
  13509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13510. isKnowKey = TRUE;
  13511. }
  13512. #if 1
  13513. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13514. {
  13515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13517. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13518. {
  13519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13520. }
  13521. else
  13522. {
  13523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13524. }
  13525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13526. isKnowKey = TRUE;
  13527. }
  13528. #endif
  13529. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13530. {
  13531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13533. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13534. {
  13535. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13536. }
  13537. else
  13538. {
  13539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13540. }
  13541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13542. isKnowKey = TRUE;
  13543. }
  13544. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13545. {
  13546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13548. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13549. {
  13550. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13551. }
  13552. else
  13553. {
  13554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13555. }
  13556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13557. isKnowKey = TRUE;
  13558. }
  13559. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13560. {
  13561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13563. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13564. {
  13565. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13566. }
  13567. else
  13568. {
  13569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13570. }
  13571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13572. isKnowKey = TRUE;
  13573. }
  13574. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13575. {
  13576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13578. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13579. {
  13580. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13581. }
  13582. else
  13583. {
  13584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13585. }
  13586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13587. isKnowKey = TRUE;
  13588. }
  13589. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13590. {
  13591. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13593. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13594. {
  13595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13596. }
  13597. else
  13598. {
  13599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13600. }
  13601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13602. isKnowKey = TRUE;
  13603. }
  13604. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13605. {
  13606. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13608. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13609. {
  13610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13611. }
  13612. else
  13613. {
  13614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13615. }
  13616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13617. isKnowKey = TRUE;
  13618. }
  13619. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13620. {
  13621. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13623. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13624. {
  13625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13626. }
  13627. else
  13628. {
  13629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13630. }
  13631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13632. isKnowKey = TRUE;
  13633. }
  13634. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13635. {
  13636. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13638. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13639. {
  13640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13641. }
  13642. else
  13643. {
  13644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13645. }
  13646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13647. isKnowKey = TRUE;
  13648. }
  13649. //=========================================================
  13650. if(!isEmpty && !isKnowKey)
  13651. {
  13652. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13653. strcpy(unknownkey[UnknownKeynum], keyReq);
  13654. UnknownKeynum = UnknownKeynum + 1;
  13655. }
  13656. }
  13657. void processUnkownKey(void)
  13658. {
  13659. DEBUG_INFO("processUnkownKey...\n");
  13660. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13661. for(int index=0; index < UnknownKeynum; index++)
  13662. {
  13663. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13664. {
  13665. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13666. }
  13667. }
  13668. }
  13669. int setKeyValue(char *key, char *value)
  13670. {
  13671. int isSuccess = NotSupported;
  13672. int check_ascii=0;
  13673. char str[256]={0};
  13674. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13675. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13676. {
  13677. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13678. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13679. {
  13680. strcpy(str, (const char*)value);
  13681. for(int i = 0; str[i]; i++){
  13682. str[i] = tolower(str[i]);
  13683. }
  13684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13685. isSuccess = ConfigurationStatus_Accepted;
  13686. }
  13687. else
  13688. {
  13689. isSuccess = ConfigurationStatus_Rejected;
  13690. }
  13691. }
  13692. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13693. {
  13694. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13695. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13696. {
  13697. strcpy(str, (const char*)value);
  13698. for(int i = 0; str[i]; i++){
  13699. str[i] = tolower(str[i]);
  13700. }
  13701. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13702. isSuccess = ConfigurationStatus_Accepted;
  13703. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13704. }
  13705. else
  13706. {
  13707. isSuccess = ConfigurationStatus_Rejected;
  13708. }
  13709. }
  13710. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13711. {
  13712. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13713. {
  13714. strcpy(str, (const char*)value);
  13715. for(int i = 0; str[i]; i++)
  13716. {
  13717. str[i] = tolower(str[i]);
  13718. }
  13719. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13720. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13721. isSuccess = ConfigurationStatus_Accepted;
  13722. }
  13723. else
  13724. {
  13725. isSuccess = ConfigurationStatus_Rejected;
  13726. }
  13727. }
  13728. if(strcmp(key, "BlinkRepeat") == 0)
  13729. {
  13730. //Charger.BlinkRepeat = Integer.parseInt(value);
  13731. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13732. {
  13733. check_ascii = value[0];
  13734. if( (check_ascii < 48) || (check_ascii > 57) )
  13735. {
  13736. isSuccess = ConfigurationStatus_Rejected;
  13737. }
  13738. else
  13739. {
  13740. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13741. isSuccess = ConfigurationStatus_Accepted;
  13742. }
  13743. }
  13744. else
  13745. {
  13746. isSuccess = ConfigurationStatus_Rejected;
  13747. }
  13748. }
  13749. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13750. {
  13751. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13752. {
  13753. check_ascii = value[0];
  13754. if( (check_ascii < 48) || (check_ascii > 57) )
  13755. {
  13756. isSuccess = ConfigurationStatus_Rejected;
  13757. }
  13758. else
  13759. {
  13760. if((atoi(value) == 0) || (atoi(value) >= 10))
  13761. {
  13762. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13763. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13764. isSuccess = ConfigurationStatus_Accepted;
  13765. }
  13766. else
  13767. isSuccess = ConfigurationStatus_Rejected;
  13768. }
  13769. }
  13770. else
  13771. {
  13772. isSuccess = ConfigurationStatus_Rejected;
  13773. }
  13774. }
  13775. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13776. {
  13777. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13778. {
  13779. check_ascii = value[0];
  13780. if( (check_ascii < 48) || (check_ascii > 57) )
  13781. {
  13782. isSuccess = ConfigurationStatus_Rejected;
  13783. }
  13784. else
  13785. {
  13786. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13787. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13788. isSuccess = ConfigurationStatus_Accepted;
  13789. }
  13790. }
  13791. else
  13792. {
  13793. isSuccess = ConfigurationStatus_Rejected;
  13794. }
  13795. }
  13796. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13797. {
  13798. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13799. {
  13800. check_ascii = value[0];
  13801. if( (check_ascii < 48) || (check_ascii > 57) )
  13802. {
  13803. isSuccess = ConfigurationStatus_Rejected;
  13804. }
  13805. else
  13806. {
  13807. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13808. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13809. isSuccess = ConfigurationStatus_Accepted;
  13810. }
  13811. }
  13812. else
  13813. {
  13814. isSuccess = ConfigurationStatus_Rejected;
  13815. }
  13816. }
  13817. if(strcmp(key, "HeartbeatInterval") == 0)
  13818. {
  13819. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13820. {
  13821. check_ascii = value[0];
  13822. if( (check_ascii < 48) || (check_ascii > 57) )
  13823. {
  13824. isSuccess = ConfigurationStatus_Rejected;
  13825. }
  13826. else
  13827. {
  13828. if((atoi(value) == 0) || (atoi(value) >= 10))
  13829. {
  13830. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13831. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13832. HeartBeatWaitTime = atoi(value);
  13833. isSuccess = ConfigurationStatus_Accepted;
  13834. }
  13835. else
  13836. {
  13837. isSuccess = ConfigurationStatus_Rejected;
  13838. }
  13839. }
  13840. }
  13841. else
  13842. {
  13843. isSuccess = ConfigurationStatus_Rejected;
  13844. }
  13845. }
  13846. if(strcmp(key, "LightIntensity") == 0)
  13847. {
  13848. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13849. {
  13850. check_ascii = value[0];
  13851. if( (check_ascii < 48) || (check_ascii > 57) )
  13852. {
  13853. isSuccess = ConfigurationStatus_Rejected;
  13854. }
  13855. else
  13856. {
  13857. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13858. isSuccess = ConfigurationStatus_Accepted;
  13859. }
  13860. }
  13861. else
  13862. {
  13863. isSuccess = ConfigurationStatus_Rejected;
  13864. }
  13865. }
  13866. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13867. {
  13868. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13869. {
  13870. strcpy(str, (const char*)value);
  13871. for(int i = 0; str[i]; i++)
  13872. {
  13873. str[i] = tolower(str[i]);
  13874. }
  13875. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13876. isSuccess = ConfigurationStatus_Accepted;
  13877. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13878. }
  13879. else
  13880. {
  13881. isSuccess = ConfigurationStatus_Rejected;
  13882. }
  13883. }
  13884. if(strcmp(key, "LocalPreAuthorize") == 0)
  13885. {
  13886. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13887. {
  13888. strcpy(str, (const char*)value);
  13889. for(int i = 0; str[i]; i++)
  13890. {
  13891. str[i] = tolower(str[i]);
  13892. }
  13893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13894. isSuccess = ConfigurationStatus_Accepted;
  13895. }
  13896. else
  13897. {
  13898. isSuccess = ConfigurationStatus_Rejected;
  13899. }
  13900. }
  13901. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13902. {
  13903. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13904. {
  13905. check_ascii = value[0];
  13906. if( (check_ascii < 48) || (check_ascii > 57) )
  13907. {
  13908. isSuccess = ConfigurationStatus_Rejected;
  13909. }
  13910. else
  13911. {
  13912. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13913. isSuccess = ConfigurationStatus_Accepted;
  13914. }
  13915. }
  13916. else
  13917. {
  13918. isSuccess = ConfigurationStatus_Rejected;
  13919. }
  13920. }
  13921. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13922. {
  13923. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13924. {
  13925. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13926. isSuccess = ConfigurationStatus_Accepted;
  13927. }
  13928. else
  13929. {
  13930. isSuccess = ConfigurationStatus_Rejected;
  13931. }
  13932. }
  13933. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13934. {
  13935. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13936. {
  13937. check_ascii = value[0];
  13938. if( (check_ascii < 48) || (check_ascii > 57) )
  13939. {
  13940. isSuccess = ConfigurationStatus_Rejected;
  13941. }
  13942. else
  13943. {
  13944. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13945. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13946. isSuccess = ConfigurationStatus_Accepted;
  13947. }
  13948. }
  13949. else
  13950. {
  13951. isSuccess = ConfigurationStatus_Rejected;
  13952. }
  13953. }
  13954. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13955. {
  13956. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13957. {
  13958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13959. isSuccess = ConfigurationStatus_Accepted;
  13960. }
  13961. else
  13962. {
  13963. isSuccess = ConfigurationStatus_Rejected;
  13964. }
  13965. }
  13966. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13967. {
  13968. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13969. {
  13970. check_ascii = value[0];
  13971. if( (check_ascii < 48) || (check_ascii > 57) )
  13972. {
  13973. isSuccess = ConfigurationStatus_Rejected;
  13974. }
  13975. else
  13976. {
  13977. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13978. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13979. isSuccess = ConfigurationStatus_Accepted;
  13980. }
  13981. }
  13982. else
  13983. {
  13984. isSuccess = ConfigurationStatus_Rejected;
  13985. }
  13986. }
  13987. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13988. {
  13989. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13990. {
  13991. check_ascii = value[0];
  13992. if( (check_ascii < 48) || (check_ascii > 57) )
  13993. {
  13994. isSuccess = ConfigurationStatus_Rejected;
  13995. }
  13996. else
  13997. {
  13998. if((atoi(value) == 0) || (atoi(value) >= 10))
  13999. {
  14000. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14001. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14002. isSuccess = ConfigurationStatus_Accepted;
  14003. }
  14004. else
  14005. {
  14006. isSuccess = ConfigurationStatus_Rejected;
  14007. }
  14008. }
  14009. }
  14010. else
  14011. {
  14012. isSuccess = ConfigurationStatus_Rejected;
  14013. }
  14014. }
  14015. if(strcmp(key, "MinimumStatusDuration") == 0)
  14016. {
  14017. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14018. {
  14019. check_ascii = value[0];
  14020. if( (check_ascii < 48) || (check_ascii > 57) )
  14021. {
  14022. isSuccess = ConfigurationStatus_Rejected;
  14023. }
  14024. else
  14025. {
  14026. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14027. {
  14028. isSuccess = ConfigurationStatus_Rejected;
  14029. }
  14030. else
  14031. {
  14032. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14033. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14034. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14035. isSuccess = ConfigurationStatus_Accepted;
  14036. }
  14037. }
  14038. }
  14039. else
  14040. {
  14041. isSuccess = ConfigurationStatus_Rejected;
  14042. }
  14043. }
  14044. if(strcmp(key, "NumberOfConnectors") == 0)
  14045. {
  14046. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14047. {
  14048. check_ascii = value[0];
  14049. if( (check_ascii < 48) || (check_ascii > 57) )
  14050. {
  14051. isSuccess = ConfigurationStatus_Rejected;
  14052. }
  14053. else
  14054. {
  14055. //Charger.ResetRetries = Integer.parseInt(value);
  14056. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14057. isSuccess = ConfigurationStatus_Accepted;
  14058. }
  14059. }
  14060. else
  14061. {
  14062. isSuccess = ConfigurationStatus_Rejected;
  14063. }
  14064. }
  14065. if(strcmp(key, "ResetRetries") == 0)
  14066. {
  14067. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14068. {
  14069. check_ascii = value[0];
  14070. if( (check_ascii < 48) || (check_ascii > 57) )
  14071. {
  14072. isSuccess = ConfigurationStatus_Rejected;
  14073. }
  14074. else
  14075. {
  14076. //Charger.ResetRetries = Integer.parseInt(value);
  14077. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14078. isSuccess = ConfigurationStatus_Accepted;
  14079. }
  14080. }
  14081. else
  14082. {
  14083. isSuccess = ConfigurationStatus_Rejected;
  14084. }
  14085. }
  14086. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14087. {
  14088. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14089. {
  14090. strcpy(str, (const char*)value);
  14091. for(int i = 0; str[i]; i++)
  14092. {
  14093. str[i] = tolower(str[i]);
  14094. }
  14095. if(strcmp(str, "notapplicable")== 0)
  14096. {
  14097. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14098. isSuccess = ConfigurationStatus_Accepted;
  14099. }
  14100. else if(strcmp(str, "unknown")== 0)
  14101. {
  14102. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14103. isSuccess = ConfigurationStatus_Accepted;
  14104. }
  14105. else if(strcmp(str, "rst")== 0)
  14106. {
  14107. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14108. isSuccess = ConfigurationStatus_Accepted;
  14109. }
  14110. else if(strcmp(str, "rts")== 0)
  14111. {
  14112. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14113. isSuccess = ConfigurationStatus_Accepted;
  14114. }
  14115. else if(strcmp(str, "srt")== 0)
  14116. {
  14117. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14118. isSuccess = ConfigurationStatus_Accepted;
  14119. }
  14120. else if(strcmp(str, "str")== 0)
  14121. {
  14122. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14123. isSuccess = ConfigurationStatus_Accepted;
  14124. }
  14125. else if(strcmp(str, "trs")== 0)
  14126. {
  14127. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14128. isSuccess = ConfigurationStatus_Accepted;
  14129. }
  14130. else if(strcmp(str, "tsr")== 0)
  14131. {
  14132. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14133. isSuccess = ConfigurationStatus_Accepted;
  14134. }
  14135. else
  14136. {
  14137. isSuccess = ConfigurationStatus_Rejected;
  14138. }
  14139. }
  14140. else
  14141. {
  14142. isSuccess = ConfigurationStatus_Rejected;
  14143. }
  14144. }
  14145. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14146. {
  14147. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14148. {
  14149. check_ascii = value[0];
  14150. if( (check_ascii < 48) || (check_ascii > 57) )
  14151. {
  14152. isSuccess = ConfigurationStatus_Rejected;
  14153. }
  14154. else
  14155. {
  14156. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14157. isSuccess = ConfigurationStatus_Accepted;
  14158. }
  14159. }
  14160. else
  14161. {
  14162. isSuccess = ConfigurationStatus_Rejected;
  14163. }
  14164. }
  14165. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14166. {
  14167. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14168. {
  14169. strcpy(str, (const char*)value);
  14170. for(int i = 0; str[i]; i++)
  14171. {
  14172. str[i] = tolower(str[i]);
  14173. }
  14174. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14175. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14176. isSuccess = ConfigurationStatus_Accepted;
  14177. }
  14178. else
  14179. {
  14180. isSuccess = ConfigurationStatus_Rejected;
  14181. }
  14182. }
  14183. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14184. {
  14185. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14186. {
  14187. strcpy(str, (const char*)value);
  14188. for(int i = 0; str[i]; i++)
  14189. {
  14190. str[i] = tolower(str[i]);
  14191. }
  14192. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14193. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14194. isSuccess = ConfigurationStatus_Accepted;
  14195. }
  14196. else
  14197. {
  14198. isSuccess = ConfigurationStatus_Rejected;
  14199. }
  14200. }
  14201. if(strcmp(key, "StopTxnAlignedData") == 0)
  14202. {
  14203. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14204. {
  14205. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14206. isSuccess = ConfigurationStatus_Accepted;
  14207. }
  14208. else
  14209. {
  14210. isSuccess = ConfigurationStatus_Rejected;
  14211. }
  14212. }
  14213. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14214. {
  14215. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14216. {
  14217. check_ascii = value[0];
  14218. if( (check_ascii < 48) || (check_ascii > 57) )
  14219. {
  14220. isSuccess = ConfigurationStatus_Rejected;
  14221. }
  14222. else
  14223. {
  14224. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14225. isSuccess = ConfigurationStatus_Accepted;
  14226. }
  14227. }
  14228. else
  14229. {
  14230. isSuccess = ConfigurationStatus_Rejected;
  14231. }
  14232. }
  14233. if(strcmp(key, "StopTxnSampledData") == 0)
  14234. {
  14235. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14236. {
  14237. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14238. isSuccess = ConfigurationStatus_Accepted;
  14239. }
  14240. else
  14241. {
  14242. isSuccess = ConfigurationStatus_Rejected;
  14243. }
  14244. }
  14245. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14246. {
  14247. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14248. {
  14249. check_ascii = value[0];
  14250. if( (check_ascii < 48) || (check_ascii > 57) )
  14251. {
  14252. isSuccess = ConfigurationStatus_Rejected;
  14253. }
  14254. else
  14255. {
  14256. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14257. isSuccess = ConfigurationStatus_Accepted;
  14258. }
  14259. }
  14260. else
  14261. {
  14262. isSuccess = ConfigurationStatus_Rejected;
  14263. }
  14264. }
  14265. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14266. {
  14267. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14268. {
  14269. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14270. isSuccess = ConfigurationStatus_Accepted;
  14271. }
  14272. else
  14273. {
  14274. isSuccess = ConfigurationStatus_Rejected;
  14275. }
  14276. }
  14277. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14278. {
  14279. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14280. {
  14281. check_ascii = value[0];
  14282. if( (check_ascii < 48) || (check_ascii > 57) )
  14283. {
  14284. isSuccess = ConfigurationStatus_Rejected;
  14285. }
  14286. else
  14287. {
  14288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14289. isSuccess = ConfigurationStatus_Accepted;
  14290. }
  14291. }
  14292. else
  14293. {
  14294. isSuccess = ConfigurationStatus_Rejected;
  14295. }
  14296. }
  14297. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14298. {
  14299. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14300. {
  14301. check_ascii = value[0];
  14302. if( (check_ascii < 48) || (check_ascii > 57) )
  14303. {
  14304. isSuccess = ConfigurationStatus_Rejected;
  14305. }
  14306. else
  14307. {
  14308. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14309. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14310. TransactionMessageAttemptsValue = atoi(value);
  14311. isSuccess = ConfigurationStatus_Accepted;
  14312. }
  14313. }
  14314. else
  14315. {
  14316. isSuccess = ConfigurationStatus_Rejected;
  14317. }
  14318. }
  14319. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14320. {
  14321. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14322. {
  14323. check_ascii = value[0];
  14324. if( (check_ascii < 48) || (check_ascii > 57) )
  14325. {
  14326. isSuccess = ConfigurationStatus_Rejected;
  14327. }
  14328. else
  14329. {
  14330. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14331. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14332. TransactionMessageRetryIntervalValue = atoi(value);
  14333. isSuccess = ConfigurationStatus_Accepted;
  14334. }
  14335. }
  14336. else
  14337. {
  14338. isSuccess = ConfigurationStatus_Rejected;
  14339. }
  14340. }
  14341. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14342. {
  14343. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14344. {
  14345. strcpy(str, (const char*)value);
  14346. for(int i = 0; str[i]; i++)
  14347. {
  14348. str[i] = tolower(str[i]);
  14349. }
  14350. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14351. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14352. isSuccess = ConfigurationStatus_Accepted;
  14353. }
  14354. else
  14355. {
  14356. isSuccess = ConfigurationStatus_Rejected;
  14357. }
  14358. }
  14359. if(strcmp(key, "WebSocketPingInterval") == 0)
  14360. {
  14361. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14362. {
  14363. check_ascii = value[0];
  14364. if( (check_ascii < 48) || (check_ascii > 57) )
  14365. {
  14366. isSuccess = ConfigurationStatus_Rejected;
  14367. }
  14368. else
  14369. {
  14370. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14371. isSuccess = ConfigurationStatus_Accepted;
  14372. }
  14373. }
  14374. else
  14375. {
  14376. isSuccess = ConfigurationStatus_Rejected;
  14377. }
  14378. }
  14379. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  14380. {
  14381. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  14382. {
  14383. strcpy(str, (const char*)value);
  14384. for(int i = 0; str[i]; i++)
  14385. {
  14386. str[i] = tolower(str[i]);
  14387. }
  14388. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14389. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14390. isSuccess = ConfigurationStatus_Accepted;
  14391. }
  14392. else
  14393. {
  14394. isSuccess = ConfigurationStatus_Rejected;
  14395. }
  14396. }
  14397. if(strcmp(key, "AuthorizationKey") == 0)
  14398. {
  14399. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14400. {
  14401. strcpy(str, (const char*)value);
  14402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14403. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14404. isSuccess = ConfigurationStatus_Accepted;
  14405. }
  14406. else
  14407. {
  14408. isSuccess = ConfigurationStatus_Rejected;
  14409. }
  14410. }
  14411. if(strcmp(key, "SecurityProfile") == 0)
  14412. {
  14413. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14414. {
  14415. check_ascii = value[0];
  14416. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14417. {
  14418. isSuccess = ConfigurationStatus_Rejected;
  14419. }
  14420. else if(check_ascii == 0x33)
  14421. {
  14422. isSuccess = NotSupported;
  14423. }
  14424. else
  14425. {
  14426. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14427. {
  14428. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14429. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14430. isSuccess = ConfigurationStatus_Accepted;
  14431. }
  14432. else
  14433. isSuccess = ConfigurationStatus_Rejected;
  14434. }
  14435. }
  14436. else
  14437. {
  14438. isSuccess = ConfigurationStatus_Rejected;
  14439. }
  14440. }
  14441. if(strcmp(key, "DefaultPrice") == 0)
  14442. {
  14443. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14444. {
  14445. strcpy(str, (const char*)value);
  14446. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14447. isSuccess = ConfigurationStatus_Accepted;
  14448. }
  14449. else
  14450. {
  14451. isSuccess = ConfigurationStatus_Rejected;
  14452. }
  14453. }
  14454. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14455. {
  14456. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14457. {
  14458. strcpy(str, (const char*)value);
  14459. for(int i = 0; str[i]; i++)
  14460. {
  14461. str[i] = tolower(str[i]);
  14462. }
  14463. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14464. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].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, "CustomIdleFeeAfterStop") == 0)
  14473. {
  14474. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14475. {
  14476. strcpy(str, (const char*)value);
  14477. for(int i = 0; str[i]; i++)
  14478. {
  14479. str[i] = tolower(str[i]);
  14480. }
  14481. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  14482. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14483. isSuccess = ConfigurationStatus_Accepted;
  14484. }
  14485. else
  14486. {
  14487. isSuccess = ConfigurationStatus_Rejected;
  14488. }
  14489. }
  14490. #if 0
  14491. //For OCPP Test Case
  14492. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14493. {
  14494. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14495. {
  14496. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14497. isSuccess = ConfigurationStatus_Accepted;
  14498. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14499. }
  14500. else
  14501. {
  14502. isSuccess = ConfigurationStatus_Rejected;
  14503. }
  14504. }
  14505. #endif
  14506. #if 1
  14507. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14508. {
  14509. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14510. {
  14511. strcpy(str, (const char*)value);
  14512. for(int i = 0; str[i]; i++)
  14513. {
  14514. str[i] = tolower(str[i]);
  14515. }
  14516. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14517. isSuccess = ConfigurationStatus_Accepted;
  14518. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14519. }
  14520. else
  14521. {
  14522. isSuccess = ConfigurationStatus_Rejected;
  14523. }
  14524. }
  14525. #endif
  14526. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14527. {
  14528. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14529. {
  14530. check_ascii = value[0];
  14531. if( (check_ascii < 48) || (check_ascii > 57) )
  14532. {
  14533. isSuccess = ConfigurationStatus_Rejected;
  14534. }
  14535. else
  14536. {
  14537. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14538. isSuccess = ConfigurationStatus_Accepted;
  14539. }
  14540. }
  14541. else
  14542. {
  14543. isSuccess = ConfigurationStatus_Rejected;
  14544. }
  14545. }
  14546. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14547. {
  14548. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14549. {
  14550. check_ascii = value[0];
  14551. if( (check_ascii < 48) || (check_ascii > 57) )
  14552. {
  14553. isSuccess = ConfigurationStatus_Rejected;
  14554. }
  14555. else
  14556. {
  14557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14558. isSuccess = ConfigurationStatus_Accepted;
  14559. }
  14560. }
  14561. else
  14562. {
  14563. isSuccess = ConfigurationStatus_Rejected;
  14564. }
  14565. }
  14566. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14567. {
  14568. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14569. {
  14570. strcpy(str, (const char*)value);
  14571. for(int i = 0; str[i]; i++)
  14572. {
  14573. str[i] = tolower(str[i]);
  14574. }
  14575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14576. isSuccess = ConfigurationStatus_Accepted;
  14577. }
  14578. else
  14579. {
  14580. isSuccess = ConfigurationStatus_Rejected;
  14581. }
  14582. }
  14583. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14584. {
  14585. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14586. {
  14587. check_ascii = value[0];
  14588. if( (check_ascii < 48) || (check_ascii > 57) )
  14589. {
  14590. isSuccess = ConfigurationStatus_Rejected;
  14591. }
  14592. else
  14593. {
  14594. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14595. isSuccess = ConfigurationStatus_Accepted;
  14596. }
  14597. }
  14598. else
  14599. {
  14600. isSuccess = ConfigurationStatus_Rejected;
  14601. }
  14602. }
  14603. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14604. {
  14605. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14606. {
  14607. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14608. isSuccess = ConfigurationStatus_Accepted;
  14609. }
  14610. else
  14611. {
  14612. isSuccess = ConfigurationStatus_Rejected;
  14613. }
  14614. }
  14615. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14616. {
  14617. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].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. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14627. isSuccess = ConfigurationStatus_Accepted;
  14628. }
  14629. }
  14630. else
  14631. {
  14632. isSuccess = ConfigurationStatus_Rejected;
  14633. }
  14634. }
  14635. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14636. {
  14637. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14638. {
  14639. strcpy(str, (const char*)value);
  14640. for(int i = 0; str[i]; i++)
  14641. {
  14642. str[i] = tolower(str[i]);
  14643. }
  14644. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14645. isSuccess = ConfigurationStatus_Accepted;
  14646. }
  14647. else
  14648. {
  14649. isSuccess = ConfigurationStatus_Rejected;
  14650. }
  14651. }
  14652. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14653. {
  14654. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14655. {
  14656. check_ascii = value[0];
  14657. if( (check_ascii < 48) || (check_ascii > 57) )
  14658. {
  14659. isSuccess = ConfigurationStatus_Rejected;
  14660. }
  14661. else
  14662. {
  14663. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14664. isSuccess = ConfigurationStatus_Accepted;
  14665. }
  14666. }
  14667. else
  14668. {
  14669. isSuccess = ConfigurationStatus_Rejected;
  14670. }
  14671. }
  14672. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14673. return isSuccess;
  14674. }
  14675. int TransactionMessageAttemptsGet(void)
  14676. {
  14677. return TransactionMessageAttemptsValue;
  14678. }
  14679. int FirstHeartBeatResponse(void)
  14680. {
  14681. return FirstHeartBeat;
  14682. }
  14683. int TransactionMessageRetryIntervalGet(void)
  14684. {
  14685. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14686. }
  14687. int ReadHttpStatus(int sock)
  14688. {
  14689. //char c;
  14690. char buff[1024]="",*ptr=buff+1;
  14691. int bytes_received, status;
  14692. DEBUG_INFO("Begin Response ..\n");
  14693. while((bytes_received = recv(sock, ptr, 1, 0))){
  14694. if(bytes_received==-1){
  14695. perror("ReadHttpStatus");
  14696. exit(1);
  14697. }
  14698. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14699. ptr++;
  14700. }
  14701. *ptr=0;
  14702. ptr=buff+1;
  14703. sscanf(ptr,"%*s %d ", &status);
  14704. DEBUG_INFO("%s\n",ptr);
  14705. DEBUG_INFO("status=%d\n",status);
  14706. DEBUG_INFO("End Response ..\n");
  14707. return (bytes_received>0)?status:0;
  14708. }
  14709. //the only filed that it parsed is 'Content-Length'
  14710. int ParseHeader(int sock)
  14711. {
  14712. //char c;
  14713. char buff[1024]="",*ptr=buff+4;
  14714. int bytes_received;
  14715. DEBUG_INFO("Begin HEADER ..\n");
  14716. while((bytes_received = recv(sock, ptr, 1, 0))){
  14717. if(bytes_received==-1){
  14718. perror("Parse Header");
  14719. exit(1);
  14720. }
  14721. if(
  14722. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14723. (ptr[-1]=='\r') && (*ptr=='\n' )
  14724. ) break;
  14725. ptr++;
  14726. }
  14727. *ptr=0;
  14728. ptr=buff+4;
  14729. //printf("%s",ptr);
  14730. if(bytes_received){
  14731. ptr=strstr(ptr,"Content-Length:");
  14732. if(ptr){
  14733. sscanf(ptr,"%*s %d",&bytes_received);
  14734. }else
  14735. bytes_received=-1; //unknown size
  14736. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14737. }
  14738. DEBUG_INFO("End HEADER ..\n");
  14739. return bytes_received ;
  14740. }
  14741. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14742. {
  14743. int result = TRUE;
  14744. char rmFileCmd[100]={0};
  14745. char FilePath[100]={0};
  14746. char ftpbuf[200];
  14747. int systemresult;
  14748. //DEBUG_INFO("filename=%s\n",filename);
  14749. //DEBUG_INFO("url=%s\n",url);
  14750. sprintf(FilePath,"/mnt/%s",filename);
  14751. system("ping 8.8.8.8 &");
  14752. if((access(FilePath,F_OK))!=-1)
  14753. {
  14754. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14755. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14756. system(rmFileCmd);
  14757. }
  14758. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14759. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14760. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14761. systemresult = system(ftpbuf);
  14762. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14763. if(systemresult != 0)
  14764. {
  14765. DEBUG_INFO("http DownLoad error!\n");
  14766. result = FALSE;
  14767. }
  14768. system("pkill ping");
  14769. return result;
  14770. }
  14771. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14772. {
  14773. int result = TRUE;
  14774. char rmFileCmd[100]={0};
  14775. char FilePath[100]={0};
  14776. char ftpbuf[200];
  14777. int systemresult;
  14778. //char temp[100];
  14779. sprintf(FilePath,"/mnt/%s",filename);
  14780. system("ping 8.8.8.8 &");
  14781. if((access(FilePath,F_OK))!=-1)
  14782. {
  14783. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14784. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14785. system(rmFileCmd);
  14786. }
  14787. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14788. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14789. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14790. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14791. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14792. systemresult = system(ftpbuf);
  14793. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14794. if(systemresult != 0)
  14795. {
  14796. DEBUG_WARN("wget error!\n");
  14797. result = FALSE;
  14798. }
  14799. system("pkill ping");
  14800. return result;
  14801. }
  14802. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14803. {
  14804. char rmFileCmd[100]={0};
  14805. char FilePath[100]={0};
  14806. char buf[512];
  14807. int systemresult = 0;
  14808. //DEBUG_INFO("filename=%s\n",filename);
  14809. //DEBUG_INFO("url=%s\n",url);
  14810. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14811. if((access(FilePath,F_OK))!=-1)
  14812. {
  14813. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14814. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14815. system(rmFileCmd);
  14816. }
  14817. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14818. if(fp == NULL)
  14819. {
  14820. DEBUG_INFO("log is NULL\n");
  14821. return FALSE;
  14822. }
  14823. else
  14824. {
  14825. fprintf(fp, "%s\n", url);
  14826. fprintf(fp, "%s\n", filename);
  14827. fclose(fp);
  14828. }
  14829. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14830. if(phpFP == NULL)
  14831. {
  14832. DEBUG_INFO("PHP upload fail.\n");
  14833. return FALSE;
  14834. }
  14835. else
  14836. {
  14837. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14838. {
  14839. if(strstr(buf, "result") != NULL)
  14840. {
  14841. sscanf(buf, "result: %d", &systemresult);
  14842. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14843. }
  14844. }
  14845. pclose(phpFP);
  14846. }
  14847. if(systemresult != 1)
  14848. {
  14849. DEBUG_INFO("HTTP upload error!\n");
  14850. return FALSE;
  14851. }
  14852. return TRUE;
  14853. }
  14854. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14855. {
  14856. struct hostent* server;
  14857. char *IPbuffer;
  14858. char ftpbuf[200];
  14859. int systemresult;
  14860. // To retrieve host information
  14861. server = gethostbyname(location);
  14862. // To convert an Internet network
  14863. // address into ASCII string
  14864. IPbuffer = inet_ntoa(*((struct in_addr*)
  14865. server->h_addr_list[0]));
  14866. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14867. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14868. /* format : ftpput -u username -p passwd IP target source*/
  14869. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14870. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14871. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14872. systemresult = system(ftpbuf);
  14873. DEBUG_INFO("systemresult=%d\n",systemresult);
  14874. if(systemresult != 0)
  14875. {
  14876. DEBUG_INFO("ftpput error!\n");
  14877. return FALSE;
  14878. }
  14879. return TRUE;
  14880. }
  14881. int GetOcppServerURL()
  14882. {
  14883. int result = FALSE;
  14884. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14885. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14886. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14887. struct yuarel url;
  14888. char urlStr[512];
  14889. // OCPPPH only
  14890. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  14891. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14892. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  14893. {
  14894. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  14895. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14896. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14897. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  14898. if(yuarel_parse(&url, urlStr) != -1)
  14899. {
  14900. sprintf(OcppProtocol, "%s", url.scheme);
  14901. sprintf(OcppHost, "%s", url.host);
  14902. if(url.path == NULL)
  14903. OcppTempPath[0] = '\0';
  14904. else
  14905. sprintf(OcppTempPath, "%s", url.path);
  14906. if(url.port == 0)
  14907. {
  14908. if(strcmp(OcppProtocol, "wss") == 0)
  14909. OcppPort = 443;
  14910. else
  14911. OcppPort = 80;
  14912. }
  14913. else
  14914. OcppPort = url.port;
  14915. result = TRUE;
  14916. }
  14917. }
  14918. else
  14919. {
  14920. strcpy(OcppHost,"");
  14921. }
  14922. return result;
  14923. }
  14924. int GetOcppPath()
  14925. {
  14926. int result = FALSE;
  14927. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  14928. {
  14929. if(OcppTempPath == NULL)
  14930. {
  14931. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  14932. }
  14933. else
  14934. {
  14935. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  14936. }
  14937. result = TRUE;
  14938. goto End;
  14939. }
  14940. else
  14941. {
  14942. strcpy(OcppPath,"");
  14943. }
  14944. End:
  14945. return result;
  14946. }
  14947. int GetOcppPort()
  14948. {
  14949. return OcppPort;
  14950. }
  14951. int GetOcppConnStatus(void)
  14952. {
  14953. return ShmOCPP16DataPH->OcppConnStatus;
  14954. }
  14955. void SetOcppConnStatus(uint8_t status)
  14956. {
  14957. ShmOCPP16DataPH->OcppConnStatus = status;
  14958. }
  14959. int GetHeartBeatWithNOResponse(void)
  14960. {
  14961. return HeartBeatWithNOResponse;
  14962. }
  14963. void SetHeartBeatWithNOResponse(void)
  14964. {
  14965. HeartBeatWithNOResponse = 0;
  14966. }
  14967. void GetStartTransactionIdTag(int gun_index)
  14968. {
  14969. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14970. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14971. }
  14972. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14973. {
  14974. char ch;
  14975. FILE *fptr1;
  14976. int temptransactionId;
  14977. char str[100]={0};
  14978. temptransactionId = 0;
  14979. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14980. {
  14981. DEBUG_INFO("IdTag is empty.\n");
  14982. return temptransactionId;
  14983. }
  14984. /*------ Read the file ----------------*/
  14985. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  14986. if (!fptr1)
  14987. {
  14988. DEBUG_INFO("QueueTransactionId file open error.\n");
  14989. //printf(" File not found or unable to open the input file!!\n");
  14990. return temptransactionId;
  14991. }
  14992. ch=fgetc(fptr1);
  14993. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  14994. rewind(fptr1);
  14995. if(ch!=EOF)
  14996. {
  14997. // printf("%c",ch);
  14998. while (fgets(str, 100, fptr1) != NULL)
  14999. {
  15000. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15001. if(str[0]=='\0')
  15002. {
  15003. break;
  15004. }
  15005. char *revbuf[8] = {0}; // Variable store string split
  15006. int num = 0;// Quantity after string split
  15007. DEBUG_INFO("Transaction queue data= %s\n", str);
  15008. splitstring(str,",",revbuf,&num); // String split
  15009. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15010. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15011. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15012. DEBUG_INFO("------------------------------\n");
  15013. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15014. {
  15015. if(isStopTransaction)
  15016. {
  15017. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15018. {
  15019. temptransactionId = atoi(revbuf[2]);
  15020. //break;
  15021. }
  15022. }
  15023. else
  15024. {
  15025. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15026. {
  15027. temptransactionId = atoi(revbuf[2]);
  15028. //break;
  15029. }
  15030. }
  15031. }
  15032. }
  15033. }
  15034. else
  15035. DEBUG_INFO("EOF\n");
  15036. fclose(fptr1);
  15037. /*------- End of reading ---------------*/
  15038. return temptransactionId;
  15039. }
  15040. void SetTransactionIdZero(int transactionId)
  15041. {
  15042. char ch;
  15043. FILE *fptr1, *fptr2;
  15044. int temptransactionId = 0;
  15045. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  15046. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  15047. if (!fptr1)
  15048. {
  15049. //printf(" File not found or unable to open the input file!!\n");
  15050. return ;
  15051. }
  15052. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15053. if (!fptr2)
  15054. {
  15055. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15056. fclose(fptr1);
  15057. return ;
  15058. }
  15059. ch=fgetc(fptr1);
  15060. rewind(fptr1);
  15061. if(ch!=EOF)
  15062. {
  15063. // copy all contents to the temporary file except the specific line
  15064. while (fgets(str, 100, fptr1) != NULL)
  15065. {
  15066. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15067. if(str[0]=='\0')
  15068. {
  15069. break;
  15070. }
  15071. char *revbuf[8] = {0};
  15072. int num = 0;
  15073. strcpy(strtemp, str);
  15074. splitstring(str,",",revbuf,&num);
  15075. if(revbuf[2][0] != '\0')
  15076. {
  15077. temptransactionId = atoi(revbuf[2]);
  15078. if(transactionId != temptransactionId)
  15079. {
  15080. fprintf(fptr2, "%s\n", strtemp);
  15081. }
  15082. }
  15083. }
  15084. }
  15085. fclose(fptr1);
  15086. fclose(fptr2);
  15087. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  15088. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  15089. /*------ Read the file ----------------*/
  15090. }
  15091. int InternetDisconnect(void)
  15092. {
  15093. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15094. }
  15095. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15096. void storeTempStopTransaction(int gun_index)
  15097. {
  15098. char guid[37]={0};
  15099. int tempIndex = 0;
  15100. char TempStopTransaction[256];
  15101. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15102. DEBUG_INFO("storeTempStopTransaction...\n");
  15103. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15104. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  15105. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15106. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15107. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15108. {
  15109. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15110. {
  15111. tempIndex = ((gun_index==2) ? 1: 0);
  15112. }
  15113. else
  15114. {
  15115. tempIndex = gun_index;
  15116. }
  15117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15118. {
  15119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15120. {
  15121. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15122. }
  15123. }// END OF CHAdeMO_QUANTITY
  15124. }
  15125. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15126. {
  15127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15128. {
  15129. tempIndex = ((gun_index==2) ? 1: 0);
  15130. }
  15131. else
  15132. {
  15133. tempIndex = gun_index;
  15134. }
  15135. for (int index = 0; index < CCS_QUANTITY; index++)
  15136. {
  15137. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15138. {
  15139. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15140. }
  15141. }// END OF CCS_QUANTITY
  15142. }
  15143. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15144. {
  15145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15146. {
  15147. tempIndex = ((gun_index==2) ? 1: 0);
  15148. }
  15149. else
  15150. {
  15151. tempIndex = gun_index;
  15152. }
  15153. for (int index = 0; index < GB_QUANTITY; index++)
  15154. {
  15155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15156. {
  15157. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15158. }
  15159. }// END OF GB_QUANTITY
  15160. }
  15161. else if(gunType[gun_index] == GUN_TYPE_DO)
  15162. {
  15163. tempIndex = gun_index;
  15164. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15165. {
  15166. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15167. {
  15168. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15169. }
  15170. }
  15171. }
  15172. else
  15173. {
  15174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15175. {
  15176. tempIndex = 2;
  15177. }
  15178. else
  15179. {
  15180. tempIndex = gun_index;
  15181. }
  15182. for (int index = 0; index < AC_QUANTITY; index++)
  15183. {
  15184. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15185. {
  15186. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15187. }
  15188. }// END OF AC_QUANTITY
  15189. }
  15190. //Stop Transaction Time
  15191. struct timeval tmnow;
  15192. struct tm *tm;
  15193. char buf[28];//, usec_buf[6];
  15194. gettimeofday(&tmnow, NULL);
  15195. time_t t;
  15196. t = time(NULL);
  15197. /*UTC time and date*/
  15198. tm = gmtime(&t);
  15199. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  15201. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  15202. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15203. random_uuid(guid);
  15204. /***********************************transactionData******************************************************/
  15205. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15206. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15207. //=================================
  15208. //1. Transaction_Begin
  15209. //=================================
  15210. //============================== Energy.Active.Import.Interval ===========================================
  15211. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15212. {
  15213. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15216. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  15217. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15218. 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))
  15219. {
  15220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15221. }
  15222. else
  15223. {
  15224. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15225. }
  15226. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15227. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15228. }
  15229. //=================================
  15230. //2. Transaction_End
  15231. //=================================
  15232. //2.1====================================== Current.Import L1 ==============================================
  15233. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15234. {
  15235. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15236. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15237. {
  15238. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15239. {
  15240. tempIndex = ((gun_index==2) ? 1: 0);
  15241. }
  15242. else
  15243. {
  15244. tempIndex = gun_index;
  15245. }
  15246. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15247. {
  15248. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15249. {
  15250. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15251. }
  15252. }// End of for CHAdeMO_QUANTITY
  15253. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15254. }
  15255. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15256. {
  15257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15258. {
  15259. tempIndex = ((gun_index==2) ? 1: 0);
  15260. }
  15261. else
  15262. {
  15263. tempIndex = gun_index;
  15264. }
  15265. for (int index = 0; index < CCS_QUANTITY; index++)
  15266. {
  15267. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15268. {
  15269. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15270. }
  15271. }// End of for CCS_QUANTITY
  15272. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15273. }
  15274. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15275. {
  15276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15277. {
  15278. tempIndex = ((gun_index==2) ? 1: 0);
  15279. }
  15280. else
  15281. {
  15282. tempIndex = gun_index;
  15283. }
  15284. for (int index = 0; index < GB_QUANTITY; index++)
  15285. {
  15286. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15287. {
  15288. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15289. }
  15290. }// End of for GB_QUANTITY
  15291. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15292. }
  15293. else if(gunType[gun_index] == GUN_TYPE_DO)
  15294. {
  15295. tempIndex = gun_index;
  15296. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15297. {
  15298. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15299. {
  15300. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15301. }
  15302. }
  15303. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15304. }
  15305. else
  15306. {
  15307. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15308. {
  15309. tempIndex = 2;
  15310. }
  15311. else
  15312. {
  15313. tempIndex = gun_index;
  15314. }
  15315. for (int index = 0; index < AC_QUANTITY; index++)
  15316. {
  15317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15318. {
  15319. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15320. }
  15321. }// End of for AC_QUANTITY
  15322. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15323. }
  15324. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15325. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15326. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15327. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15328. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15329. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15330. }
  15331. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15332. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15333. {
  15334. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15335. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15336. {
  15337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15338. {
  15339. tempIndex = ((gun_index==2) ? 1: 0);
  15340. }
  15341. else
  15342. {
  15343. tempIndex = gun_index;
  15344. }
  15345. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15346. {
  15347. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15348. {
  15349. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15350. }
  15351. }// END OF CHAdeMO_QUANTITY
  15352. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15353. }
  15354. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15355. {
  15356. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15357. {
  15358. tempIndex = ((gun_index==2) ? 1: 0);
  15359. }
  15360. else
  15361. {
  15362. tempIndex = gun_index;
  15363. }
  15364. for (int index = 0; index < CCS_QUANTITY; index++)
  15365. {
  15366. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15367. {
  15368. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15369. }
  15370. }// END OF CCS_QUANTITY
  15371. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15372. }
  15373. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15374. {
  15375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15376. {
  15377. tempIndex = ((gun_index==2) ? 1: 0);
  15378. }
  15379. else
  15380. {
  15381. tempIndex = gun_index;
  15382. }
  15383. for (int index = 0; index < GB_QUANTITY; index++)
  15384. {
  15385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15386. {
  15387. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15388. }
  15389. }// END OF GB_QUANTITY
  15390. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15391. }
  15392. else if(gunType[gun_index] == GUN_TYPE_DO)
  15393. {
  15394. tempIndex = gun_index;
  15395. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15396. {
  15397. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15398. {
  15399. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15400. }
  15401. }
  15402. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15403. }
  15404. else
  15405. {
  15406. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15407. {
  15408. tempIndex = 2;
  15409. }
  15410. else
  15411. {
  15412. tempIndex = gun_index;
  15413. }
  15414. for (int index = 0; index < AC_QUANTITY; index++)
  15415. {
  15416. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15417. {
  15418. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15419. }
  15420. }// END OF AC_QUANTITY
  15421. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15422. }
  15423. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15424. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15425. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15426. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15427. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15428. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15429. }
  15430. //2.3====================================== Power.Active.Import =========================================
  15431. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15432. {
  15433. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15434. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15435. {
  15436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15437. {
  15438. tempIndex = ((gun_index==2) ? 1: 0);
  15439. }
  15440. else
  15441. {
  15442. tempIndex = gun_index;
  15443. }
  15444. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15445. {
  15446. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15447. {
  15448. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15449. }
  15450. } // End for CHAdeMO_QUANTITY
  15451. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15452. }
  15453. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15454. {
  15455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15456. {
  15457. tempIndex = ((gun_index==2) ? 1: 0);
  15458. }
  15459. else
  15460. {
  15461. tempIndex = gun_index;
  15462. }
  15463. for (int index = 0; index < CCS_QUANTITY; index++)
  15464. {
  15465. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15466. {
  15467. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15468. }
  15469. } // END for CCS_QUANTITY
  15470. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15471. }
  15472. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15473. {
  15474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15475. {
  15476. tempIndex = ((gun_index==2) ? 1: 0);
  15477. }
  15478. else
  15479. {
  15480. tempIndex = gun_index;
  15481. }
  15482. for (int index = 0; index < GB_QUANTITY; index++)
  15483. {
  15484. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15485. {
  15486. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15487. }
  15488. }// END for GB_QUANTITY
  15489. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15490. }
  15491. else if(gunType[gun_index] == GUN_TYPE_DO)
  15492. {
  15493. tempIndex = gun_index;
  15494. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15495. {
  15496. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15497. {
  15498. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15499. }
  15500. }
  15501. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15502. }
  15503. else
  15504. {
  15505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15506. {
  15507. tempIndex = 2;
  15508. }
  15509. else
  15510. {
  15511. tempIndex = gun_index;
  15512. }
  15513. for (int index = 0; index < AC_QUANTITY; index++)
  15514. {
  15515. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15516. {
  15517. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15518. }
  15519. } // END for AC_QUANTITY
  15520. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15521. }
  15522. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15523. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15524. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15525. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15526. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15527. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15528. }
  15529. //2.4====================================== Voltage L1 ====================================================
  15530. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15531. {
  15532. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15533. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15534. {
  15535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15536. {
  15537. tempIndex = ((gun_index==2) ? 1: 0);
  15538. }
  15539. else
  15540. {
  15541. tempIndex = gun_index;
  15542. }
  15543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15544. {
  15545. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15546. {
  15547. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15548. }
  15549. } // END OF FOR CHAdeMO_QUANTITY
  15550. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15551. }
  15552. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15553. {
  15554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15555. {
  15556. tempIndex = ((gun_index==2) ? 1: 0);
  15557. }
  15558. else
  15559. {
  15560. tempIndex = gun_index;
  15561. }
  15562. for (int index = 0; index < CCS_QUANTITY; index++)
  15563. {
  15564. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15565. {
  15566. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15567. }
  15568. } // END OF FOR CCS_QUANTITY
  15569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15570. }
  15571. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15572. {
  15573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15574. {
  15575. tempIndex = ((gun_index==2) ? 1: 0);
  15576. }
  15577. else
  15578. {
  15579. tempIndex = gun_index;
  15580. }
  15581. for (int index = 0; index < GB_QUANTITY; index++)
  15582. {
  15583. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15584. {
  15585. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15586. }
  15587. } // END OF FOR GB_QUANTITY
  15588. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15589. }
  15590. else if(gunType[gun_index] == GUN_TYPE_DO)
  15591. {
  15592. tempIndex = gun_index;
  15593. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15594. {
  15595. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15596. {
  15597. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15598. }
  15599. }
  15600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15601. }
  15602. else
  15603. {
  15604. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15605. {
  15606. tempIndex = 2;
  15607. }
  15608. else
  15609. {
  15610. tempIndex = gun_index;
  15611. }
  15612. for (int index = 0; index < AC_QUANTITY; index++)
  15613. {
  15614. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15615. {
  15616. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15617. }
  15618. } // END OF FOR AC_QUANTITY
  15619. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15620. }
  15621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15622. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15624. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15627. }
  15628. //2.5============================================== End SoC =========================================================
  15629. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15630. {
  15631. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15632. 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))
  15633. {
  15634. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15635. {
  15636. tempIndex = ((gun_index==2) ? 1: 0);
  15637. }
  15638. else
  15639. {
  15640. tempIndex = gun_index;
  15641. }
  15642. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15643. {
  15644. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15645. {
  15646. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15647. {
  15648. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15649. }
  15650. }
  15651. }
  15652. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15653. {
  15654. for (int index = 0; index < CCS_QUANTITY; index++)
  15655. {
  15656. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15657. {
  15658. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15659. }
  15660. }
  15661. }
  15662. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15663. {
  15664. for (int index = 0; index < GB_QUANTITY; index++)
  15665. {
  15666. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15667. {
  15668. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15669. }
  15670. }
  15671. }
  15672. else if(gunType[gun_index] == GUN_TYPE_DO)
  15673. {
  15674. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15675. {
  15676. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15677. {
  15678. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15679. }
  15680. }
  15681. }
  15682. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15688. } // END FOR DC CASE
  15689. }
  15690. //2.6====================================== Current.Import L2 ==============================================
  15691. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15692. {
  15693. // AC 3 phase L2 current
  15694. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15695. {
  15696. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15697. {
  15698. tempIndex = 2;
  15699. }
  15700. else
  15701. {
  15702. tempIndex = gun_index;
  15703. }
  15704. for (int index = 0; index < AC_QUANTITY; index++)
  15705. {
  15706. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15707. {
  15708. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15709. }
  15710. }// End of for AC_QUANTITY
  15711. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15712. }
  15713. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15714. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15716. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15717. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15718. }
  15719. //2.7====================================== Current.Import L3 ==============================================
  15720. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15721. {
  15722. // AC 3 phase L3 current
  15723. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15724. {
  15725. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15726. {
  15727. tempIndex = 2;
  15728. }
  15729. else
  15730. {
  15731. tempIndex = gun_index;
  15732. }
  15733. for (int index = 0; index < AC_QUANTITY; index++)
  15734. {
  15735. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15736. {
  15737. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15738. }
  15739. }// End of for AC_QUANTITY
  15740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15741. }
  15742. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15744. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15747. }
  15748. //2.9====================================== Voltage L2 ====================================================
  15749. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15750. {
  15751. // AC 3 phase L2 volatge
  15752. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15753. {
  15754. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15755. {
  15756. tempIndex = 2;
  15757. }
  15758. else
  15759. {
  15760. tempIndex = gun_index;
  15761. }
  15762. for (int index = 0; index < AC_QUANTITY; index++)
  15763. {
  15764. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15765. {
  15766. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15767. }
  15768. } // END OF FOR AC_QUANTITY
  15769. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15770. }
  15771. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15772. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15773. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15774. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15775. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15776. }
  15777. //2.10====================================== Voltage L3 ====================================================
  15778. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15779. {
  15780. // AC 3 phase L3 volatge
  15781. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15782. {
  15783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15784. {
  15785. tempIndex = 2;
  15786. }
  15787. else
  15788. {
  15789. tempIndex = gun_index;
  15790. }
  15791. for (int index = 0; index < AC_QUANTITY; index++)
  15792. {
  15793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15794. {
  15795. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  15796. }
  15797. } // END OF FOR AC_QUANTITY
  15798. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15799. }
  15800. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15801. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15802. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15804. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15805. }
  15806. //====================== Start SoC ================================
  15807. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15808. {
  15809. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15810. 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))
  15811. {
  15812. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15813. {
  15814. tempIndex = ((gun_index==2) ? 1: 0);
  15815. }
  15816. else
  15817. {
  15818. tempIndex = gun_index;
  15819. }
  15820. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15821. {
  15822. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15823. {
  15824. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15825. {
  15826. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15827. }
  15828. }
  15829. }
  15830. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15831. {
  15832. for (int index = 0; index < CCS_QUANTITY; index++)
  15833. {
  15834. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15835. {
  15836. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15837. }
  15838. }
  15839. }
  15840. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15841. {
  15842. for (int index = 0; index < GB_QUANTITY; index++)
  15843. {
  15844. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15845. {
  15846. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15847. }
  15848. }
  15849. }
  15850. else if(gunType[gun_index] == GUN_TYPE_DO)
  15851. {
  15852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15853. {
  15854. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15855. {
  15856. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15857. }
  15858. }
  15859. }
  15860. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15861. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15862. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15863. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15864. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15865. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15866. } // END FOR DC CASE
  15867. }
  15868. //======================================== Message create ==============================================
  15869. json_object *StopTransaction = json_object_new_object();
  15870. json_object *transactionDatas = json_object_new_array();
  15871. json_object *sampledValues = json_object_new_array();
  15872. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  15873. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  15874. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  15875. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  15876. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  15877. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15878. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  15879. {
  15880. json_object *transactionData = json_object_new_object();
  15881. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15882. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15883. {
  15884. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15885. {
  15886. json_object *sampledValue = json_object_new_object();
  15887. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15888. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15889. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15890. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15891. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15892. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15893. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15894. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15895. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15896. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15897. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15898. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15899. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15900. json_object_array_add(sampledValues, sampledValue);
  15901. }
  15902. }
  15903. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15904. json_object_array_add(transactionDatas, transactionData);
  15905. }
  15906. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15907. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15908. ,MESSAGE_TYPE_CALL
  15909. ,guid
  15910. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15911. json_object_put(StopTransaction);
  15912. // Check File "TempStopTransaction" Exist
  15913. if((access(TempStopTransaction,F_OK))!=-1)
  15914. {
  15915. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15916. fclose(fopen(TempStopTransaction, "w"));
  15917. }
  15918. else
  15919. {
  15920. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15921. FILE *log = fopen(TempStopTransaction, "w+");
  15922. if(log == NULL)
  15923. {
  15924. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15925. return ;
  15926. }
  15927. else
  15928. {
  15929. fclose(log);
  15930. }
  15931. }
  15932. //Add TempStopTransaction | Update TempStopTransaction
  15933. // open file for writing
  15934. FILE *outfile;
  15935. outfile = fopen (TempStopTransaction, "a");
  15936. //DEBUG_INFO("data = %s\n", queuedata);
  15937. fputs(queuedata, outfile);
  15938. fputs("\n", outfile);
  15939. fclose (outfile);
  15940. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15941. }
  15942. void checkTempStopTransaction(int gun_index)
  15943. {
  15944. FILE *fptr1;
  15945. char ch;
  15946. char str[QUEUE_MESSAGE_LENGTH]={0};
  15947. char guid[37]={0};
  15948. char tempdata[65]={0};
  15949. char connectorStr[2]={0};
  15950. char TempStopTransaction[256];
  15951. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15952. fptr1 = fopen(TempStopTransaction, "r");
  15953. //TempStopTransaction格式: 槍號,StopTransaction封包
  15954. if (!fptr1)
  15955. {
  15956. //printf(" File not found or unable to open the input file!!\n");
  15957. return ;
  15958. }
  15959. ch=fgetc(fptr1);
  15960. //printf(" Now the content of the file %s is : \n",fname);
  15961. rewind(fptr1);
  15962. if(ch!=EOF)
  15963. {
  15964. // copy all contents to the temporary file except the specific line
  15965. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15966. {
  15967. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15968. if(str[0]=='\0')
  15969. {
  15970. break;
  15971. }
  15972. //TempStopTransaction格式: 槍號,StopTransaction封包
  15973. strncpy(connectorStr, str, 1);
  15974. if(atoi(connectorStr) != (gun_index+1))
  15975. {
  15976. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15977. fclose(fptr1);
  15978. return ;
  15979. }
  15980. //random_uuid(guid);
  15981. strncpy(guid, str+6, 36); //copy guid
  15982. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15983. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15984. {
  15985. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15986. }
  15987. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15988. OCPP_insert_transaction_msg(NO, str);
  15989. memset(str,0,ARRAY_SIZE(str));
  15990. }
  15991. }
  15992. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15993. fclose(fptr1);
  15994. remove(TempStopTransaction); // remove the original file
  15995. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15996. }
  15997. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15998. {
  15999. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16000. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16001. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16002. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16003. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16004. }
  16005. int GetWebSocketPingInterval(void)
  16006. {
  16007. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16008. }
  16009. int GetServerSign(void)
  16010. {
  16011. return server_sign;
  16012. }
  16013. uint8_t GetOcppSecurityProfile()
  16014. {
  16015. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16016. }
  16017. void GetOcppChargerBoxId(uint8_t *data)
  16018. {
  16019. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  16020. }
  16021. void GetOcppSecurityPassword(uint8_t *data)
  16022. {
  16023. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16024. }
  16025. void SetOcppVersion(uint8_t *version)
  16026. {
  16027. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16028. DEBUG_INFO("ocpp version: %s\n", version);
  16029. if(strstr((char*)version, "ocpp1.6") != NULL)
  16030. {
  16031. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16032. }
  16033. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16034. {
  16035. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16036. system("pkill OcppBackend");
  16037. }
  16038. }
  16039. void SetServerSign(int value)
  16040. {
  16041. server_sign = value;
  16042. }
  16043. int GetBootNotificationInterval(void)
  16044. {
  16045. return BootNotificationInterval;
  16046. }
  16047. int GetInternetConn(void)
  16048. {
  16049. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16050. }
  16051. int GetBackendConnectionTimeout(void)
  16052. {
  16053. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16054. }
  16055. int isConnectorInitMode(int gun_index)
  16056. {
  16057. int tempIndex = 0;
  16058. int result = TRUE;
  16059. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16060. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16061. {
  16062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16063. {
  16064. tempIndex = ((gun_index==2) ? 1: 0);
  16065. }
  16066. else
  16067. {
  16068. tempIndex = gun_index;
  16069. }
  16070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16071. {
  16072. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16073. {
  16074. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16075. } //end of the same index
  16076. }//end of for CHAdeMO_QUANTITY
  16077. }
  16078. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16079. {
  16080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16081. {
  16082. tempIndex = ((gun_index==2) ? 1: 0);
  16083. }
  16084. else
  16085. {
  16086. tempIndex = gun_index;
  16087. }
  16088. for (int index = 0; index < CCS_QUANTITY; index++)
  16089. {
  16090. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16091. {
  16092. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16093. } //end of the same index
  16094. } // end of for CCS_QUANTITY
  16095. }
  16096. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16097. {
  16098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16099. {
  16100. tempIndex = ((gun_index==2) ? 1: 0);
  16101. }
  16102. else
  16103. {
  16104. tempIndex = gun_index;
  16105. }
  16106. for (int index = 0; index < GB_QUANTITY; index++)
  16107. {
  16108. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16109. {
  16110. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16111. } //end of the same index
  16112. } // end of for GB_QUANTITY
  16113. }
  16114. else if(gunType[gun_index] == GUN_TYPE_DO)
  16115. {
  16116. tempIndex = gun_index;
  16117. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16118. {
  16119. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16120. {
  16121. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16122. } //end of the same index
  16123. }
  16124. }
  16125. else
  16126. {
  16127. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16128. {
  16129. tempIndex = 2;
  16130. }
  16131. else
  16132. {
  16133. tempIndex = gun_index;
  16134. }
  16135. for (int index = 0; index < AC_QUANTITY; index++)
  16136. {
  16137. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16138. {
  16139. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16140. }//end of the same index
  16141. }//end of for AC_QUANTITY
  16142. }
  16143. return result;
  16144. }
  16145. void refreshProcDogTimer()
  16146. {
  16147. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  16148. }
  16149. void InitialSystemValue(void)
  16150. {
  16151. int connectorIndex = 0;
  16152. //int valueASCII = 0;
  16153. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16154. gunTotalNumber=0;
  16155. SystemInitial = 0;
  16156. locallistVersion=0;
  16157. BootNotificationInterval = 0;
  16158. authorizeRetryTimes = 0;
  16159. GunStatusInterval = 10;
  16160. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16161. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16162. //Hear Beat
  16163. HeartBeatWithNOResponse = 0;
  16164. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16165. FirstHeartBeat = 0;
  16166. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16167. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16168. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16169. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16170. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16171. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16172. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16173. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16174. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16175. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16176. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16177. memset(gunType, 0, ARRAY_SIZE(gunType));
  16178. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16179. {
  16180. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16181. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16182. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16183. {
  16184. // DO series
  16185. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16186. {
  16187. SystemInitial = SystemInitial + 1;
  16188. gunTotalNumber = gunTotalNumber + 1;
  16189. gunType[connectorIndex] = GUN_TYPE_DO;
  16190. connectorIndex = connectorIndex + 1;
  16191. }
  16192. }
  16193. else
  16194. {
  16195. // DM, DW, DS series
  16196. //check connector / socket type (index: 8, 9, 10)
  16197. for(int index=7; index <10 ; index++)
  16198. {
  16199. if(index != 8)
  16200. {
  16201. // DC Connector
  16202. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16203. {
  16204. SystemInitial = SystemInitial + 1;
  16205. gunTotalNumber = gunTotalNumber + 1;
  16206. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16207. connectorIndex = connectorIndex + 1;
  16208. }
  16209. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16210. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16211. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16212. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16213. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16214. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16215. {
  16216. SystemInitial = SystemInitial + 1;
  16217. gunTotalNumber = gunTotalNumber + 1;
  16218. gunType[connectorIndex] = GUN_TYPE_CCS;
  16219. connectorIndex = connectorIndex + 1;
  16220. }
  16221. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16222. {
  16223. SystemInitial = SystemInitial + 1;
  16224. gunTotalNumber = gunTotalNumber + 1;
  16225. gunType[connectorIndex] = GUN_TYPE_GBT;
  16226. connectorIndex = connectorIndex + 1;
  16227. }
  16228. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16229. {
  16230. SystemInitial = SystemInitial + 1;
  16231. gunTotalNumber = gunTotalNumber + 1;
  16232. gunType[connectorIndex] = GUN_TYPE_DO;
  16233. connectorIndex = connectorIndex + 1;
  16234. }
  16235. }
  16236. else
  16237. {
  16238. // AC Connector
  16239. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16240. {
  16241. SystemInitial = SystemInitial + 1;
  16242. gunTotalNumber = gunTotalNumber + 1;
  16243. gunType[connectorIndex] = GUN_TYPE_AC;
  16244. connectorIndex = connectorIndex + 1;
  16245. }
  16246. }
  16247. }
  16248. }
  16249. //DEBUG_INFO("DC ...\n");
  16250. }
  16251. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16252. {
  16253. //check connector / socket type (index: 8, 9, 10)
  16254. for(int index=7; index <10 ; index++)
  16255. {
  16256. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16257. {
  16258. SystemInitial = SystemInitial + 1;
  16259. gunTotalNumber = gunTotalNumber + 1;
  16260. gunType[connectorIndex] = GUN_TYPE_AC;
  16261. connectorIndex = connectorIndex + 1;
  16262. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16263. }
  16264. }
  16265. }
  16266. //Status && ConnectorPlugIn Setting
  16267. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16268. {
  16269. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16270. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16271. }
  16272. for (int index = 0; index < CCS_QUANTITY; index++)
  16273. {
  16274. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16275. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16276. }
  16277. for (int index = 0; index < GB_QUANTITY; index++)
  16278. {
  16279. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16280. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16281. }
  16282. for (int index = 0; index < AC_QUANTITY; index++)
  16283. {
  16284. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16285. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16286. }
  16287. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16288. {
  16289. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16290. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16291. }
  16292. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16293. {
  16294. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16295. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16296. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16297. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16298. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16299. }
  16300. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16301. clientTime.Heartbeat=time((time_t*)NULL);
  16302. sleep(1);
  16303. }
  16304. void LWS_Send(char *str)
  16305. {
  16306. //=====================================================
  16307. // Check InternetConn 0: disconnected, 1: connected
  16308. //====================================================
  16309. if(GetOcppConnStatus() == 0)
  16310. {
  16311. DEBUG_INFO("offline now !!!\n");
  16312. return;
  16313. }
  16314. // Only disable isWebsocketSendable operation initiated by charger
  16315. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16316. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16317. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16318. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16319. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16320. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16321. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16322. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16323. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16324. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16325. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16326. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16327. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16328. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16329. {
  16330. isWebsocketSendable = 0;
  16331. }
  16332. pthread_mutex_lock(&lock_send);
  16333. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16334. sprintf((char *)SendBuffer, "%s", str);
  16335. SendBufLen = strlen(str);
  16336. pthread_mutex_unlock(&lock_send);
  16337. lws_callback_on_writable(wsi_client);
  16338. //lws_service(context, 0);
  16339. //sleep(1);
  16340. }
  16341. void LWS_SendNow(char *str)
  16342. {
  16343. //=====================================================
  16344. // Check InternetConn 0: disconnected, 1: connected
  16345. //====================================================
  16346. if(GetOcppConnStatus() == 0)
  16347. {
  16348. DEBUG_INFO("offline now !!!\n");
  16349. return;
  16350. }
  16351. // Only disable isWebsocketSendable operation initiated by charger
  16352. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16353. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16354. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16355. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16356. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16357. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16358. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16359. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16360. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16361. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16362. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16363. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16364. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16365. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16366. {
  16367. isWebsocketSendable = 0;
  16368. }
  16369. pthread_mutex_lock(&lock_send);
  16370. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16371. sprintf((char *)SendBuffer, "%s", str);
  16372. SendBufLen = strlen(str);
  16373. pthread_mutex_unlock(&lock_send);
  16374. lws_callback_on_writable(wsi_client);
  16375. lws_service(context, 0);
  16376. //sleep(1);
  16377. }