MessageHandler.c 830 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969
  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 InterLock
  93. {
  94. unsigned char isGetDiagnosticGoing:1;
  95. unsigned char isUpdateFirmwareGoing:1;
  96. }interLock;
  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[1]={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 ParsingResult
  861. {
  862. int result;
  863. int scanedElement;
  864. int year;
  865. int month;
  866. int mday;
  867. int hour;
  868. int min;
  869. int sec;
  870. int tz_hour;
  871. int tz_min;
  872. float minSec;
  873. }parsingResult;
  874. struct tm tmStart;
  875. struct timeb tbStart;
  876. if(strstr((char*)start, ".") != NULL)
  877. {
  878. // Original data with mini second
  879. if(strstr((char*)start, "Z") != NULL)
  880. {
  881. // Original data with Z
  882. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  883. &parsingResult.year,
  884. &parsingResult.month,
  885. &parsingResult.mday,
  886. &parsingResult.hour,
  887. &parsingResult.min,
  888. &parsingResult.sec,
  889. &parsingResult.minSec);
  890. }
  891. else
  892. {
  893. // Original data without Z
  894. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  895. &parsingResult.year,
  896. &parsingResult.month,
  897. &parsingResult.mday,
  898. &parsingResult.hour,
  899. &parsingResult.min,
  900. &parsingResult.sec,
  901. &parsingResult.minSec,
  902. &parsingResult.tz_hour,
  903. &parsingResult.tz_min);
  904. }
  905. }
  906. else
  907. {
  908. // Original data without mini second
  909. if(strstr((char*)start, "Z") != NULL)
  910. {
  911. // Original data with Z
  912. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  913. &parsingResult.year,
  914. &parsingResult.month,
  915. &parsingResult.mday,
  916. &parsingResult.hour,
  917. &parsingResult.min,
  918. &parsingResult.sec);
  919. }
  920. else
  921. {
  922. // Original data without Z
  923. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  924. &parsingResult.year,
  925. &parsingResult.month,
  926. &parsingResult.mday,
  927. &parsingResult.hour,
  928. &parsingResult.min,
  929. &parsingResult.sec,
  930. &parsingResult.tz_hour,
  931. &parsingResult.tz_min);
  932. }
  933. }
  934. if(parsingResult.scanedElement >= 6)
  935. {
  936. tmStart.tm_year = parsingResult.year - 1900;
  937. tmStart.tm_mon = parsingResult.month - 1;
  938. tmStart.tm_mday = parsingResult.mday;
  939. tmStart.tm_hour = parsingResult.hour;
  940. tmStart.tm_min = parsingResult.min;
  941. tmStart.tm_sec = parsingResult.sec;
  942. tmStart.tm_gmtoff = 0;
  943. tbStart.time = mktime(&tmStart);
  944. tbStart.timezone = 0;
  945. tbStart.millitm = 0;
  946. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  947. if(DiffTimebWithNowSec(tbStart) <= 0)
  948. result = NO;
  949. else
  950. result = YES;
  951. }
  952. else
  953. {
  954. DEBUG_WARN("Start date parsing error.\n");
  955. }
  956. return result;
  957. }
  958. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  959. {
  960. int result = -1;
  961. struct tm tmStart;
  962. struct timeb tbStart;
  963. struct tm tmStop;
  964. struct timeb tbStop;
  965. 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) &&
  966. (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))
  967. {
  968. tmStart.tm_year -= 1900;
  969. tmStart.tm_mon -= 1;
  970. tbStart.time = mktime(&tmStart);
  971. tbStart.millitm = 0;
  972. tmStop.tm_year -= 1900;
  973. tmStop.tm_mon -= 1;
  974. tbStop.time = mktime(&tmStop);
  975. tbStop.millitm = 0;
  976. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  977. }
  978. return result;
  979. }
  980. void checkChargePointMaxProfile(uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  981. {
  982. FILE *fp;
  983. char profileFileName[128];
  984. char *line = NULL;
  985. size_t len = 0;
  986. time_t CurrentTime;
  987. struct tm *tmComposite;
  988. struct StructChargingProfile maxProfile;
  989. uint8_t limitMax=0;
  990. int compositePeriodIdx = 0;
  991. CurrentTime = time(NULL);
  992. tmComposite=localtime(&CurrentTime);
  993. 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);
  994. if(isUnitA)
  995. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  996. else
  997. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  998. compositeProfile->ChargingSchedule.Duration = durationReq;
  999. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1000. {
  1001. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1002. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1003. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1004. }
  1005. compositeProfile->ChargingProfileId = 0;
  1006. compositeProfile->StackLevel = 99 ;
  1007. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1008. maxProfile.ChargingProfileId = -1;
  1009. maxProfile.ChargingSchedule.Duration = -1;
  1010. system("rm -f /tmp/*.json");
  1011. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1012. // Search max profile
  1013. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1014. if((access(profileFileName, F_OK))!=-1)
  1015. {
  1016. fp = fopen(profileFileName, "r");
  1017. while(getline(&line, &len, fp) != -1)
  1018. {
  1019. json_object *obj = NULL;
  1020. obj = json_tokener_parse(line);
  1021. if(is_error(obj))
  1022. {
  1023. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1024. }
  1025. else
  1026. {
  1027. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  1028. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1029. )
  1030. {
  1031. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1032. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1033. )
  1034. {
  1035. struct tm tmFrom, tmTo;
  1036. struct timeb tbFrom, tbTo;
  1037. 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) &&
  1038. (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))
  1039. {
  1040. tmFrom.tm_year -= 1900;
  1041. tmFrom.tm_mon -= 1;
  1042. tbFrom.time = mktime(&tmFrom);
  1043. tmTo.tm_year -= 1900;
  1044. tmTo.tm_mon -= 1;
  1045. tbTo.time = mktime(&tmTo);
  1046. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1047. {
  1048. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1049. {
  1050. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1051. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1053. }
  1054. maxProfile.ChargingProfileId = -1;
  1055. maxProfile.StackLevel = -1;
  1056. if(maxProfile.ChargingProfileId == -1)
  1057. DEBUG_INFO("MaxProfile found.\n");
  1058. else
  1059. DEBUG_INFO("MaxProfile updated.\n");
  1060. // Required item
  1061. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1062. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1063. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1064. if(isUnitA)
  1065. {
  1066. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1067. 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++)
  1068. {
  1069. 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"));
  1070. 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?
  1071. 3:
  1072. 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")));
  1073. 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")));
  1074. }
  1075. }
  1076. else
  1077. {
  1078. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1079. 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++)
  1080. {
  1081. 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"));
  1082. 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?
  1083. 3:
  1084. 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")));
  1085. 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));
  1086. }
  1087. }
  1088. // Optional item
  1089. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1090. {
  1091. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1092. }
  1093. else
  1094. {
  1095. sprintf((char*)maxProfile.ValidFrom, " ");
  1096. }
  1097. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1098. {
  1099. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1100. }
  1101. else
  1102. {
  1103. sprintf((char*)maxProfile.ValidTo, " ");
  1104. }
  1105. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1106. {
  1107. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1108. }
  1109. else
  1110. {
  1111. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1112. }
  1113. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1114. {
  1115. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1116. }
  1117. else
  1118. {
  1119. maxProfile.TransactionId = -1;
  1120. }
  1121. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1122. {
  1123. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1124. }
  1125. else
  1126. {
  1127. maxProfile.ChargingSchedule.Duration = 86400;
  1128. }
  1129. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1130. {
  1131. 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")));
  1132. }
  1133. else
  1134. {
  1135. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1136. }
  1137. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1138. {
  1139. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1140. }
  1141. else
  1142. {
  1143. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. else
  1149. {
  1150. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1151. {
  1152. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1153. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1154. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1155. }
  1156. maxProfile.ChargingProfileId = -1;
  1157. maxProfile.StackLevel = -1;
  1158. if(maxProfile.ChargingProfileId == -1)
  1159. DEBUG_INFO("MaxProfile found.\n");
  1160. else
  1161. DEBUG_INFO("MaxProfile updated.\n");
  1162. // Required item
  1163. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1164. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1165. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1166. if(isUnitA)
  1167. {
  1168. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1169. 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++)
  1170. {
  1171. 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"));
  1172. 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?
  1173. 3:
  1174. 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")));
  1175. 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")));
  1176. }
  1177. }
  1178. else
  1179. {
  1180. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1181. 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++)
  1182. {
  1183. 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"));
  1184. 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?
  1185. 3:
  1186. 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")));
  1187. 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));
  1188. }
  1189. }
  1190. // Optional item
  1191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1192. {
  1193. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1194. }
  1195. else
  1196. {
  1197. sprintf((char*)maxProfile.ValidFrom, " ");
  1198. }
  1199. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1200. {
  1201. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1202. }
  1203. else
  1204. {
  1205. sprintf((char*)maxProfile.ValidTo, " ");
  1206. }
  1207. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1208. {
  1209. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1210. }
  1211. else
  1212. {
  1213. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1214. }
  1215. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1216. {
  1217. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1218. }
  1219. else
  1220. {
  1221. maxProfile.TransactionId = -1;
  1222. }
  1223. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1224. {
  1225. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1226. }
  1227. else
  1228. {
  1229. maxProfile.ChargingSchedule.Duration = 86400;
  1230. }
  1231. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1232. {
  1233. 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")));
  1234. }
  1235. else
  1236. {
  1237. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1238. }
  1239. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1240. {
  1241. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1242. }
  1243. else
  1244. {
  1245. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. json_object_put(obj);
  1251. }
  1252. fclose(fp);
  1253. /*
  1254. if(maxProfile.ChargingProfileId !=-1)
  1255. {
  1256. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1257. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1258. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1259. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1260. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1261. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1262. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1263. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1264. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1265. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1266. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1270. {
  1271. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1272. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1273. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1274. }
  1275. }
  1276. }
  1277. else
  1278. DEBUG_INFO("MaxProfile not found.\n");
  1279. DEBUG_INFO("------------------------------------\n");*/
  1280. }
  1281. if(maxProfile.ChargingProfileId != -1)
  1282. {
  1283. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1284. {
  1285. if(maxProfile.ChargingSchedule.Duration != -1)
  1286. {
  1287. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1288. 0:
  1289. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1290. }
  1291. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1292. {
  1293. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1294. {
  1295. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1296. 0:
  1297. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1298. if(idxPeriod > 0)
  1299. {
  1300. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1301. {
  1302. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1303. }
  1304. }
  1305. }
  1306. }
  1307. }
  1308. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1309. {
  1310. if(maxProfile.ChargingSchedule.Duration != -1)
  1311. {
  1312. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1313. }
  1314. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1315. {
  1316. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1317. {
  1318. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1319. if(idxPeriod > 0)
  1320. {
  1321. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1322. {
  1323. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1324. }
  1325. }
  1326. }
  1327. }
  1328. }
  1329. else
  1330. {
  1331. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1332. {
  1333. if(maxProfile.ChargingSchedule.Duration != -1)
  1334. {
  1335. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1336. 0:
  1337. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1338. }
  1339. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1340. {
  1341. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1342. {
  1343. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1344. 0:
  1345. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1346. if(idxPeriod > 0)
  1347. {
  1348. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1349. {
  1350. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1351. }
  1352. }
  1353. }
  1354. }
  1355. }
  1356. else
  1357. {
  1358. if(maxProfile.ChargingSchedule.Duration != -1)
  1359. {
  1360. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1361. 0:
  1362. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1363. }
  1364. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1365. {
  1366. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1367. {
  1368. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1369. 0:
  1370. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1371. if(idxPeriod > 0)
  1372. {
  1373. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1374. {
  1375. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. /*
  1383. DEBUG_INFO("MaxProfile after align.\n");
  1384. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1385. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1386. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1387. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1388. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1389. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1390. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1391. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1392. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1393. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1394. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1395. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1396. {
  1397. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1398. {
  1399. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1400. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1401. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1402. }
  1403. }
  1404. DEBUG_INFO("------------------------------------\n");*/
  1405. }
  1406. // Find each profile period quantity
  1407. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1408. {
  1409. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1410. limitMax = idx+1;
  1411. }
  1412. if(maxProfile.ChargingProfileId != -1)
  1413. {
  1414. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1415. {
  1416. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1417. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1418. (maxProfile.ChargingSchedule.Duration > 0))
  1419. {
  1420. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1421. {
  1422. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1423. compositePeriodIdx++;
  1424. }
  1425. else
  1426. {
  1427. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1428. }
  1429. }
  1430. }
  1431. }
  1432. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1433. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1434. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1435. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1436. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1437. {
  1438. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1439. {
  1440. compositeProfile->ChargingProfileId = 1;
  1441. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1442. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1443. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1444. }
  1445. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1446. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1447. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1448. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1449. }
  1450. if(line)
  1451. free(line);
  1452. }
  1453. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1454. {
  1455. FILE *fp;
  1456. char profileFileName[128];
  1457. char *line = NULL;
  1458. size_t len = 0;
  1459. time_t CurrentTime;
  1460. struct tm *tmComposite;
  1461. struct StructChargingProfile maxProfile;
  1462. struct StructChargingProfile defaultTxProfile;
  1463. struct StructChargingProfile txProfile;
  1464. struct StructChargingSchedulePeriod tmpPeriod;
  1465. uint8_t limitMax=0;
  1466. uint8_t limitDef=0;
  1467. uint8_t limitTx=0;
  1468. int compositePeriodIdx = 0;
  1469. CurrentTime = time(NULL);
  1470. tmComposite=localtime(&CurrentTime);
  1471. 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);
  1472. if(isUnitA)
  1473. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1474. else
  1475. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1476. compositeProfile->ChargingSchedule.Duration = durationReq;
  1477. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1478. {
  1479. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1480. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1481. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1482. }
  1483. compositeProfile->ChargingProfileId = 0;
  1484. compositeProfile->StackLevel = 99 ;
  1485. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1486. maxProfile.ChargingProfileId = -1;
  1487. defaultTxProfile.ChargingProfileId = -1;
  1488. txProfile.ChargingProfileId = -1;
  1489. maxProfile.ChargingSchedule.Duration = -1;
  1490. defaultTxProfile.ChargingSchedule.Duration = -1;
  1491. txProfile.ChargingSchedule.Duration = -1;
  1492. system("rm -f /tmp/*.json");
  1493. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1494. /*
  1495. * Search valid charging profile
  1496. */
  1497. //DEBUG_INFO("====================================\n");
  1498. // Search tx profile
  1499. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1500. if((access(profileFileName, F_OK))!=-1)
  1501. {
  1502. fp = fopen(profileFileName, "r");
  1503. while(getline(&line, &len, fp) != -1)
  1504. {
  1505. json_object *obj = NULL;
  1506. obj = json_tokener_parse(line);
  1507. if(is_error(obj))
  1508. {
  1509. DEBUG_ERROR("Parse txProfile from file error.\n");
  1510. }
  1511. else
  1512. {
  1513. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != txProfile.ChargingProfileId) &&
  1514. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1515. )
  1516. {
  1517. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1518. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1519. )
  1520. {
  1521. struct tm tmFrom, tmTo;
  1522. struct timeb tbFrom, tbTo;
  1523. 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) &&
  1524. (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))
  1525. {
  1526. tmFrom.tm_year -= 1900;
  1527. tmFrom.tm_mon -= 1;
  1528. tbFrom.time = mktime(&tmFrom);
  1529. tmTo.tm_year -= 1900;
  1530. tmTo.tm_mon -= 1;
  1531. tbTo.time = mktime(&tmTo);
  1532. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1533. {
  1534. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1535. {
  1536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1538. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1539. }
  1540. txProfile.ChargingProfileId = -1;
  1541. txProfile.StackLevel = -1;
  1542. if(txProfile.ChargingProfileId == -1)
  1543. DEBUG_INFO("TxProfile found.\n");
  1544. else
  1545. DEBUG_INFO("TxProfile updated.\n");
  1546. // Required item
  1547. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1548. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1549. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1550. if(isUnitA)
  1551. {
  1552. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1553. 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++)
  1554. {
  1555. 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"));
  1556. 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?
  1557. 3:
  1558. 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")));
  1559. 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")));
  1560. }
  1561. }
  1562. else
  1563. {
  1564. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1565. 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++)
  1566. {
  1567. 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"));
  1568. 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?
  1569. 3:
  1570. 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")));
  1571. 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));
  1572. }
  1573. }
  1574. // Optional item
  1575. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1576. {
  1577. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1578. }
  1579. else
  1580. {
  1581. sprintf((char*)txProfile.ValidFrom, " ");
  1582. }
  1583. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1584. {
  1585. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1586. }
  1587. else
  1588. {
  1589. sprintf((char*)txProfile.ValidTo, " ");
  1590. }
  1591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1592. {
  1593. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1594. }
  1595. else
  1596. {
  1597. sprintf((char*)txProfile.RecurrencyKind, " ");
  1598. }
  1599. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1600. {
  1601. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1602. }
  1603. else
  1604. {
  1605. txProfile.TransactionId = -1;
  1606. }
  1607. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1608. {
  1609. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1610. }
  1611. else
  1612. {
  1613. txProfile.ChargingSchedule.Duration = 86400;
  1614. }
  1615. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1616. {
  1617. 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")));
  1618. }
  1619. else
  1620. {
  1621. 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));
  1622. }
  1623. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1624. {
  1625. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1626. }
  1627. else
  1628. {
  1629. txProfile.ChargingSchedule.MinChargingRate = -1;
  1630. }
  1631. }
  1632. }
  1633. }
  1634. else
  1635. {
  1636. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1637. {
  1638. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1639. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1640. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1641. }
  1642. txProfile.ChargingProfileId = -1;
  1643. txProfile.StackLevel = -1;
  1644. if(txProfile.ChargingProfileId == -1)
  1645. DEBUG_INFO("TxProfile found.\n");
  1646. else
  1647. DEBUG_INFO("TxProfile updated.\n");
  1648. // Required item
  1649. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1650. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1651. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1652. if(isUnitA)
  1653. {
  1654. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1655. 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++)
  1656. {
  1657. 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"));
  1658. 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?
  1659. 3:
  1660. 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")));
  1661. 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")));
  1662. }
  1663. }
  1664. else
  1665. {
  1666. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1667. 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++)
  1668. {
  1669. 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"));
  1670. 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?
  1671. 3:
  1672. 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")));
  1673. 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));
  1674. }
  1675. }
  1676. // Optional item
  1677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1678. {
  1679. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1680. }
  1681. else
  1682. {
  1683. sprintf((char*)txProfile.ValidFrom, " ");
  1684. }
  1685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1686. {
  1687. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1688. }
  1689. else
  1690. {
  1691. sprintf((char*)txProfile.ValidTo, " ");
  1692. }
  1693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1694. {
  1695. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1696. }
  1697. else
  1698. {
  1699. sprintf((char*)txProfile.RecurrencyKind, " ");
  1700. }
  1701. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1702. {
  1703. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1704. }
  1705. else
  1706. {
  1707. txProfile.TransactionId = -1;
  1708. }
  1709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1710. {
  1711. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1712. }
  1713. else
  1714. {
  1715. txProfile.ChargingSchedule.Duration = 86400;
  1716. }
  1717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1718. {
  1719. 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")));
  1720. }
  1721. else
  1722. {
  1723. 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));
  1724. }
  1725. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1726. {
  1727. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1728. }
  1729. else
  1730. {
  1731. txProfile.ChargingSchedule.MinChargingRate = -1;
  1732. }
  1733. }
  1734. }
  1735. }
  1736. json_object_put(obj);
  1737. }
  1738. fclose(fp);
  1739. /*
  1740. if(txProfile.ChargingProfileId != -1)
  1741. {
  1742. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1743. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1744. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1745. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1746. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1747. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1748. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  1749. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1750. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1751. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1752. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1756. {
  1757. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1758. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1759. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1760. }
  1761. }
  1762. }
  1763. else
  1764. DEBUG_INFO("TxProfile not found.\n");*/
  1765. }
  1766. // Search default tx profile
  1767. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1768. if((access(profileFileName, F_OK))==-1)
  1769. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1770. if((access(profileFileName, F_OK))!=-1)
  1771. {
  1772. fp = fopen(profileFileName, "r");
  1773. while(getline(&line, &len, fp) != -1)
  1774. {
  1775. json_object *obj = NULL;
  1776. obj = json_tokener_parse(line);
  1777. if(is_error(obj))
  1778. {
  1779. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1780. }
  1781. else
  1782. {
  1783. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1784. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1785. )
  1786. {
  1787. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1788. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1789. )
  1790. {
  1791. struct tm tmFrom, tmTo;
  1792. struct timeb tbFrom, tbTo;
  1793. 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) &&
  1794. (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))
  1795. {
  1796. tmFrom.tm_year -= 1900;
  1797. tmFrom.tm_mon -= 1;
  1798. tbFrom.time = mktime(&tmFrom);
  1799. tmTo.tm_year -= 1900;
  1800. tmTo.tm_mon -= 1;
  1801. tbTo.time = mktime(&tmTo);
  1802. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1803. {
  1804. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1805. {
  1806. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1807. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1808. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1809. }
  1810. defaultTxProfile.ChargingProfileId = -1;
  1811. defaultTxProfile.StackLevel = -1;
  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. else
  1905. {
  1906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1907. {
  1908. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1909. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1910. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1911. }
  1912. defaultTxProfile.ChargingProfileId = -1;
  1913. defaultTxProfile.StackLevel = -1;
  1914. if(defaultTxProfile.ChargingProfileId == -1)
  1915. DEBUG_INFO("TxDefaultProfile found.\n");
  1916. else
  1917. DEBUG_INFO("TxDefaultProfile updated.\n");
  1918. // Required item
  1919. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1920. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1921. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1922. if(isUnitA)
  1923. {
  1924. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1925. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1926. {
  1927. 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"));
  1928. 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?
  1929. 3:
  1930. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1931. 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")));
  1932. }
  1933. }
  1934. else
  1935. {
  1936. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1937. 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++)
  1938. {
  1939. 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"));
  1940. 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?
  1941. 3:
  1942. 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")));
  1943. 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));
  1944. }
  1945. }
  1946. // Optional item
  1947. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1948. {
  1949. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1950. }
  1951. else
  1952. {
  1953. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1954. }
  1955. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1956. {
  1957. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1958. }
  1959. else
  1960. {
  1961. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1962. }
  1963. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  1964. {
  1965. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  1966. }
  1967. else
  1968. {
  1969. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1970. }
  1971. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1972. {
  1973. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1974. }
  1975. else
  1976. {
  1977. defaultTxProfile.TransactionId = -1;
  1978. }
  1979. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1980. {
  1981. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1982. }
  1983. else
  1984. {
  1985. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1986. }
  1987. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1988. {
  1989. 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")));
  1990. }
  1991. else
  1992. {
  1993. 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));
  1994. }
  1995. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1996. {
  1997. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1998. }
  1999. else
  2000. {
  2001. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  2002. }
  2003. }
  2004. }
  2005. }
  2006. json_object_put(obj);
  2007. }
  2008. fclose(fp);
  2009. /*
  2010. if(defaultTxProfile.ChargingProfileId != -1)
  2011. {
  2012. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2013. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2014. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2015. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2016. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2017. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2018. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2019. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  2020. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2021. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2022. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2023. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2024. {
  2025. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2026. {
  2027. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2028. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2029. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2030. }
  2031. }
  2032. }
  2033. else
  2034. DEBUG_INFO("TxDefaultProfile not found.\n");
  2035. DEBUG_INFO("------------------------------------\n");*/
  2036. }
  2037. // Search max profile
  2038. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2039. if((access(profileFileName, F_OK))!=-1)
  2040. {
  2041. fp = fopen(profileFileName, "r");
  2042. while(getline(&line, &len, fp) != -1)
  2043. {
  2044. json_object *obj = NULL;
  2045. obj = json_tokener_parse(line);
  2046. if(is_error(obj))
  2047. {
  2048. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2049. }
  2050. else
  2051. {
  2052. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId")) != maxProfile.ChargingProfileId) &&
  2053. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2054. )
  2055. {
  2056. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2057. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2058. )
  2059. {
  2060. struct tm tmFrom, tmTo;
  2061. struct timeb tbFrom, tbTo;
  2062. 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) &&
  2063. (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))
  2064. {
  2065. tmFrom.tm_year -= 1900;
  2066. tmFrom.tm_mon -= 1;
  2067. tbFrom.time = mktime(&tmFrom);
  2068. tmTo.tm_year -= 1900;
  2069. tmTo.tm_mon -= 1;
  2070. tbTo.time = mktime(&tmTo);
  2071. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2072. {
  2073. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2074. {
  2075. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2076. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2077. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2078. }
  2079. maxProfile.ChargingProfileId = -1;
  2080. maxProfile.StackLevel = -1;
  2081. if(maxProfile.ChargingProfileId == -1)
  2082. DEBUG_INFO("MaxProfile found.\n");
  2083. else
  2084. DEBUG_INFO("MaxProfile updated.\n");
  2085. // Required item
  2086. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2087. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2088. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2089. if(isUnitA)
  2090. {
  2091. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2092. 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++)
  2093. {
  2094. 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"));
  2095. 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?
  2096. 3:
  2097. 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")));
  2098. 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")));
  2099. }
  2100. }
  2101. else
  2102. {
  2103. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2104. 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++)
  2105. {
  2106. 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"));
  2107. 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?
  2108. 3:
  2109. 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")));
  2110. 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));
  2111. }
  2112. }
  2113. // Optional item
  2114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2115. {
  2116. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2117. }
  2118. else
  2119. {
  2120. sprintf((char*)maxProfile.ValidFrom, " ");
  2121. }
  2122. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2123. {
  2124. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2125. }
  2126. else
  2127. {
  2128. sprintf((char*)maxProfile.ValidTo, " ");
  2129. }
  2130. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2131. {
  2132. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2133. }
  2134. else
  2135. {
  2136. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2137. }
  2138. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2139. {
  2140. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2141. }
  2142. else
  2143. {
  2144. maxProfile.TransactionId = -1;
  2145. }
  2146. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2147. {
  2148. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2149. }
  2150. else
  2151. {
  2152. maxProfile.ChargingSchedule.Duration = 86400;
  2153. }
  2154. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2155. {
  2156. 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")));
  2157. }
  2158. else
  2159. {
  2160. 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));
  2161. }
  2162. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2163. {
  2164. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2165. }
  2166. else
  2167. {
  2168. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2169. }
  2170. }
  2171. }
  2172. }
  2173. else
  2174. {
  2175. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2176. {
  2177. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2178. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2179. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2180. }
  2181. maxProfile.ChargingProfileId = -1;
  2182. maxProfile.StackLevel = -1;
  2183. if(maxProfile.ChargingProfileId == -1)
  2184. DEBUG_INFO("MaxProfile found.\n");
  2185. else
  2186. DEBUG_INFO("MaxProfile updated.\n");
  2187. // Required item
  2188. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2189. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2190. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2191. if(isUnitA)
  2192. {
  2193. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2194. 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++)
  2195. {
  2196. 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"));
  2197. 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?
  2198. 3:
  2199. 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")));
  2200. 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")));
  2201. }
  2202. }
  2203. else
  2204. {
  2205. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2206. 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++)
  2207. {
  2208. 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"));
  2209. 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?
  2210. 3:
  2211. 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")));
  2212. 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));
  2213. }
  2214. }
  2215. // Optional item
  2216. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2217. {
  2218. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2219. }
  2220. else
  2221. {
  2222. sprintf((char*)maxProfile.ValidFrom, " ");
  2223. }
  2224. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2225. {
  2226. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2227. }
  2228. else
  2229. {
  2230. sprintf((char*)maxProfile.ValidTo, " ");
  2231. }
  2232. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind") != NULL)
  2233. {
  2234. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "recurrencyKind")));
  2235. }
  2236. else
  2237. {
  2238. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2239. }
  2240. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2241. {
  2242. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2243. }
  2244. else
  2245. {
  2246. maxProfile.TransactionId = -1;
  2247. }
  2248. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2249. {
  2250. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2251. }
  2252. else
  2253. {
  2254. maxProfile.ChargingSchedule.Duration = 86400;
  2255. }
  2256. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2257. {
  2258. 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")));
  2259. }
  2260. else
  2261. {
  2262. 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));
  2263. }
  2264. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2265. {
  2266. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2267. }
  2268. else
  2269. {
  2270. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2271. }
  2272. }
  2273. }
  2274. }
  2275. json_object_put(obj);
  2276. }
  2277. fclose(fp);
  2278. /*
  2279. if(maxProfile.ChargingProfileId !=-1)
  2280. {
  2281. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2282. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2283. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2284. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2285. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2286. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2287. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2288. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2289. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2290. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2291. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2293. {
  2294. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2295. {
  2296. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2297. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2298. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2299. }
  2300. }
  2301. }
  2302. else
  2303. DEBUG_INFO("MaxProfile not found.\n");
  2304. DEBUG_INFO("------------------------------------\n");*/
  2305. }
  2306. /*
  2307. * Align found profile start schedule & periods
  2308. */
  2309. //DEBUG_INFO("====================================\n");
  2310. /*
  2311. // For local test usage, force modify found profile start schedule info
  2312. 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);
  2313. 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);
  2314. 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);
  2315. */
  2316. if(txProfile.ChargingProfileId != -1)
  2317. {
  2318. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2319. {
  2320. if(txProfile.ChargingSchedule.Duration != -1)
  2321. {
  2322. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2323. 0:
  2324. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2325. }
  2326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2327. {
  2328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2329. {
  2330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2331. 0:
  2332. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2333. if(idxPeriod > 0)
  2334. {
  2335. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2336. {
  2337. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2344. {
  2345. if(txProfile.ChargingSchedule.Duration != -1)
  2346. {
  2347. 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?
  2348. 0:
  2349. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2350. }
  2351. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2352. {
  2353. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2354. {
  2355. 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?
  2356. 0:
  2357. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2358. if(idxPeriod > 0)
  2359. {
  2360. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2361. {
  2362. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2363. }
  2364. }
  2365. }
  2366. }
  2367. }
  2368. else
  2369. {
  2370. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2371. {
  2372. if(txProfile.ChargingSchedule.Duration != -1)
  2373. {
  2374. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2375. 0:
  2376. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2377. }
  2378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2379. {
  2380. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2381. {
  2382. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2383. 0:
  2384. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2385. if(idxPeriod > 0)
  2386. {
  2387. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2388. {
  2389. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2390. }
  2391. }
  2392. }
  2393. }
  2394. }
  2395. else
  2396. {
  2397. if(txProfile.ChargingSchedule.Duration != -1)
  2398. {
  2399. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2400. 0:
  2401. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2402. }
  2403. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2404. {
  2405. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2406. {
  2407. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2408. 0:
  2409. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2410. if(idxPeriod > 0)
  2411. {
  2412. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2413. {
  2414. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. }
  2421. /*
  2422. DEBUG_INFO("txProfile after align.\n");
  2423. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2424. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2425. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2426. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2427. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2428. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2429. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.RecurrencyKind);
  2430. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2431. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2432. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2433. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2434. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2435. {
  2436. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2437. {
  2438. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2439. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2440. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2441. }
  2442. }*/
  2443. }
  2444. if(defaultTxProfile.ChargingProfileId != -1)
  2445. {
  2446. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2447. {
  2448. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2449. {
  2450. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2451. 0:
  2452. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2453. }
  2454. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2455. {
  2456. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2457. {
  2458. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2459. 0:
  2460. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2462. {
  2463. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2464. }
  2465. if(idxPeriod > 0)
  2466. {
  2467. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2468. {
  2469. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2470. }
  2471. }
  2472. }
  2473. }
  2474. }
  2475. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2476. {
  2477. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2478. {
  2479. 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?
  2480. 0:
  2481. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2482. }
  2483. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2484. {
  2485. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2486. {
  2487. 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?
  2488. 0:
  2489. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2490. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2491. {
  2492. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2493. }
  2494. if(idxPeriod > 0)
  2495. {
  2496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2497. {
  2498. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. else
  2505. {
  2506. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2507. {
  2508. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2509. {
  2510. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2511. 0:
  2512. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2513. }
  2514. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2515. {
  2516. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2517. {
  2518. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2519. 0:
  2520. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2521. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2522. {
  2523. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2524. }
  2525. if(idxPeriod > 0)
  2526. {
  2527. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2528. {
  2529. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2530. }
  2531. }
  2532. }
  2533. }
  2534. }
  2535. else
  2536. {
  2537. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2538. {
  2539. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2540. 0:
  2541. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2542. }
  2543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2544. {
  2545. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2546. {
  2547. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2548. 0:
  2549. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2550. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2551. {
  2552. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2553. }
  2554. if(idxPeriod > 0)
  2555. {
  2556. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2557. {
  2558. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2559. }
  2560. }
  2561. }
  2562. }
  2563. }
  2564. }
  2565. /*
  2566. DEBUG_INFO("defaultTxProfile after align.\n");
  2567. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2568. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2569. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2570. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2571. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2572. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2573. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2574. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2575. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2576. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2577. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2578. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2579. {
  2580. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2581. {
  2582. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2583. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2584. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2585. }
  2586. }
  2587. DEBUG_INFO("------------------------------------\n");*/
  2588. }
  2589. if(maxProfile.ChargingProfileId != -1)
  2590. {
  2591. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2592. {
  2593. if(maxProfile.ChargingSchedule.Duration != -1)
  2594. {
  2595. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2596. 0:
  2597. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2598. }
  2599. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2600. {
  2601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2602. {
  2603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2604. 0:
  2605. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2606. if(idxPeriod > 0)
  2607. {
  2608. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2609. {
  2610. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2611. }
  2612. }
  2613. }
  2614. }
  2615. }
  2616. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2617. {
  2618. if(maxProfile.ChargingSchedule.Duration != -1)
  2619. {
  2620. 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?
  2621. 0:
  2622. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2623. }
  2624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2625. {
  2626. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2627. {
  2628. 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?
  2629. 0:
  2630. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2631. if(idxPeriod > 0)
  2632. {
  2633. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2634. {
  2635. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2636. }
  2637. }
  2638. }
  2639. }
  2640. }
  2641. else
  2642. {
  2643. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2644. {
  2645. if(maxProfile.ChargingSchedule.Duration != -1)
  2646. {
  2647. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2648. 0:
  2649. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2650. }
  2651. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2652. {
  2653. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2654. {
  2655. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2656. 0:
  2657. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2658. if(idxPeriod > 0)
  2659. {
  2660. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2661. {
  2662. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2663. }
  2664. }
  2665. }
  2666. }
  2667. }
  2668. else
  2669. {
  2670. if(maxProfile.ChargingSchedule.Duration != -1)
  2671. {
  2672. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2673. 0:
  2674. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2675. }
  2676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2677. {
  2678. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2679. {
  2680. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2681. 0:
  2682. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2683. if(idxPeriod > 0)
  2684. {
  2685. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2686. {
  2687. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2688. }
  2689. }
  2690. }
  2691. }
  2692. }
  2693. }
  2694. /*
  2695. DEBUG_INFO("MaxProfile after align.\n");
  2696. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2697. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2698. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2699. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2700. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2701. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2702. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2703. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2704. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2705. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2706. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2707. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2708. {
  2709. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2710. {
  2711. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2712. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2713. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2714. }
  2715. }
  2716. DEBUG_INFO("------------------------------------\n");*/
  2717. }
  2718. /*
  2719. * Merge to conposite schedule
  2720. */
  2721. //DEBUG_INFO("====================================\n");
  2722. // Find each profile period quantity
  2723. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2724. {
  2725. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2726. limitMax = idx+1;
  2727. }
  2728. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2729. {
  2730. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2731. limitDef = idx+1;
  2732. }
  2733. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2734. {
  2735. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2736. limitTx = idx+1;
  2737. }
  2738. // TxProfile found, composite schedule based on it
  2739. if(txProfile.ChargingProfileId != -1)
  2740. {
  2741. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2742. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2743. {
  2744. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2745. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2746. (txProfile.ChargingSchedule.Duration > 0))
  2747. {
  2748. if(maxProfile.ChargingProfileId != -1)
  2749. {
  2750. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2751. {
  2752. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2753. {
  2754. if((maxProfile.ChargingSchedule.Duration > 0))
  2755. {
  2756. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2757. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2758. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2759. }
  2760. else
  2761. {
  2762. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2763. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2764. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2765. }
  2766. }
  2767. if(idxMaxPeriod == (limitMax-1))
  2768. {
  2769. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2770. {
  2771. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2772. {
  2773. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2774. compositePeriodIdx++;
  2775. }
  2776. else
  2777. {
  2778. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2779. }
  2780. }
  2781. }
  2782. }
  2783. }
  2784. else
  2785. {
  2786. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2787. {
  2788. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2789. compositePeriodIdx++;
  2790. }
  2791. else
  2792. {
  2793. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2794. }
  2795. }
  2796. }
  2797. if(idxTxPeriod == (limitTx-1))
  2798. {
  2799. if(defaultTxProfile.ChargingProfileId != -1)
  2800. {
  2801. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2802. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2803. {
  2804. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2805. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2806. (defaultTxProfile.ChargingSchedule.Duration>0))
  2807. {
  2808. if(maxProfile.ChargingProfileId != -1)
  2809. {
  2810. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2811. {
  2812. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2813. {
  2814. if((maxProfile.ChargingSchedule.Duration > 0))
  2815. {
  2816. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2817. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2818. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2819. }
  2820. else
  2821. {
  2822. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2823. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2824. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2825. }
  2826. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2827. {
  2828. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2829. {
  2830. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2831. compositePeriodIdx++;
  2832. }
  2833. else
  2834. {
  2835. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2836. }
  2837. }
  2838. // Delete duplicate period
  2839. if(compositePeriodIdx > 1)
  2840. {
  2841. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2842. {
  2843. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2844. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2845. compositePeriodIdx -= 1;
  2846. }
  2847. }
  2848. }
  2849. else
  2850. {
  2851. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2852. {
  2853. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2854. compositePeriodIdx++;
  2855. }
  2856. else
  2857. {
  2858. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2859. }
  2860. break;
  2861. }
  2862. }
  2863. }
  2864. else
  2865. {
  2866. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2867. {
  2868. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2869. compositePeriodIdx++;
  2870. }
  2871. else
  2872. {
  2873. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2874. }
  2875. }
  2876. }
  2877. }
  2878. }
  2879. }
  2880. }
  2881. }
  2882. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2883. else if(defaultTxProfile.ChargingProfileId != -1)
  2884. {
  2885. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2886. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2887. {
  2888. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2889. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2890. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2891. {
  2892. if(maxProfile.ChargingProfileId != -1)
  2893. {
  2894. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2895. {
  2896. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2897. {
  2898. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2899. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2900. if((maxProfile.ChargingSchedule.Duration > 0))
  2901. {
  2902. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2903. }
  2904. else
  2905. {
  2906. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2907. }
  2908. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2909. {
  2910. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2911. {
  2912. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2913. compositePeriodIdx++;
  2914. }
  2915. else
  2916. {
  2917. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2918. }
  2919. }
  2920. // Delete duplicate period
  2921. if(compositePeriodIdx > 1)
  2922. {
  2923. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2924. {
  2925. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2926. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2927. compositePeriodIdx -= 1;
  2928. }
  2929. }
  2930. }
  2931. else
  2932. {
  2933. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2934. {
  2935. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2936. compositePeriodIdx++;
  2937. }
  2938. else
  2939. {
  2940. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2941. }
  2942. break;
  2943. }
  2944. }
  2945. }
  2946. else
  2947. {
  2948. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2949. {
  2950. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2951. compositePeriodIdx++;
  2952. }
  2953. else
  2954. {
  2955. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2956. }
  2957. }
  2958. }
  2959. }
  2960. }
  2961. // Fill other period by MaxProfile
  2962. if(maxProfile.ChargingProfileId != -1)
  2963. {
  2964. if(compositePeriodIdx==0)
  2965. {
  2966. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2967. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2968. {
  2969. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2970. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2971. (maxProfile.ChargingSchedule.Duration > 0))
  2972. {
  2973. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2974. {
  2975. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2976. compositePeriodIdx++;
  2977. }
  2978. else
  2979. {
  2980. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2981. }
  2982. }
  2983. }
  2984. }
  2985. else
  2986. {
  2987. int lastCompositePeriodIdx = compositePeriodIdx;
  2988. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2989. {
  2990. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2991. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2992. (maxProfile.ChargingSchedule.Duration > 0))
  2993. {
  2994. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  2995. {
  2996. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  2997. {
  2998. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  2999. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3000. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  3001. }
  3002. else
  3003. {
  3004. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  3005. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  3006. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  3007. }
  3008. }
  3009. if(tmpPeriod.Limit != -1)
  3010. {
  3011. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  3012. {
  3013. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  3014. {
  3015. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3016. compositePeriodIdx++;
  3017. }
  3018. else
  3019. {
  3020. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  3021. }
  3022. }
  3023. // Delete duplicate period
  3024. if(compositePeriodIdx > 1)
  3025. {
  3026. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  3027. {
  3028. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  3029. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  3030. compositePeriodIdx -= 1;
  3031. }
  3032. }
  3033. }
  3034. }
  3035. }
  3036. }
  3037. }
  3038. compositeProfile->ChargingSchedule.Duration = durationReq;
  3039. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3040. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3041. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3042. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3043. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3044. {
  3045. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3046. {
  3047. compositeProfile->ChargingProfileId = 1;
  3048. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3049. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3050. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3051. }
  3052. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3053. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3054. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3055. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3056. }
  3057. if(line)
  3058. free(line);
  3059. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3060. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3061. }
  3062. //==========================================
  3063. // Init all share memory
  3064. //==========================================
  3065. int InitShareMemory()
  3066. {
  3067. int result = PASS;
  3068. int MeterSMId;
  3069. //creat ShmSysConfigAndInfo
  3070. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3071. {
  3072. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3073. result = FAIL;
  3074. }
  3075. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3076. {
  3077. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3078. result = FAIL;
  3079. }
  3080. else
  3081. {}
  3082. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3083. {
  3084. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3085. result = FAIL;
  3086. }
  3087. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3088. {
  3089. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3090. result = FAIL;
  3091. }
  3092. else
  3093. {}
  3094. //creat ShmPsuData
  3095. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3096. {
  3097. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3098. result = FAIL;
  3099. }
  3100. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3101. {
  3102. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3103. result = FAIL;
  3104. }
  3105. else
  3106. {}
  3107. //link ShmOCPP16Data
  3108. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3109. {
  3110. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3111. result = FAIL;
  3112. }
  3113. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3114. {
  3115. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3116. result = FAIL;
  3117. }
  3118. else
  3119. {}
  3120. //creat ShmOCPP16DataPH
  3121. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3122. {
  3123. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3124. result = FAIL;
  3125. }
  3126. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3127. {
  3128. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3129. result = FAIL;
  3130. }
  3131. else
  3132. {}
  3133. /****************************** For Initial Settings************************************************/
  3134. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3135. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3136. // allocate Configuration memory address
  3137. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3138. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3139. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3140. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3141. //offline MeterValue Interval
  3142. TempMeterValueInterval = 0;
  3143. return result;
  3144. }
  3145. int ProcessShareMemory()
  3146. {
  3147. if(InitShareMemory() == FAIL)
  3148. {
  3149. DEBUG_ERROR("InitShareMemory NG\n");
  3150. if(ShmStatusCodeData!=NULL)
  3151. {
  3152. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3153. }
  3154. sleep(5);
  3155. return FAIL;
  3156. }
  3157. return PASS;
  3158. }
  3159. void CheckSystemValue(void)
  3160. {
  3161. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3162. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3163. char filenmae[100]={0};
  3164. char str[100]={0};
  3165. int tempIndex = 0;
  3166. //===============================
  3167. // send Heartbeat
  3168. //===============================
  3169. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3170. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3171. {
  3172. clientTime.Heartbeat=time((time_t*)NULL);
  3173. if(server_sign == TRUE)
  3174. {
  3175. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3176. }
  3177. else
  3178. {
  3179. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3180. }
  3181. }
  3182. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3183. {
  3184. //parameter for test
  3185. sendHeartbeatRequest(0);
  3186. //==============================================
  3187. // Reset Waiting Time
  3188. //==============================================
  3189. HeartBeatWithNOResponse += 2;
  3190. }
  3191. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3192. {
  3193. //==========================================
  3194. // csu trigger DataTransferReq
  3195. //==========================================
  3196. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3197. {
  3198. sendDataTransferRequest(gun_index);
  3199. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3200. }
  3201. //===============================
  3202. // CSU Trigger Authorize Request
  3203. //===============================
  3204. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3205. {
  3206. sendAuthorizeRequest(0);
  3207. authorizeRetryTimes = authorizeRetryTimes + 1;
  3208. if(authorizeRetryTimes < 3)
  3209. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3210. }
  3211. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3212. {
  3213. authorizeRetryTimes = 0;
  3214. SetOcppConnStatus(FALSE);
  3215. server_sign = FALSE;
  3216. }
  3217. 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))
  3218. {
  3219. sendAuthorizeRequest(0);
  3220. }
  3221. //==============================================
  3222. // Charger start transaction
  3223. //==============================================
  3224. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3225. {
  3226. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3227. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3228. sendStartTransactionRequest(gun_index);
  3229. clientTime.StartTransaction = time((time_t*)NULL);
  3230. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3231. storeTempStopTransaction(gun_index);
  3232. }
  3233. //==============================================
  3234. // Charger stop transaction
  3235. //==============================================
  3236. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3237. {
  3238. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3239. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3240. sendStopTransactionRequest(gun_index);
  3241. clientTime.StopTransaction = time((time_t*)NULL);
  3242. }
  3243. //==============================================
  3244. // Charger status report
  3245. //==============================================
  3246. //--- Check Mode Change ---//
  3247. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3248. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3249. {
  3250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3251. {
  3252. tempIndex = ((gun_index==2) ? 1: 0);
  3253. }
  3254. else
  3255. {
  3256. tempIndex = gun_index;
  3257. }
  3258. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3259. {
  3260. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3261. {
  3262. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3263. {
  3264. // Sent unplug message for California pricing logic
  3265. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3266. {
  3267. uint8_t ts[20];
  3268. getNowDatetime(ts);
  3269. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3270. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3271. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3272. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3273. }
  3274. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3275. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3276. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3277. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3278. {
  3279. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3280. if((access(filenmae,F_OK))!=-1)
  3281. {
  3282. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3283. sprintf(str,"rm -f %s",filenmae);
  3284. system(str);
  3285. }
  3286. }
  3287. }
  3288. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3289. #if 1 // for TempStopTransaction
  3290. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3291. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3292. {
  3293. checkTempStopTransaction(gun_index);
  3294. }
  3295. #endif
  3296. }
  3297. }
  3298. }
  3299. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3300. {
  3301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3302. {
  3303. tempIndex = ((gun_index==2) ? 1: 0);
  3304. }
  3305. else
  3306. {
  3307. tempIndex = gun_index;
  3308. }
  3309. for (int index = 0; index < CCS_QUANTITY; index++)
  3310. {
  3311. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3312. {
  3313. 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]*/ )
  3314. {
  3315. // Sent unplug message for California pricing logic
  3316. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3317. {
  3318. uint8_t ts[20];
  3319. getNowDatetime(ts);
  3320. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3321. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3322. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3323. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3324. }
  3325. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3326. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3327. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3328. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3329. {
  3330. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3331. if((access(filenmae,F_OK))!=-1)
  3332. {
  3333. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3334. sprintf(str,"rm -f %s",filenmae);
  3335. system(str);
  3336. }
  3337. }
  3338. }
  3339. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3340. #if 1 // for TempStopTransaction
  3341. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3342. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3343. {
  3344. checkTempStopTransaction(gun_index);
  3345. }
  3346. #endif
  3347. }
  3348. }
  3349. }
  3350. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3351. {
  3352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3353. {
  3354. tempIndex = ((gun_index==2) ? 1: 0);
  3355. }
  3356. else
  3357. {
  3358. tempIndex = gun_index;
  3359. }
  3360. for (int index = 0; index < GB_QUANTITY; index++)
  3361. {
  3362. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3363. {
  3364. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3365. {
  3366. // Sent unplug message for California pricing logic
  3367. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3368. {
  3369. uint8_t ts[20];
  3370. getNowDatetime(ts);
  3371. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3372. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3373. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3374. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3375. }
  3376. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3377. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3378. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3379. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3380. {
  3381. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3382. if((access(filenmae,F_OK))!=-1)
  3383. {
  3384. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3385. sprintf(str,"rm -f %s",filenmae);
  3386. system(str);
  3387. }
  3388. }
  3389. }
  3390. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3391. #if 1 // for TempStopTransaction
  3392. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3393. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3394. {
  3395. checkTempStopTransaction(gun_index);
  3396. }
  3397. #endif
  3398. }
  3399. }
  3400. }
  3401. else if(gunType[gun_index] == GUN_TYPE_DO)
  3402. {
  3403. tempIndex = gun_index;
  3404. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3405. {
  3406. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3407. {
  3408. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3409. {
  3410. // Sent unplug message for California pricing logic
  3411. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3412. {
  3413. uint8_t ts[20];
  3414. getNowDatetime(ts);
  3415. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3416. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3417. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3418. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3419. }
  3420. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3421. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3422. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3423. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_IDLE))) // complete
  3424. {
  3425. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3426. if((access(filenmae,F_OK))!=-1)
  3427. {
  3428. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3429. sprintf(str,"rm -f %s",filenmae);
  3430. system(str);
  3431. }
  3432. }
  3433. }
  3434. 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);
  3435. #if 1 // for TempStopTransaction
  3436. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3437. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3438. {
  3439. checkTempStopTransaction(gun_index);
  3440. }
  3441. #endif
  3442. }
  3443. }
  3444. }
  3445. else
  3446. {
  3447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3448. {
  3449. tempIndex = 2;
  3450. }
  3451. else
  3452. {
  3453. tempIndex = gun_index;
  3454. }
  3455. for (int index = 0; index < AC_QUANTITY; index++)
  3456. {
  3457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3458. {
  3459. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3460. {
  3461. // Sent unplug message for California pricing logic
  3462. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_A))
  3463. {
  3464. uint8_t ts[20];
  3465. getNowDatetime(ts);
  3466. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3467. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3468. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3469. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3470. }
  3471. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3472. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3473. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3474. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3475. {
  3476. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3477. if((access(filenmae,F_OK))!=-1)
  3478. {
  3479. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3480. sprintf(str,"rm -f %s",filenmae);
  3481. system(str);
  3482. }
  3483. }
  3484. }
  3485. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3486. #if 1 // for TempStopTransaction
  3487. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3488. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3489. {
  3490. checkTempStopTransaction(gun_index);
  3491. }
  3492. #endif
  3493. }
  3494. }// END
  3495. }
  3496. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3497. (
  3498. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3499. )
  3500. )
  3501. {
  3502. if(SystemInitial > 0)
  3503. SystemInitial -= 1;
  3504. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3505. sendStatusNotificationRequest(gun_index);
  3506. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3507. }
  3508. //==============================================
  3509. // CSU Trigger Smart Charging Profilw
  3510. //==============================================
  3511. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3512. {
  3513. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3514. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3515. }
  3516. //==============================================
  3517. // Meter report
  3518. //==============================================
  3519. // Trigger MeterValue
  3520. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3521. {
  3522. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3523. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3524. }
  3525. // ClockAlign MeterValue
  3526. 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))
  3527. {
  3528. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3529. {
  3530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3531. {
  3532. tempIndex = ((gun_index==2) ? 1: 0);
  3533. }
  3534. else
  3535. {
  3536. tempIndex = gun_index;
  3537. }
  3538. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3539. {
  3540. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3541. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3542. {
  3543. reqClockAlignMeter[gun_index] = 1;
  3544. }
  3545. }// End for CHAdeMO
  3546. }
  3547. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3548. {
  3549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3550. {
  3551. tempIndex = ((gun_index==2) ? 1: 0);
  3552. }
  3553. else
  3554. {
  3555. tempIndex = gun_index;
  3556. }
  3557. for (int index = 0; index < CCS_QUANTITY; index++)
  3558. {
  3559. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3560. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3561. {
  3562. reqClockAlignMeter[gun_index] = 1;
  3563. }
  3564. } // End for CCS
  3565. }
  3566. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3567. {
  3568. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3569. {
  3570. tempIndex = ((gun_index==2) ? 1: 0);
  3571. }
  3572. else
  3573. {
  3574. tempIndex = gun_index;
  3575. }
  3576. for (int index = 0; index < GB_QUANTITY; index++)
  3577. {
  3578. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3579. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3580. {
  3581. reqClockAlignMeter[gun_index] = 1;
  3582. }
  3583. }// End for GB
  3584. }
  3585. else if(gunType[gun_index] == GUN_TYPE_DO)
  3586. {
  3587. tempIndex = gun_index;
  3588. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3589. {
  3590. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3591. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3592. {
  3593. reqClockAlignMeter[gun_index] = 1;
  3594. }
  3595. }
  3596. }
  3597. else
  3598. {
  3599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3600. {
  3601. tempIndex = 2;
  3602. }
  3603. else
  3604. {
  3605. tempIndex = gun_index;
  3606. }
  3607. for (int index = 0; index < AC_QUANTITY; index++)
  3608. {
  3609. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3610. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3611. {
  3612. reqClockAlignMeter[gun_index] = 1;
  3613. }
  3614. }//End for AC
  3615. }
  3616. if(reqClockAlignMeter[gun_index] == 1)
  3617. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3618. }
  3619. // Sample period MeterValue
  3620. 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))))
  3621. {
  3622. //check Transaction active
  3623. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3624. {
  3625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3626. {
  3627. tempIndex = ((gun_index==2) ? 1: 0);
  3628. }
  3629. else
  3630. {
  3631. tempIndex = gun_index;
  3632. }
  3633. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3634. {
  3635. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3636. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3637. {
  3638. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3639. {
  3640. reqSampleMeter[gun_index] = 1;
  3641. }
  3642. }
  3643. }// End for CHAdeMO
  3644. }
  3645. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3646. {
  3647. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3648. {
  3649. tempIndex = ((gun_index==2) ? 1: 0);
  3650. }
  3651. else
  3652. {
  3653. tempIndex = gun_index;
  3654. }
  3655. for (int index = 0; index < CCS_QUANTITY; index++)
  3656. {
  3657. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3658. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3659. {
  3660. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3661. {
  3662. reqSampleMeter[gun_index] = 1;
  3663. }
  3664. }
  3665. } // End for CCS
  3666. }
  3667. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3668. {
  3669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3670. {
  3671. tempIndex = ((gun_index==2) ? 1: 0);
  3672. }
  3673. else
  3674. {
  3675. tempIndex = gun_index;
  3676. }
  3677. for (int index = 0; index < GB_QUANTITY; index++)
  3678. {
  3679. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3680. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3681. {
  3682. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3683. {
  3684. reqSampleMeter[gun_index] = 1;
  3685. }
  3686. }
  3687. }// End for GB
  3688. }
  3689. else if(gunType[gun_index] == GUN_TYPE_DO)
  3690. {
  3691. tempIndex = gun_index;
  3692. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3693. {
  3694. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3695. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3696. {
  3697. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3698. {
  3699. reqSampleMeter[gun_index] = 1;
  3700. }
  3701. }
  3702. }
  3703. }
  3704. else
  3705. {
  3706. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3707. {
  3708. tempIndex = 2;
  3709. }
  3710. else
  3711. {
  3712. tempIndex = gun_index;
  3713. }
  3714. for (int index = 0; index < AC_QUANTITY; index++)
  3715. {
  3716. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3717. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3718. {
  3719. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3720. {
  3721. reqSampleMeter[gun_index] = 1;
  3722. }
  3723. }
  3724. }//End for AC
  3725. }
  3726. if(reqSampleMeter[gun_index] == 1)
  3727. {
  3728. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3729. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3730. storeTempStopTransaction(gun_index);
  3731. }
  3732. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3733. }
  3734. //==============================================
  3735. // Check Connector reserved
  3736. //==============================================
  3737. //===============================
  3738. // Check if Reserve is expired
  3739. //===============================
  3740. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3741. {
  3742. double diff_t;
  3743. struct tm tp;
  3744. // current time
  3745. time_t t = time(NULL);
  3746. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3747. tp.tm_isdst = -1;
  3748. time_t utc = mktime(&tp);
  3749. diff_t = difftime(utc, t);
  3750. if(diff_t <= 0)
  3751. {
  3752. DEBUG_INFO("reserve expired.\n");
  3753. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3754. }
  3755. }//END OF Check if Reserve is expired
  3756. //==========================================
  3757. // csu trigger FirmwareStatusNotificationReq
  3758. //==========================================
  3759. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3760. {
  3761. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3762. }
  3763. //==========================================
  3764. // csu trigger DiagnosticsStatusNotificationReq
  3765. //==========================================
  3766. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3767. {
  3768. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3769. }
  3770. //==========================================
  3771. // csu trigger CancelReservationConf
  3772. //==========================================
  3773. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3774. {
  3775. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3776. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3777. }
  3778. //==========================================
  3779. // csu trigger ChangeAvailabilityConf
  3780. //==========================================
  3781. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3782. {
  3783. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3784. }
  3785. //==========================================
  3786. // csu trigger UnlockConnectorConf
  3787. //==========================================
  3788. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3789. {
  3790. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3791. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3792. }
  3793. //==========================================
  3794. // csu trigger ReserveNowConf
  3795. //==========================================
  3796. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3797. {
  3798. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3799. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3800. }
  3801. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3802. {
  3803. sendSignCertificateRequest();
  3804. }
  3805. }
  3806. }
  3807. //==========================================
  3808. // send request routine
  3809. //==========================================
  3810. int sendAuthorizeRequest(int gun_index)
  3811. {
  3812. mtrace();
  3813. int result = FAIL;
  3814. char message[100]={0};
  3815. char guid[37];
  3816. char tempdata[65]={0};
  3817. DEBUG_INFO("sendAuthorizeRequest...\n");
  3818. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3819. //Local Authorize
  3820. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3821. {
  3822. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3823. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3824. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3825. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3826. result = PASS;
  3827. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3828. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3829. authorizeRetryTimes = 0;
  3830. return result;
  3831. }
  3832. 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))||
  3833. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3834. {
  3835. // Query from cache
  3836. DEBUG_INFO("Authorize from cache.\n");
  3837. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3838. // Query from list
  3839. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3840. {
  3841. DEBUG_INFO("Authorize from list.\n");
  3842. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3843. }
  3844. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3845. {
  3846. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3847. {
  3848. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3849. }
  3850. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3851. {
  3852. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3853. }
  3854. if(!GetOcppConnStatus())
  3855. {
  3856. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3857. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3858. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3859. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3860. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3861. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3862. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3863. authorizeRetryTimes = 0;
  3864. return result;
  3865. }
  3866. }
  3867. else
  3868. {
  3869. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3870. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3871. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3872. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3873. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3874. else
  3875. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3876. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3877. result = PASS;
  3878. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3879. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3880. authorizeRetryTimes = 0;
  3881. return result;
  3882. }
  3883. }
  3884. //initialize struct Authorize
  3885. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3886. //get data from shared memory
  3887. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3888. random_uuid(guid);
  3889. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3890. LWS_Send(message);
  3891. sprintf(tempdata, "Authorize,%d", gun_index);
  3892. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3893. {
  3894. result = PASS;
  3895. DEBUG_INFO("Authorize mapItem pass\n");
  3896. }
  3897. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3898. return result;
  3899. }
  3900. int sendBootNotificationRequest(void)
  3901. {
  3902. mtrace();
  3903. int result = FAIL;
  3904. char message[500]={0}, payload[700]={0};
  3905. char guid[37]={0};
  3906. char tempdata[65]={0};
  3907. // Fill BootNotification fields
  3908. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3909. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3910. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3911. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3912. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3913. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3914. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3915. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3916. ShmOCPP16DataPH->ChargeBoxId
  3917. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3918. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3919. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3920. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3921. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3922. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3923. random_uuid(guid);
  3924. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3925. LWS_Send(message);
  3926. sprintf(tempdata, "BootNotification,0");
  3927. 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*/)
  3928. {
  3929. result = PASS;
  3930. }
  3931. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3932. strcpy(queuedata,message);
  3933. return result;
  3934. }
  3935. int sendDataTransferRequest(int gun_index)
  3936. {
  3937. mtrace();
  3938. char message[1000]={0};
  3939. char guid[37]={0};
  3940. char tempdata[65]={0};
  3941. int result = FAIL;
  3942. random_uuid(guid);
  3943. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3944. MESSAGE_TYPE_CALL,
  3945. guid,
  3946. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  3947. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  3948. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  3949. LWS_Send(message);
  3950. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3951. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3952. {
  3953. result = PASS;
  3954. DEBUG_INFO("DataTransfer mapItem pass\n");
  3955. }
  3956. return result;
  3957. }
  3958. int sendDiagnosticsStatusNotificationRequest(char *status)
  3959. {
  3960. mtrace();
  3961. int result = FAIL;
  3962. char message[110]={0};
  3963. char guid[37]={0};
  3964. char tempdata[65]={0};
  3965. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3966. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3967. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3968. random_uuid(guid);
  3969. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3970. LWS_SendNow(message);
  3971. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3972. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3973. {
  3974. result = PASS;
  3975. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3976. }
  3977. //#ifdef SystemLogMessage
  3978. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3979. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3980. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3981. //#endif
  3982. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3983. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3984. //record status
  3985. if(strcmp(status,"Idle")==0)
  3986. {
  3987. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3988. }
  3989. else if(strcmp(status,"Uploaded")==0)
  3990. {
  3991. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3992. }
  3993. else if(strcmp(status,"UploadFailed")==0)
  3994. {
  3995. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3996. }
  3997. else if(strcmp(status,"Uploading")==0)
  3998. {
  3999. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  4000. }
  4001. return result;
  4002. }
  4003. int sendFirmwareStatusNotificationRequest(char *status)
  4004. {
  4005. mtrace();
  4006. int result = FAIL;
  4007. char message[110]={0};
  4008. char guid[37]={0};
  4009. char tempdata[65]={0};
  4010. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  4011. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  4012. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  4013. random_uuid(guid);
  4014. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  4015. LWS_SendNow(message);
  4016. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  4017. 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*/)
  4018. {
  4019. result = PASS;
  4020. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  4021. }
  4022. //#ifdef SystemLogMessage
  4023. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  4024. //DEBUG_INFO("Message: %s\n", SendBuffer);
  4025. //#endif
  4026. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  4027. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  4028. //record status
  4029. if(strcmp(status,"Downloaded")==0)
  4030. {
  4031. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4032. }
  4033. else if(strcmp(status,"DownloadFailed")==0)
  4034. {
  4035. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4036. }
  4037. else if(strcmp(status,"Downloading")==0)
  4038. {
  4039. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4040. }
  4041. else if(strcmp(status,"Idle")==0)
  4042. {
  4043. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4044. }
  4045. else if(strcmp(status,"InstallationFailed")==0)
  4046. {
  4047. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4048. }
  4049. else if(strcmp(status,"Installing")==0)
  4050. {
  4051. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4052. }
  4053. else if(strcmp(status,"Installed")==0)
  4054. {
  4055. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4056. }
  4057. return result;
  4058. }
  4059. int sendHeartbeatRequest(int gun_index)
  4060. {
  4061. mtrace();
  4062. int result = FAIL;
  4063. char message[80]={0};
  4064. char guid[37]={0};
  4065. char tempdata[65]={0};
  4066. random_uuid(guid);
  4067. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4068. , MESSAGE_TYPE_CALL
  4069. , guid );
  4070. LWS_Send(message);
  4071. sprintf(tempdata, "Heartbeat,%d", 0);
  4072. 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*/)
  4073. {
  4074. result = PASS;
  4075. }
  4076. return result;
  4077. }
  4078. int sendStartTransactionRequest(int gun_index)
  4079. {
  4080. mtrace();
  4081. int result = FAIL;
  4082. char message[250]={0};
  4083. char guid[37]={0};
  4084. struct timeval tmnow;
  4085. struct tm *tm;
  4086. char buf[28];//, usec_buf[6];
  4087. char tempdata[65]={0};
  4088. int tempIndex = 0;
  4089. DEBUG_INFO("sendStartTransactionRequest...\n");
  4090. gettimeofday(&tmnow, NULL);
  4091. time_t t;
  4092. t = time(NULL);
  4093. /*UTC time and date*/
  4094. tm = gmtime(&t);
  4095. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4096. #if 0 // remove temporally
  4097. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4098. strcat(buf,".");
  4099. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4100. strcat(buf,usec_buf);
  4101. #endif
  4102. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4103. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4104. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4105. // clear StartTransaction Response
  4106. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4107. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4108. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4109. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4110. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4112. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4113. {
  4114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4115. {
  4116. tempIndex = ((gun_index==2) ? 1: 0);
  4117. }
  4118. else
  4119. {
  4120. tempIndex = gun_index;
  4121. }
  4122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4123. {
  4124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4125. {
  4126. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4127. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4128. }
  4129. }
  4130. }
  4131. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4132. {
  4133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4134. {
  4135. tempIndex = ((gun_index==2) ? 1: 0);
  4136. }
  4137. else
  4138. {
  4139. tempIndex = gun_index;
  4140. }
  4141. for (int index = 0; index < CCS_QUANTITY; index++)
  4142. {
  4143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4144. {
  4145. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4146. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4147. }
  4148. }
  4149. }
  4150. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4151. {
  4152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4153. {
  4154. tempIndex = ((gun_index==2) ? 1: 0);
  4155. }
  4156. else
  4157. {
  4158. tempIndex = gun_index;
  4159. }
  4160. for (int index = 0; index < GB_QUANTITY; index++)
  4161. {
  4162. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4163. {
  4164. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4165. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4166. }
  4167. }
  4168. }
  4169. else if(gunType[gun_index] == GUN_TYPE_DO)
  4170. {
  4171. tempIndex = gun_index;
  4172. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4173. {
  4174. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4175. {
  4176. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4177. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4178. }
  4179. }
  4180. }
  4181. else
  4182. {
  4183. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4184. {
  4185. tempIndex = 2;
  4186. }
  4187. else
  4188. {
  4189. tempIndex = gun_index;
  4190. }
  4191. for (int index = 0; index < AC_QUANTITY; index++)
  4192. {
  4193. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4194. {
  4195. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4196. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4197. }
  4198. }
  4199. }
  4200. random_uuid(guid);
  4201. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4202. {
  4203. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4204. , gun_index +1
  4205. , MESSAGE_TYPE_CALL
  4206. , guid
  4207. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4208. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4209. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4210. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4211. }
  4212. else
  4213. {
  4214. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4215. , gun_index +1
  4216. , MESSAGE_TYPE_CALL
  4217. , guid
  4218. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4219. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4220. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4221. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4222. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4223. }
  4224. #if 1
  4225. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4226. 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*/)
  4227. {
  4228. result = PASS;
  4229. }
  4230. #endif
  4231. strcpy(queuedata, message);
  4232. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4233. OCPP_insert_transaction_msg(YES, queuedata);
  4234. return result;
  4235. }
  4236. int sendStatusNotificationRequest(int gun_index)
  4237. {
  4238. mtrace();
  4239. int result = FAIL;
  4240. char message[600]={0};
  4241. char guid[37];
  4242. int currentStatus = 0;
  4243. struct timeval tmnow;
  4244. struct tm *tm;
  4245. char buf[28];//, usec_buf[6];
  4246. char tempdata[65]={0};
  4247. int tempIndex = 0;
  4248. uint8_t isStateChanged = TRUE;
  4249. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4250. gettimeofday(&tmnow, NULL);
  4251. time_t t;
  4252. t = time(NULL);
  4253. /*UTC time and date*/
  4254. tm = gmtime(&t);
  4255. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4256. #if 0 // remove temporally
  4257. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4258. strcat(buf,".");
  4259. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4260. strcat(buf,usec_buf);
  4261. #endif
  4262. //printf("%s",buf);
  4263. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4264. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4265. // it's option
  4266. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4267. /*
  4268. enum _SYSTEM_STATUS
  4269. {
  4270. S_BOOTING = 0,
  4271. S_IDLE, = 1
  4272. S_AUTHORIZING, =2
  4273. S_REASSIGN_CHECK, =3
  4274. S_REASSIGN, =4
  4275. S_PRECHARGE, =5
  4276. S_PREPARING_FOR_EV, =6
  4277. S_PREPARING_FOR_EVSE, =7
  4278. S_CHARGING, =8
  4279. S_TERMINATING, =9
  4280. S_COMPLETE, =10
  4281. S_ALARM, =11
  4282. S_FAULT =12
  4283. }
  4284. */
  4285. //check Transaction active
  4286. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4287. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4288. {
  4289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4290. {
  4291. tempIndex = ((gun_index==2) ? 1: 0);
  4292. }
  4293. else
  4294. {
  4295. tempIndex = gun_index;
  4296. }
  4297. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4298. {
  4299. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4300. {
  4301. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4302. {
  4303. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4304. {
  4305. currentStatus = Preparing; //OCPP Status: Preparing
  4306. }
  4307. else
  4308. {
  4309. currentStatus = Available; //OCPP Status: Available
  4310. }
  4311. }
  4312. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4313. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4314. ) //S_PRECHARGE
  4315. {
  4316. currentStatus = Preparing; //OCPP Status: Preparing
  4317. }
  4318. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4319. {
  4320. currentStatus = Charging; //OCPP Status: Charging
  4321. }
  4322. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4323. {
  4324. currentStatus = Finishing; //OCPP Status: Finishing
  4325. }
  4326. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4327. {
  4328. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4329. }
  4330. 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
  4331. {
  4332. currentStatus = Unavailable; //OCPP Status: Unavailable
  4333. }
  4334. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4335. {
  4336. currentStatus = Faulted; //OCPP Status: Faulted
  4337. }
  4338. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4339. {
  4340. currentStatus = Reserved; //OCPP Status: Reserved
  4341. }
  4342. } //end of the same index
  4343. }//end of for CHAdeMO_QUANTITY
  4344. }
  4345. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4346. {
  4347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4348. {
  4349. tempIndex = ((gun_index==2) ? 1: 0);
  4350. }
  4351. else
  4352. {
  4353. tempIndex = gun_index;
  4354. }
  4355. for (int index = 0; index < CCS_QUANTITY; index++)
  4356. {
  4357. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4358. {
  4359. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4360. {
  4361. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4362. {
  4363. currentStatus = Preparing; //OCPP Status: Preparing
  4364. }
  4365. else
  4366. {
  4367. currentStatus = Available; //OCPP Status: Available
  4368. }
  4369. }
  4370. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4371. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4372. ) //S_PRECHARGE
  4373. {
  4374. currentStatus = Preparing; //OCPP Status: Preparing
  4375. }
  4376. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4377. {
  4378. currentStatus = Charging; //OCPP Status: Charging
  4379. }
  4380. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4381. {
  4382. currentStatus = Finishing; //OCPP Status: Finishing
  4383. }
  4384. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4385. {
  4386. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4387. }
  4388. 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
  4389. {
  4390. currentStatus = Unavailable; //OCPP Status : Unavailable
  4391. }
  4392. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4393. {
  4394. currentStatus = Faulted; //OCPP Status: Faulted
  4395. }
  4396. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4397. {
  4398. currentStatus = Reserved; //OCPP Status: Reserved
  4399. }
  4400. } //end of the same index
  4401. } // end of for CCS_QUANTITY
  4402. }
  4403. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < GB_QUANTITY; index++)
  4414. {
  4415. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4416. {
  4417. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4418. {
  4419. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4420. {
  4421. currentStatus = Preparing; //OCPP Status: Preparing
  4422. }
  4423. else
  4424. {
  4425. currentStatus = Available; //OCPP Status: Available
  4426. }
  4427. }
  4428. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4429. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4430. ) //S_PRECHARGE
  4431. {
  4432. currentStatus = Preparing; //OCPP Status: Preparing
  4433. }
  4434. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4435. {
  4436. currentStatus = Charging; //OCPP Status: Charging
  4437. }
  4438. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4439. {
  4440. currentStatus = Finishing; //OCPP Status: Finishing
  4441. }
  4442. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4443. {
  4444. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4445. }
  4446. 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
  4447. {
  4448. currentStatus = Unavailable; //OCPP Status: Unavailable
  4449. }
  4450. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4451. {
  4452. currentStatus = Faulted; //OCPP Status: Faulted
  4453. }
  4454. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4455. {
  4456. currentStatus = Reserved; //OCPP Status: Reserved
  4457. }
  4458. } //end of the same index
  4459. } // end of for GB_QUANTITY
  4460. }
  4461. else if(gunType[gun_index] == GUN_TYPE_DO)
  4462. {
  4463. tempIndex = gun_index;
  4464. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4465. {
  4466. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4467. {
  4468. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4469. {
  4470. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4471. {
  4472. currentStatus = Preparing; //OCPP Status: Preparing
  4473. }
  4474. else
  4475. {
  4476. currentStatus = Available; //OCPP Status: Available
  4477. }
  4478. }
  4479. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4480. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4481. ) //S_PRECHARGE
  4482. {
  4483. currentStatus = Preparing; //OCPP Status: Preparing
  4484. }
  4485. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4486. {
  4487. currentStatus = Charging; //OCPP Status: Charging
  4488. }
  4489. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4490. {
  4491. currentStatus = Finishing; //OCPP Status: Finishing
  4492. }
  4493. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4494. {
  4495. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4496. }
  4497. 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
  4498. {
  4499. currentStatus = Unavailable; //OCPP Status: Unavailable
  4500. }
  4501. 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
  4502. {
  4503. currentStatus = Faulted; //OCPP Status: Faulted
  4504. }
  4505. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4506. {
  4507. currentStatus = Reserved; //OCPP Status: Reserved
  4508. }
  4509. } //end of the same index
  4510. }
  4511. }
  4512. else
  4513. {
  4514. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4515. {
  4516. tempIndex = 2;
  4517. }
  4518. else
  4519. {
  4520. tempIndex = gun_index;
  4521. }
  4522. for (int index = 0; index < AC_QUANTITY; index++)
  4523. {
  4524. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4525. {
  4526. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4527. {
  4528. 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))
  4529. {
  4530. currentStatus = Preparing; //OCPP Status: Preparing
  4531. }
  4532. else
  4533. {
  4534. currentStatus = Available; //OCPP Status: Available
  4535. }
  4536. }
  4537. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4538. {
  4539. currentStatus = Preparing; //OCPP Status: Preparing
  4540. }
  4541. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4542. {
  4543. currentStatus = Charging; //OCPP Status: Charging
  4544. }
  4545. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4546. {
  4547. currentStatus = Finishing; //OCPP Status: Finishing
  4548. }
  4549. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4550. {
  4551. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4552. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4553. else
  4554. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4555. }
  4556. 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
  4557. {
  4558. currentStatus = Unavailable; //OCPP Status: Unavailable
  4559. }
  4560. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4561. {
  4562. currentStatus = Faulted; //OCPP Status: Faulted
  4563. }
  4564. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4565. {
  4566. currentStatus = Reserved; //OCPP Status: Reserved
  4567. }
  4568. }//end of the same index
  4569. }//end of for AC_QUANTITY
  4570. }
  4571. //it's option
  4572. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4573. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4574. {
  4575. isStateChanged = FALSE;
  4576. }
  4577. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4578. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4579. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4580. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4581. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4582. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4583. random_uuid(guid);
  4584. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4585. , MESSAGE_TYPE_CALL
  4586. , guid
  4587. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4588. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4589. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4590. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4591. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4592. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4593. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4594. if((server_sign == TRUE) && isStateChanged)
  4595. {
  4596. LWS_Send(message);
  4597. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4598. 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*/)
  4599. {
  4600. //DEBUG_ERROR("statusNotification mapitem pass");
  4601. result = PASS;
  4602. }
  4603. }
  4604. else
  4605. {
  4606. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4607. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4608. result = PASS;
  4609. }
  4610. return result;
  4611. }
  4612. int sendStopTransactionRequest(int gun_index)
  4613. {
  4614. mtrace();
  4615. int result = FAIL;
  4616. //char message[1500]={0};
  4617. char guid[37]={0};
  4618. char tempdata[65]={0};
  4619. int tempIndex = 0;
  4620. char TempStopTransaction[256];
  4621. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4622. //int idx_sample=0;
  4623. DEBUG_INFO("sendStopTransactionRequest \n");
  4624. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4625. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4626. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4627. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4628. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4629. {
  4630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4631. {
  4632. tempIndex = ((gun_index==2) ? 1: 0);
  4633. }
  4634. else
  4635. {
  4636. tempIndex = gun_index;
  4637. }
  4638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4639. {
  4640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4641. {
  4642. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4643. }
  4644. }// END OF CHAdeMO_QUANTITY
  4645. }
  4646. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4647. {
  4648. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4649. {
  4650. tempIndex = ((gun_index==2) ? 1: 0);
  4651. }
  4652. else
  4653. {
  4654. tempIndex = gun_index;
  4655. }
  4656. for (int index = 0; index < CCS_QUANTITY; index++)
  4657. {
  4658. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4659. {
  4660. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4661. }
  4662. }// END OF CCS_QUANTITY
  4663. }
  4664. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4665. {
  4666. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4667. {
  4668. tempIndex = ((gun_index==2) ? 1: 0);
  4669. }
  4670. else
  4671. {
  4672. tempIndex = gun_index;
  4673. }
  4674. for (int index = 0; index < GB_QUANTITY; index++)
  4675. {
  4676. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4677. {
  4678. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4679. }
  4680. }// END OF GB_QUANTITY
  4681. }
  4682. else if(gunType[gun_index] == GUN_TYPE_DO)
  4683. {
  4684. tempIndex = gun_index;
  4685. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4686. {
  4687. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4688. {
  4689. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4690. }
  4691. }// END OF GB_QUANTITY
  4692. }
  4693. else
  4694. {
  4695. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4696. {
  4697. tempIndex = 2;
  4698. }
  4699. else
  4700. {
  4701. tempIndex = gun_index;
  4702. }
  4703. for (int index = 0; index < AC_QUANTITY; index++)
  4704. {
  4705. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4706. {
  4707. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4708. }
  4709. }// END OF AC_QUANTITY
  4710. }
  4711. //====================================== Stop Transaction Time =====================================================
  4712. struct timeval tmnow;
  4713. struct tm *tm;
  4714. char buf[28];//, usec_buf[6];
  4715. gettimeofday(&tmnow, NULL);
  4716. time_t t;
  4717. t = time(NULL);
  4718. /*UTC time and date*/
  4719. tm = gmtime(&t);
  4720. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4721. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4722. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4723. random_uuid(guid);
  4724. /***********************************transactionData******************************************************/
  4725. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4727. //=================================
  4728. // Transaction_Begin
  4729. //=================================
  4730. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4731. {
  4732. //============================================ Energy.Active.Import.Interval ================================
  4733. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4734. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4735. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4736. 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*/]);
  4737. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4738. 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))
  4739. {
  4740. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4741. }
  4742. else
  4743. {
  4744. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4745. }
  4746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4748. }
  4749. //=================================
  4750. // Transaction_End
  4751. //=================================
  4752. // ================================= Current.Import L1 ===============================================
  4753. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4754. {
  4755. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4756. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4757. {
  4758. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4759. {
  4760. tempIndex = ((gun_index==2) ? 1: 0);
  4761. }
  4762. else
  4763. {
  4764. tempIndex = gun_index;
  4765. }
  4766. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4767. {
  4768. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4769. {
  4770. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4771. }
  4772. }// End of for CHAdeMO_QUANTITY
  4773. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4774. }
  4775. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4776. {
  4777. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4778. {
  4779. tempIndex = ((gun_index==2) ? 1: 0);
  4780. }
  4781. else
  4782. {
  4783. tempIndex = gun_index;
  4784. }
  4785. for (int index = 0; index < CCS_QUANTITY; index++)
  4786. {
  4787. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4788. {
  4789. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4790. }
  4791. }// End of for CCS_QUANTITY
  4792. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4793. }
  4794. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4795. {
  4796. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4797. {
  4798. tempIndex = ((gun_index==2) ? 1: 0);
  4799. }
  4800. else
  4801. {
  4802. tempIndex = gun_index;
  4803. }
  4804. for (int index = 0; index < GB_QUANTITY; index++)
  4805. {
  4806. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4807. {
  4808. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4809. }
  4810. }// End of for GB_QUANTITY
  4811. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4812. }
  4813. else if(gunType[gun_index] == GUN_TYPE_DO)
  4814. {
  4815. tempIndex = gun_index;
  4816. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4817. {
  4818. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4819. {
  4820. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4821. }
  4822. }
  4823. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4824. }
  4825. else
  4826. {
  4827. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4828. {
  4829. tempIndex = 2;
  4830. }
  4831. else
  4832. {
  4833. tempIndex = gun_index;
  4834. }
  4835. for (int index = 0; index < AC_QUANTITY; index++)
  4836. {
  4837. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4838. {
  4839. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4840. }
  4841. }// End of for AC_QUANTITY
  4842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4843. }
  4844. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4845. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4847. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4848. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4849. }
  4850. // ================================= Energy.Active.Import.Interval ==============================================
  4851. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4852. {
  4853. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4854. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4855. {
  4856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4857. {
  4858. tempIndex = ((gun_index==2) ? 1: 0);
  4859. }
  4860. else
  4861. {
  4862. tempIndex = gun_index;
  4863. }
  4864. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4865. {
  4866. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4867. {
  4868. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4869. }
  4870. }// END OF CHAdeMO_QUANTITY
  4871. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4872. }
  4873. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4874. {
  4875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4876. {
  4877. tempIndex = ((gun_index==2) ? 1: 0);
  4878. }
  4879. else
  4880. {
  4881. tempIndex = gun_index;
  4882. }
  4883. for (int index = 0; index < CCS_QUANTITY; index++)
  4884. {
  4885. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4886. {
  4887. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4888. }
  4889. }// END OF CCS_QUANTITY
  4890. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4891. }
  4892. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4893. {
  4894. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4895. {
  4896. tempIndex = ((gun_index==2) ? 1: 0);
  4897. }
  4898. else
  4899. {
  4900. tempIndex = gun_index;
  4901. }
  4902. for (int index = 0; index < GB_QUANTITY; index++)
  4903. {
  4904. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4905. {
  4906. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4907. }
  4908. }// END OF GB_QUANTITY
  4909. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4910. }
  4911. else if(gunType[gun_index] == GUN_TYPE_DO)
  4912. {
  4913. tempIndex = gun_index;
  4914. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4915. {
  4916. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4917. {
  4918. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4919. }
  4920. }
  4921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4922. }
  4923. else
  4924. {
  4925. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4926. {
  4927. tempIndex = 2;
  4928. }
  4929. else
  4930. {
  4931. tempIndex = gun_index;
  4932. }
  4933. for (int index = 0; index < AC_QUANTITY; index++)
  4934. {
  4935. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4936. {
  4937. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4938. }
  4939. }// END OF AC_QUANTITY
  4940. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4941. }
  4942. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4943. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4944. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4946. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4947. }
  4948. //=================================== Power.Active.Import ==================================================
  4949. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4950. {
  4951. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4952. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4953. {
  4954. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4955. {
  4956. tempIndex = ((gun_index==2) ? 1: 0);
  4957. }
  4958. else
  4959. {
  4960. tempIndex = gun_index;
  4961. }
  4962. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4963. {
  4964. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4965. {
  4966. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4967. }
  4968. } // End for CHAdeMO_QUANTITY
  4969. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4970. }
  4971. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4972. {
  4973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4974. {
  4975. tempIndex = ((gun_index==2) ? 1: 0);
  4976. }
  4977. else
  4978. {
  4979. tempIndex = gun_index;
  4980. }
  4981. for (int index = 0; index < CCS_QUANTITY; index++)
  4982. {
  4983. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4984. {
  4985. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4986. }
  4987. } // END for CCS_QUANTITY
  4988. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4989. }
  4990. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4991. {
  4992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4993. {
  4994. tempIndex = ((gun_index==2) ? 1: 0);
  4995. }
  4996. else
  4997. {
  4998. tempIndex = gun_index;
  4999. }
  5000. for (int index = 0; index < GB_QUANTITY; index++)
  5001. {
  5002. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5003. {
  5004. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5005. }
  5006. }// END for GB_QUANTITY
  5007. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5008. }
  5009. else if(gunType[gun_index] == GUN_TYPE_DO)
  5010. {
  5011. tempIndex = gun_index;
  5012. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5015. {
  5016. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5017. }
  5018. }
  5019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  5020. }
  5021. else
  5022. {
  5023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5024. {
  5025. tempIndex = 2;
  5026. }
  5027. else
  5028. {
  5029. tempIndex = gun_index;
  5030. }
  5031. for (int index = 0; index < AC_QUANTITY; index++)
  5032. {
  5033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5034. {
  5035. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5036. }
  5037. } // END for AC_QUANTITY
  5038. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5039. }
  5040. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5041. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5042. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5043. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5044. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5045. }
  5046. //============================ Voltage L1 ====================================
  5047. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5048. {
  5049. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5050. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5051. {
  5052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5053. {
  5054. tempIndex = ((gun_index==2) ? 1: 0);
  5055. }
  5056. else
  5057. {
  5058. tempIndex = gun_index;
  5059. }
  5060. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5061. {
  5062. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5063. {
  5064. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5065. }
  5066. } // END OF FOR CHAdeMO_QUANTITY
  5067. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5068. }
  5069. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5070. {
  5071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5072. {
  5073. tempIndex = ((gun_index==2) ? 1: 0);
  5074. }
  5075. else
  5076. {
  5077. tempIndex = gun_index;
  5078. }
  5079. for (int index = 0; index < CCS_QUANTITY; index++)
  5080. {
  5081. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5082. {
  5083. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5084. }
  5085. } // END OF FOR CCS_QUANTITY
  5086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5087. }
  5088. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5089. {
  5090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5091. {
  5092. tempIndex = ((gun_index==2) ? 1: 0);
  5093. }
  5094. else
  5095. {
  5096. tempIndex = gun_index;
  5097. }
  5098. for (int index = 0; index < GB_QUANTITY; index++)
  5099. {
  5100. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5101. {
  5102. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5103. }
  5104. } // END OF FOR GB_QUANTITY
  5105. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5106. }
  5107. else if(gunType[gun_index] == GUN_TYPE_DO)
  5108. {
  5109. tempIndex = gun_index;
  5110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5111. {
  5112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5113. {
  5114. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5115. }
  5116. }
  5117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5118. }
  5119. else
  5120. {
  5121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5122. {
  5123. tempIndex = 2;
  5124. }
  5125. else
  5126. {
  5127. tempIndex = gun_index;
  5128. }
  5129. for (int index = 0; index < AC_QUANTITY; index++)
  5130. {
  5131. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5132. {
  5133. 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
  5134. }
  5135. } // END OF FOR AC_QUANTITY
  5136. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5137. }
  5138. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5139. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5140. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5141. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5142. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5143. }
  5144. //====================== End SoC ================================
  5145. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5146. {
  5147. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5148. 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))
  5149. {
  5150. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5151. {
  5152. tempIndex = ((gun_index==2) ? 1: 0);
  5153. }
  5154. else
  5155. {
  5156. tempIndex = gun_index;
  5157. }
  5158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5159. {
  5160. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5161. {
  5162. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5163. {
  5164. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5165. }
  5166. }
  5167. }
  5168. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5169. {
  5170. for (int index = 0; index < CCS_QUANTITY; index++)
  5171. {
  5172. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5173. {
  5174. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5175. }
  5176. }
  5177. }
  5178. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5179. {
  5180. for (int index = 0; index < GB_QUANTITY; index++)
  5181. {
  5182. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5183. {
  5184. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5185. }
  5186. }
  5187. }
  5188. else if(gunType[gun_index] == GUN_TYPE_DO)
  5189. {
  5190. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5191. {
  5192. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5193. {
  5194. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5195. }
  5196. }
  5197. }
  5198. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5201. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5202. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5203. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5204. } // END FOR DC CASE
  5205. }
  5206. // ================================= Current.Import L2 ===============================================
  5207. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5208. {
  5209. // AC 3 phse L2 current
  5210. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5211. {
  5212. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5213. {
  5214. tempIndex = 2;
  5215. }
  5216. else
  5217. {
  5218. tempIndex = gun_index;
  5219. }
  5220. for (int index = 0; index < AC_QUANTITY; index++)
  5221. {
  5222. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5223. {
  5224. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5225. }
  5226. }// End of for AC_QUANTITY
  5227. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5228. }
  5229. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5230. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5231. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5232. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5233. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5234. }
  5235. // ================================= Current.Import L3 ===============================================
  5236. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5237. {
  5238. // AC 3 phse L3 current
  5239. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5240. {
  5241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5242. {
  5243. tempIndex = 2;
  5244. }
  5245. else
  5246. {
  5247. tempIndex = gun_index;
  5248. }
  5249. for (int index = 0; index < AC_QUANTITY; index++)
  5250. {
  5251. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5252. {
  5253. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5254. }
  5255. }// End of for AC_QUANTITY
  5256. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5257. }
  5258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5259. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5260. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5261. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5262. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5263. }
  5264. //============================ Voltage L2 ====================================
  5265. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5266. {
  5267. // AC 3 phse L2 voltage
  5268. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5269. {
  5270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5271. {
  5272. tempIndex = 2;
  5273. }
  5274. else
  5275. {
  5276. tempIndex = gun_index;
  5277. }
  5278. for (int index = 0; index < AC_QUANTITY; index++)
  5279. {
  5280. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5281. {
  5282. 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
  5283. }
  5284. } // END OF FOR AC_QUANTITY
  5285. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5286. }
  5287. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5288. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5289. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5290. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5291. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5292. }
  5293. //============================ Voltage L3 ====================================
  5294. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5295. {
  5296. // AC 3 phse L3 voltage
  5297. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5298. {
  5299. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5300. {
  5301. tempIndex = 2;
  5302. }
  5303. else
  5304. {
  5305. tempIndex = gun_index;
  5306. }
  5307. for (int index = 0; index < AC_QUANTITY; index++)
  5308. {
  5309. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5310. {
  5311. 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
  5312. }
  5313. } // END OF FOR AC_QUANTITY
  5314. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5315. }
  5316. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5317. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5318. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5319. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5320. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5321. }
  5322. //====================== Start SoC ================================
  5323. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5324. {
  5325. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5326. 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))
  5327. {
  5328. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5329. {
  5330. tempIndex = ((gun_index==2) ? 1: 0);
  5331. }
  5332. else
  5333. {
  5334. tempIndex = gun_index;
  5335. }
  5336. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5337. {
  5338. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5339. {
  5340. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5341. {
  5342. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5343. }
  5344. }
  5345. }
  5346. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5347. {
  5348. for (int index = 0; index < CCS_QUANTITY; index++)
  5349. {
  5350. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5351. {
  5352. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5353. }
  5354. }
  5355. }
  5356. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5357. {
  5358. for (int index = 0; index < GB_QUANTITY; index++)
  5359. {
  5360. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5361. {
  5362. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5363. }
  5364. }
  5365. }
  5366. else if(gunType[gun_index] == GUN_TYPE_DO)
  5367. {
  5368. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5369. {
  5370. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5371. {
  5372. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5373. }
  5374. }
  5375. }
  5376. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5378. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5382. } // END FOR DC CASE
  5383. }
  5384. //================================================ Message create ====================================================
  5385. json_object *StopTransaction = json_object_new_object();
  5386. json_object *transactionDatas = json_object_new_array();
  5387. json_object *sampledValues = json_object_new_array();
  5388. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5389. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5390. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5391. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5392. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5393. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5394. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5395. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5396. {
  5397. json_object *transactionData = json_object_new_object();
  5398. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5399. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5400. {
  5401. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5402. {
  5403. json_object *sampledValue = json_object_new_object();
  5404. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5405. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5406. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5407. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5408. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5409. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5410. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5411. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5412. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5413. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5414. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5415. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5416. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5417. json_object_array_add(sampledValues, sampledValue);
  5418. }
  5419. }
  5420. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5421. json_object_array_add(transactionDatas, transactionData);
  5422. }
  5423. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5424. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5425. ,MESSAGE_TYPE_CALL
  5426. ,guid
  5427. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5428. json_object_put(StopTransaction);
  5429. #if 1 // for TempStopTransaction
  5430. //Delete TempStopTransaction
  5431. if((access(TempStopTransaction,F_OK))!=-1)
  5432. {
  5433. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5434. }
  5435. #endif
  5436. #if 1
  5437. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5438. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5439. {
  5440. result = PASS;
  5441. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5442. }
  5443. #endif
  5444. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5445. OCPP_insert_transaction_msg(NO, queuedata);
  5446. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5447. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5448. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5449. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5450. {
  5451. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5452. }
  5453. //for test
  5454. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5455. return result;
  5456. }
  5457. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5458. {
  5459. mtrace();
  5460. int result = FAIL;
  5461. char guid[37]={0};
  5462. char tempdata[65]={0};
  5463. int tempIndex = 0;
  5464. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5465. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5466. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5467. //set value
  5468. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5469. 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) )?
  5470. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5471. -1);
  5472. random_uuid(guid);
  5473. //UTC Date time
  5474. struct timeval tmnow;
  5475. struct tm *tm;
  5476. char buf[28];//, usec_buf[6];
  5477. gettimeofday(&tmnow, NULL);
  5478. time_t t;
  5479. t = time(NULL);
  5480. /*UTC time and date*/
  5481. tm = gmtime(&t);
  5482. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5483. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5484. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5485. //********************************(1)Current.Import L1************************************************/
  5486. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5487. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5488. (dataType == ReadingContext_Trigger))
  5489. {
  5490. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5491. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5492. {
  5493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5494. {
  5495. tempIndex = ((gun_index==2) ? 1: 0);
  5496. }
  5497. else
  5498. {
  5499. tempIndex = gun_index;
  5500. }
  5501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5502. {
  5503. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5504. {
  5505. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5506. }
  5507. }
  5508. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5509. }
  5510. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5511. {
  5512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5513. {
  5514. tempIndex = ((gun_index==2) ? 1: 0);
  5515. }
  5516. else
  5517. {
  5518. tempIndex = gun_index;
  5519. }
  5520. for (int index = 0; index < CCS_QUANTITY; index++)
  5521. {
  5522. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5523. {
  5524. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5525. }
  5526. }
  5527. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5528. }
  5529. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5530. {
  5531. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5532. {
  5533. tempIndex = ((gun_index==2) ? 1: 0);
  5534. }
  5535. else
  5536. {
  5537. tempIndex = gun_index;
  5538. }
  5539. for (int index = 0; index < GB_QUANTITY; index++)
  5540. {
  5541. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5542. {
  5543. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5544. }
  5545. }
  5546. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5547. }
  5548. else if(gunType[gun_index] == GUN_TYPE_DO)
  5549. {
  5550. tempIndex = gun_index;
  5551. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5552. {
  5553. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5554. {
  5555. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5556. }
  5557. }
  5558. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5559. }
  5560. else
  5561. {
  5562. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5563. {
  5564. tempIndex = 2;
  5565. }
  5566. else
  5567. {
  5568. tempIndex = gun_index;
  5569. }
  5570. for (int index = 0; index < AC_QUANTITY; index++)
  5571. {
  5572. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5573. {
  5574. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5575. }
  5576. }
  5577. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5578. }
  5579. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5580. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5581. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5582. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5583. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5584. }
  5585. //********************************(2)Energy.Active.Import.Register ************************************************/
  5586. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5587. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5588. (dataType == ReadingContext_Trigger))
  5589. {
  5590. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5591. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5592. {
  5593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5594. {
  5595. tempIndex = ((gun_index==2) ? 1: 0);
  5596. }
  5597. else
  5598. {
  5599. tempIndex = gun_index;
  5600. }
  5601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5602. {
  5603. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5604. {
  5605. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5606. }
  5607. }
  5608. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5609. }
  5610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5611. {
  5612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5613. {
  5614. tempIndex = ((gun_index==2) ? 1: 0);
  5615. }
  5616. else
  5617. {
  5618. tempIndex = gun_index;
  5619. }
  5620. for (int index = 0; index < CCS_QUANTITY; index++)
  5621. {
  5622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5623. {
  5624. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5625. }
  5626. }
  5627. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5628. }
  5629. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5630. {
  5631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5632. {
  5633. tempIndex = ((gun_index==2) ? 1: 0);
  5634. }
  5635. else
  5636. {
  5637. tempIndex = gun_index;
  5638. }
  5639. for (int index = 0; index < GB_QUANTITY; index++)
  5640. {
  5641. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5642. {
  5643. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5644. }
  5645. }
  5646. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5647. }
  5648. else if(gunType[gun_index] == GUN_TYPE_DO)
  5649. {
  5650. tempIndex = gun_index;
  5651. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5652. {
  5653. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5654. {
  5655. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5656. }
  5657. }
  5658. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5659. }
  5660. else
  5661. {
  5662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5663. {
  5664. tempIndex = 2;
  5665. }
  5666. else
  5667. {
  5668. tempIndex = gun_index;
  5669. }
  5670. for (int index = 0; index < AC_QUANTITY; index++)
  5671. {
  5672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5673. {
  5674. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5675. }
  5676. }
  5677. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5678. }
  5679. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5680. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5681. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5682. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5683. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5684. }
  5685. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5686. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5687. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5688. (dataType == ReadingContext_Trigger))
  5689. {
  5690. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5691. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5692. {
  5693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5694. {
  5695. tempIndex = ((gun_index==2) ? 1: 0);
  5696. }
  5697. else
  5698. {
  5699. tempIndex = gun_index;
  5700. }
  5701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5702. {
  5703. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5704. {
  5705. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5706. }
  5707. } // END OF FOR CHAdeMO_QUANTITY
  5708. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5709. }
  5710. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5711. {
  5712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5713. {
  5714. tempIndex = ((gun_index==2) ? 1: 0);
  5715. }
  5716. else
  5717. {
  5718. tempIndex = gun_index;
  5719. }
  5720. for (int index = 0; index < CCS_QUANTITY; index++)
  5721. {
  5722. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5723. {
  5724. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5725. }
  5726. } // END OF CCS_QUANTITY
  5727. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5728. }
  5729. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5730. {
  5731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5732. {
  5733. tempIndex = ((gun_index==2) ? 1: 0);
  5734. }
  5735. else
  5736. {
  5737. tempIndex = gun_index;
  5738. }
  5739. for (int index = 0; index < GB_QUANTITY; index++)
  5740. {
  5741. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5742. {
  5743. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5744. }
  5745. } // END OF GB_QUANTITY
  5746. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5747. }
  5748. else if(gunType[gun_index] == GUN_TYPE_DO)
  5749. {
  5750. tempIndex = gun_index;
  5751. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5752. {
  5753. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5754. {
  5755. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5756. }
  5757. }
  5758. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5759. }
  5760. else
  5761. {
  5762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5763. {
  5764. tempIndex = 2;
  5765. }
  5766. else
  5767. {
  5768. tempIndex = gun_index;
  5769. }
  5770. for (int index = 0; index < AC_QUANTITY; index++)
  5771. {
  5772. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5773. {
  5774. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5775. }
  5776. }
  5777. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5778. }
  5779. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5780. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5781. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5782. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5783. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5784. }
  5785. //********************************(4)Power.Active.Import************************************************/
  5786. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5787. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5788. (dataType == ReadingContext_Trigger))
  5789. {
  5790. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5791. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5792. {
  5793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5794. {
  5795. tempIndex = ((gun_index==2) ? 1: 0);
  5796. }
  5797. else
  5798. {
  5799. tempIndex = gun_index;
  5800. }
  5801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5802. {
  5803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5804. {
  5805. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5806. }
  5807. } // END OF FOR
  5808. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5809. }
  5810. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5811. {
  5812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5813. {
  5814. tempIndex = ((gun_index==2) ? 1: 0);
  5815. }
  5816. else
  5817. {
  5818. tempIndex = gun_index;
  5819. }
  5820. for (int index = 0; index < CCS_QUANTITY; index++)
  5821. {
  5822. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5823. {
  5824. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5825. }
  5826. }
  5827. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5828. }
  5829. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5830. {
  5831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5832. {
  5833. tempIndex = ((gun_index==2) ? 1: 0);
  5834. }
  5835. else
  5836. {
  5837. tempIndex = gun_index;
  5838. }
  5839. for (int index = 0; index < GB_QUANTITY; index++)
  5840. {
  5841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5842. {
  5843. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5844. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5845. }
  5846. }
  5847. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5848. }
  5849. else if(gunType[gun_index] == GUN_TYPE_DO)
  5850. {
  5851. tempIndex = gun_index;
  5852. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5853. {
  5854. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5855. {
  5856. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5857. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5858. }
  5859. }
  5860. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5861. }
  5862. else
  5863. {
  5864. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5865. {
  5866. tempIndex = 2;
  5867. }
  5868. else
  5869. {
  5870. tempIndex = gun_index;
  5871. }
  5872. for (int index = 0; index < AC_QUANTITY; index++)
  5873. {
  5874. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5875. {
  5876. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5877. }
  5878. }
  5879. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5880. }
  5881. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5882. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5883. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5884. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5885. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5886. }
  5887. //***********************************************(5)VOLTAGE L1******************************************************/
  5888. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5889. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5890. (dataType == ReadingContext_Trigger))
  5891. {
  5892. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5893. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5894. {
  5895. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5896. {
  5897. tempIndex = ((gun_index==2) ? 1: 0);
  5898. }
  5899. else
  5900. {
  5901. tempIndex = gun_index;
  5902. }
  5903. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5904. {
  5905. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5906. {
  5907. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5908. }
  5909. }
  5910. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5911. }
  5912. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5913. {
  5914. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5915. {
  5916. tempIndex = ((gun_index==2) ? 1: 0);
  5917. }
  5918. else
  5919. {
  5920. tempIndex = gun_index;
  5921. }
  5922. for (int index = 0; index < CCS_QUANTITY; index++)
  5923. {
  5924. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5925. {
  5926. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5927. }
  5928. }
  5929. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5930. }
  5931. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5932. {
  5933. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5934. {
  5935. tempIndex = ((gun_index==2) ? 1: 0);
  5936. }
  5937. else
  5938. {
  5939. tempIndex = gun_index;
  5940. }
  5941. for (int index = 0; index < GB_QUANTITY; index++)
  5942. {
  5943. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5944. {
  5945. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5946. }
  5947. }
  5948. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5949. }
  5950. else if(gunType[gun_index] == GUN_TYPE_DO)
  5951. {
  5952. tempIndex = gun_index;
  5953. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5954. {
  5955. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5956. {
  5957. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5958. }
  5959. }
  5960. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5961. }
  5962. else
  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[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5977. }
  5978. }
  5979. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5980. }
  5981. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5982. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5983. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5984. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5985. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5986. }
  5987. //***********************************************(6)SOC******************************************************/
  5988. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  5989. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  5990. (dataType == ReadingContext_Trigger))
  5991. {
  5992. 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))
  5993. {
  5994. //idx_sample=5;
  5995. //sampledValue = NULL;
  5996. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5997. {
  5998. tempIndex = ((gun_index==2) ? 1: 0);
  5999. }
  6000. else
  6001. {
  6002. tempIndex = gun_index;
  6003. }
  6004. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6005. {
  6006. //tempIndex = ((gun_index==2) ? 1: 0);
  6007. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6008. {
  6009. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6010. {
  6011. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  6012. }
  6013. }
  6014. }
  6015. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6016. {
  6017. //tempIndex = ((gun_index==2) ? 1: 0);
  6018. for (int index = 0; index < CCS_QUANTITY; index++)
  6019. {
  6020. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6021. {
  6022. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  6023. }
  6024. }
  6025. }
  6026. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6027. {
  6028. //tempIndex = ((gun_index==2) ? 1: 0);
  6029. for (int index = 0; index < GB_QUANTITY; index++)
  6030. {
  6031. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6032. {
  6033. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6034. }
  6035. }
  6036. }
  6037. else if(gunType[gun_index] == GUN_TYPE_DO)
  6038. {
  6039. //tempIndex = ((gun_index==2) ? 1: 0);
  6040. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6045. }
  6046. }
  6047. }
  6048. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6050. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6051. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6054. }
  6055. }
  6056. //********************************(7)Current.Import L2************************************************/
  6057. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6058. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6059. (dataType == ReadingContext_Trigger))
  6060. {
  6061. // Only for AC 3 phase
  6062. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6063. {
  6064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6065. {
  6066. tempIndex = 2;
  6067. }
  6068. else
  6069. {
  6070. tempIndex = gun_index;
  6071. }
  6072. for (int index = 0; index < AC_QUANTITY; index++)
  6073. {
  6074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6075. {
  6076. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6077. }
  6078. }
  6079. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6080. }
  6081. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6083. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6084. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6085. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6086. }
  6087. //********************************(8)Current.Import L3************************************************/
  6088. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6089. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6090. (dataType == ReadingContext_Trigger))
  6091. {
  6092. // Only for AC 3 phase
  6093. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6094. {
  6095. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6096. {
  6097. tempIndex = 2;
  6098. }
  6099. else
  6100. {
  6101. tempIndex = gun_index;
  6102. }
  6103. for (int index = 0; index < AC_QUANTITY; index++)
  6104. {
  6105. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6106. {
  6107. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6108. }
  6109. }
  6110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6111. }
  6112. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6114. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6115. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6116. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6117. }
  6118. //***********************************************(9)VOLTAGE L2******************************************************/
  6119. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6120. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6121. (dataType == ReadingContext_Trigger))
  6122. {
  6123. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6124. {
  6125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6126. {
  6127. tempIndex = 2;
  6128. }
  6129. else
  6130. {
  6131. tempIndex = gun_index;
  6132. }
  6133. for (int index = 0; index < AC_QUANTITY; index++)
  6134. {
  6135. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6136. {
  6137. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6138. }
  6139. }
  6140. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6141. }
  6142. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6143. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6144. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6145. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6146. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6147. }
  6148. //***********************************************(10)VOLTAGE L3******************************************************/
  6149. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6150. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6151. (dataType == ReadingContext_Trigger))
  6152. {
  6153. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6154. {
  6155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6156. {
  6157. tempIndex = 2;
  6158. }
  6159. else
  6160. {
  6161. tempIndex = gun_index;
  6162. }
  6163. for (int index = 0; index < AC_QUANTITY; index++)
  6164. {
  6165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6166. {
  6167. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6168. }
  6169. }
  6170. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6171. }
  6172. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6173. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6174. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6175. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6176. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6177. }
  6178. //***********************************************(11)Current.Offered******************************************************/
  6179. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6180. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6181. (dataType == ReadingContext_Trigger))
  6182. {
  6183. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6184. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6185. {
  6186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6187. {
  6188. tempIndex = ((gun_index==2) ? 1: 0);
  6189. }
  6190. else
  6191. {
  6192. tempIndex = gun_index;
  6193. }
  6194. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6195. {
  6196. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6197. {
  6198. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6199. }
  6200. } // END OF FOR CHAdeMO_QUANTITY
  6201. }
  6202. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6203. {
  6204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6205. {
  6206. tempIndex = ((gun_index==2) ? 1: 0);
  6207. }
  6208. else
  6209. {
  6210. tempIndex = gun_index;
  6211. }
  6212. for (int index = 0; index < CCS_QUANTITY; index++)
  6213. {
  6214. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6215. {
  6216. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6217. }
  6218. } // END OF CCS_QUANTITY
  6219. }
  6220. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6221. {
  6222. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6223. {
  6224. tempIndex = ((gun_index==2) ? 1: 0);
  6225. }
  6226. else
  6227. {
  6228. tempIndex = gun_index;
  6229. }
  6230. for (int index = 0; index < GB_QUANTITY; index++)
  6231. {
  6232. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6233. {
  6234. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6235. }
  6236. } // END OF GB_QUANTITY
  6237. }
  6238. else if(gunType[gun_index] == GUN_TYPE_DO)
  6239. {
  6240. tempIndex = gun_index;
  6241. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6242. {
  6243. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6244. {
  6245. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6246. }
  6247. }
  6248. }
  6249. else
  6250. {
  6251. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6252. {
  6253. tempIndex = 2;
  6254. }
  6255. else
  6256. {
  6257. tempIndex = gun_index;
  6258. }
  6259. for (int index = 0; index < AC_QUANTITY; index++)
  6260. {
  6261. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6262. {
  6263. uint16_t currentOffer;
  6264. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6265. {
  6266. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6267. }
  6268. else
  6269. {
  6270. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6271. }
  6272. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6273. }
  6274. }
  6275. }
  6276. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6277. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6278. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6279. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6280. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6281. }
  6282. //***********************************************(12)Power.Offered******************************************************/
  6283. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6284. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6285. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6286. {
  6287. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6288. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6289. {
  6290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6291. {
  6292. tempIndex = ((gun_index==2) ? 1: 0);
  6293. }
  6294. else
  6295. {
  6296. tempIndex = gun_index;
  6297. }
  6298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6299. {
  6300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6301. {
  6302. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6303. }
  6304. } // END OF FOR CHAdeMO_QUANTITY
  6305. }
  6306. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6307. {
  6308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6309. {
  6310. tempIndex = ((gun_index==2) ? 1: 0);
  6311. }
  6312. else
  6313. {
  6314. tempIndex = gun_index;
  6315. }
  6316. for (int index = 0; index < CCS_QUANTITY; index++)
  6317. {
  6318. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6319. {
  6320. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6321. }
  6322. } // END OF CCS_QUANTITY
  6323. }
  6324. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6325. {
  6326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6327. {
  6328. tempIndex = ((gun_index==2) ? 1: 0);
  6329. }
  6330. else
  6331. {
  6332. tempIndex = gun_index;
  6333. }
  6334. for (int index = 0; index < GB_QUANTITY; index++)
  6335. {
  6336. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6337. {
  6338. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6339. }
  6340. } // END OF GB_QUANTITY
  6341. }
  6342. else if(gunType[gun_index] == GUN_TYPE_DO)
  6343. {
  6344. tempIndex = gun_index;
  6345. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6346. {
  6347. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6348. {
  6349. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6350. }
  6351. }
  6352. }
  6353. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6354. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6355. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6356. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6357. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6358. }
  6359. // Message create ====================================================================================================
  6360. if(TRUE)
  6361. {
  6362. json_object *MeterValueReq = json_object_new_object();
  6363. json_object *MeterValues = json_object_new_array();
  6364. json_object *sampledValues = json_object_new_array();
  6365. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6366. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6367. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6368. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6369. {
  6370. json_object *MeterValue = json_object_new_object();
  6371. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6372. {
  6373. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6374. {
  6375. json_object *sampledValue = json_object_new_object();
  6376. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6377. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6378. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6379. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6380. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6381. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6382. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6383. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6384. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6385. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6386. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6387. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6388. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6389. json_object_array_add(sampledValues, sampledValue);
  6390. }
  6391. }
  6392. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6393. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6394. json_object_array_add(MeterValues, MeterValue);
  6395. }
  6396. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6397. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6398. ,gun_index + 1
  6399. ,MESSAGE_TYPE_CALL
  6400. ,guid
  6401. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6402. json_object_put(MeterValueReq);
  6403. }
  6404. // Put request guid to hash map
  6405. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6406. 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*/)
  6407. {
  6408. result = PASS;
  6409. //DEBUG_INFO("MeterValues mapitem pass\n");
  6410. }
  6411. if((dataType != ReadingContext_Trigger) &&
  6412. (dataType != ReadingContext_Sample_Clock) &&
  6413. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6414. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6415. else
  6416. {
  6417. if(FirstHeartBeat)
  6418. LWS_Send(queuedata +2);
  6419. }
  6420. return result;
  6421. }
  6422. int sendLogStatusNotificationRequest(char *status)
  6423. {
  6424. mtrace();
  6425. int result = PASS;
  6426. char message[4096]={0};
  6427. char guid[37]={0};
  6428. char tempdata[128]={0};
  6429. json_object *LogStatusNotification = json_object_new_object();
  6430. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6431. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6432. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6433. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6434. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6435. random_uuid(guid);
  6436. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6437. json_object_put(LogStatusNotification);
  6438. LWS_Send(message);
  6439. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6440. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6441. {
  6442. result = PASS;
  6443. }
  6444. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6445. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6446. return result;
  6447. }
  6448. int sendSecurityEventNotificationRequest()
  6449. {
  6450. mtrace();
  6451. int result = PASS;
  6452. char message[4096]={0};
  6453. char guid[37]={0};
  6454. char tempdata[128]={0};
  6455. json_object *SecurityEventNotification = json_object_new_object();
  6456. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6457. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6458. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6459. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6460. random_uuid(guid);
  6461. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6462. json_object_put(SecurityEventNotification);
  6463. LWS_Send(message);
  6464. sprintf(tempdata, "SecurityEventNotification,0");
  6465. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6466. {
  6467. result = PASS;
  6468. }
  6469. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6470. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6471. return result;
  6472. }
  6473. int sendSignCertificateRequest()
  6474. {
  6475. mtrace();
  6476. int result = PASS;
  6477. char message[4096]={0};
  6478. char guid[37]={0};
  6479. char tempdata[128]={0};
  6480. json_object *SignCertificate = json_object_new_object();
  6481. DEBUG_INFO("sendSignCertificateRequest...\n");
  6482. // Read csr file content
  6483. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6484. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6485. char *line = NULL;
  6486. size_t len = 0;
  6487. while(getline(&line, &len, fp) != -1)
  6488. {
  6489. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6490. {
  6491. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6492. }
  6493. }
  6494. fclose(fp);
  6495. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6496. random_uuid(guid);
  6497. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6498. json_object_put(SignCertificate);
  6499. LWS_Send(message);
  6500. sprintf(tempdata, "SignCertificate,0");
  6501. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6502. {
  6503. result = PASS;
  6504. }
  6505. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6506. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6507. return result;
  6508. }
  6509. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6510. {
  6511. mtrace();
  6512. int result = PASS;
  6513. char message[110]={0};
  6514. char guid[37]={0};
  6515. char tempdata[65]={0};
  6516. json_object *FirmwareStatusNotification = json_object_new_object();
  6517. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6518. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6519. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6520. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6521. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6522. random_uuid(guid);
  6523. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6524. json_object_put(FirmwareStatusNotification);
  6525. LWS_Send(message);
  6526. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6527. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6528. {
  6529. result = PASS;
  6530. }
  6531. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6532. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6533. return result;
  6534. }
  6535. //==========================================
  6536. // send confirm routine
  6537. //==========================================
  6538. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6539. {
  6540. mtrace();
  6541. int result = FAIL;
  6542. char message[100]={0};
  6543. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6544. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6545. LWS_Send(message);
  6546. result = TRUE;
  6547. return result;
  6548. }
  6549. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6550. {
  6551. mtrace();
  6552. int result = FAIL;
  6553. char message[100]={0};
  6554. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6555. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6556. LWS_Send(message);
  6557. result = TRUE;
  6558. return result;
  6559. }
  6560. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6561. {
  6562. mtrace();
  6563. int result = FAIL;
  6564. char message[100]={0};
  6565. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6566. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6567. LWS_Send(message);
  6568. result = TRUE;
  6569. return result;
  6570. }
  6571. int sendClearCacheConfirmation(char *uuid,char *payload)
  6572. {
  6573. mtrace();
  6574. int result = FAIL;
  6575. char message[500]={0};
  6576. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6577. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6578. LWS_Send(message);
  6579. return result;
  6580. }
  6581. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6582. {
  6583. mtrace();
  6584. int result = FAIL;
  6585. char message[500]={0};
  6586. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6587. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6588. LWS_Send(message);
  6589. return result;
  6590. }
  6591. int sendDataTransferConfirmation(char *uuid,char *payload)
  6592. {
  6593. mtrace();
  6594. char statusStr[20]={0};
  6595. char dataStr[10]={0};
  6596. char sstr[20]={0};
  6597. int c = 0;
  6598. char *loc;
  6599. int result = FAIL;
  6600. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6601. /**********************status**************************/
  6602. loc = strstr(payload, "status");
  6603. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6604. c = 0;
  6605. while (loc[3+strlen("status")+c] != '\"')
  6606. {
  6607. sstr[c] = loc[3+strlen("status")+c];
  6608. c++;
  6609. }
  6610. sstr[c] = '\0';
  6611. strcpy(statusStr, sstr);
  6612. /**********************data**************************/
  6613. loc = strstr(payload, "data");
  6614. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6615. c = 0;
  6616. while (loc[3+strlen("data")+c] != '\"')
  6617. {
  6618. sstr[c] = loc[3+strlen("data")+c];
  6619. c++;
  6620. }
  6621. sstr[c] = '\0';
  6622. strcpy(dataStr, sstr);
  6623. return result;
  6624. }
  6625. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6626. {
  6627. mtrace();
  6628. int result = FAIL;
  6629. char message[1000]={0};
  6630. int CompositeScheduleIndex = 0;
  6631. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6632. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6633. if(nPeriod == 0)
  6634. {
  6635. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6636. {
  6637. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6638. ,MESSAGE_TYPE_CALLRESULT
  6639. ,uuid
  6640. ,payload
  6641. ,connectorIdInt);
  6642. }
  6643. else
  6644. {
  6645. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6646. ,MESSAGE_TYPE_CALLRESULT
  6647. ,uuid
  6648. ,payload
  6649. ,connectorIdInt
  6650. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6651. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6652. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6653. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6654. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6655. }
  6656. }
  6657. else
  6658. {
  6659. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6660. ,MESSAGE_TYPE_CALLRESULT
  6661. ,uuid
  6662. ,payload
  6663. ,connectorIdInt
  6664. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6665. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6666. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6667. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6668. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6669. {
  6670. if (idx_sample == 0)
  6671. {
  6672. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6673. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6674. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6675. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6676. }
  6677. else
  6678. {
  6679. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6680. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6681. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6682. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6683. }
  6684. }
  6685. sprintf(message + strlen(message), "]}}]");
  6686. }
  6687. LWS_Send(message);
  6688. result = TRUE;
  6689. return result;
  6690. }
  6691. int sendGetConfigurationConfirmation(char *uuid)
  6692. {
  6693. mtrace();
  6694. int result = FAIL;
  6695. int MaxKeySupported = 0;
  6696. int sentConfigurationNumber= 0;
  6697. int sentunConfigurationNumber= 0;
  6698. char message[1024*10]={0};
  6699. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6700. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6701. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6702. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6703. ,MESSAGE_TYPE_CALLRESULT
  6704. ,uuid );
  6705. //configuration key
  6706. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6707. {
  6708. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6709. {
  6710. if (sentConfigurationNumber == 0)
  6711. {
  6712. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6713. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6714. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6715. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6716. }
  6717. else
  6718. {
  6719. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6720. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6721. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6722. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6723. }
  6724. sentConfigurationNumber = sentConfigurationNumber + 1;
  6725. }
  6726. }
  6727. sprintf(message + strlen(message), "]");
  6728. if(UnknownKeynum != 0)
  6729. {
  6730. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6731. //unkown key
  6732. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6733. {
  6734. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6735. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6736. if(sentunConfigurationNumber == 0)
  6737. {
  6738. sprintf(message + strlen(message), "\"%s\""
  6739. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6740. }
  6741. else
  6742. {
  6743. sprintf(message + strlen(message), ",\"%s\""
  6744. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6745. }
  6746. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6747. }
  6748. sprintf(message + strlen(message), "]");
  6749. }
  6750. sprintf(message + strlen(message), "}]");
  6751. LWS_Send(message);
  6752. return result;
  6753. }
  6754. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6755. {
  6756. mtrace();
  6757. int result = FAIL;
  6758. char message[400]={0};
  6759. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6760. if(strcmp(payload,"")==0)
  6761. {
  6762. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6763. }
  6764. else
  6765. {
  6766. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6767. }
  6768. LWS_Send(message);
  6769. result = TRUE;
  6770. return result;
  6771. }
  6772. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6773. {
  6774. mtrace();
  6775. int result = FAIL;
  6776. char message[80]={0};
  6777. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6778. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  6779. LWS_Send(message);
  6780. result = TRUE;
  6781. return result;
  6782. }
  6783. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6784. {
  6785. mtrace();
  6786. int result = FAIL;
  6787. char message[80]={0};
  6788. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6789. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6790. LWS_Send(message);
  6791. result = TRUE;
  6792. return result;
  6793. }
  6794. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6795. {
  6796. mtrace();
  6797. int result = FAIL;
  6798. char message[80]={0};
  6799. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6800. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6801. LWS_Send(message);
  6802. result = TRUE;
  6803. return result;
  6804. }
  6805. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6806. {
  6807. mtrace();
  6808. int result = FAIL;
  6809. char message[80]={0};
  6810. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6811. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6812. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6813. LWS_Send(message);
  6814. result = TRUE;
  6815. return result;
  6816. }
  6817. int sendResetConfirmation(char *uuid,char *payload)
  6818. {
  6819. mtrace();
  6820. int result = FAIL;
  6821. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6822. char message[80]={0};
  6823. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6824. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6825. LWS_Send(message);
  6826. result = TRUE;
  6827. return result;
  6828. }
  6829. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6830. {
  6831. mtrace();
  6832. int result = FAIL;
  6833. char message[500]={0};
  6834. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6835. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6836. LWS_Send(message);
  6837. result = TRUE;
  6838. return result;
  6839. }
  6840. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6841. {
  6842. mtrace();
  6843. int result = FAIL;
  6844. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6845. char message[80]={0};
  6846. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6847. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6848. LWS_Send(message);
  6849. result = TRUE;
  6850. return result;
  6851. }
  6852. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6853. {
  6854. mtrace();
  6855. int result = FAIL;
  6856. char message[80]={0};
  6857. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6858. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6859. LWS_Send(message);
  6860. result = TRUE;
  6861. return result;
  6862. }
  6863. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6864. {
  6865. mtrace();
  6866. int result = FAIL;
  6867. char message[80]={0};
  6868. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6869. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6870. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6871. LWS_Send(message);
  6872. result = TRUE;
  6873. return result;
  6874. }
  6875. int sendUpdateFirmwareConfirmation(char *uuid)
  6876. {
  6877. mtrace();
  6878. int result = FAIL;
  6879. char message[60]={0};
  6880. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6881. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6882. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6883. LWS_Send(message);
  6884. result = TRUE;
  6885. return result;
  6886. }
  6887. int sendCertificateSignedConfirmation(char *uuid)
  6888. {
  6889. mtrace();
  6890. int result = PASS;
  6891. char message[4096]={0};
  6892. json_object *CertificateSigned = json_object_new_object();
  6893. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6894. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6895. sprintf(message,"[%d,\"%s\",%s]"
  6896. ,MESSAGE_TYPE_CALLRESULT
  6897. ,uuid
  6898. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6899. json_object_put(CertificateSigned);
  6900. LWS_Send(message);
  6901. return result;
  6902. }
  6903. int sendDeleteCertificateConfirmation(char *uuid)
  6904. {
  6905. mtrace();
  6906. int result = PASS;
  6907. char message[4096]={0};
  6908. json_object *DeleteCertificate = json_object_new_object();
  6909. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6910. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6911. sprintf(message,"[%d,\"%s\",%s]"
  6912. ,MESSAGE_TYPE_CALLRESULT
  6913. ,uuid
  6914. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6915. json_object_put(DeleteCertificate);
  6916. LWS_Send(message);
  6917. return result;
  6918. }
  6919. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6920. {
  6921. mtrace();
  6922. int result = PASS;
  6923. char message[4096]={0};
  6924. json_object *ExtendedTriggerMessage = json_object_new_object();
  6925. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6926. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6927. sprintf(message,"[%d,\"%s\",%s]"
  6928. ,MESSAGE_TYPE_CALLRESULT
  6929. ,uuid
  6930. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6931. json_object_put(ExtendedTriggerMessage);
  6932. LWS_Send(message);
  6933. return result;
  6934. }
  6935. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6936. {
  6937. mtrace();
  6938. int result = PASS;
  6939. char message[4096]={0};
  6940. json_object *GetInstalledCertificateIds = json_object_new_object();
  6941. json_object *certificateHashDataDatas = json_object_new_array();
  6942. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6943. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6944. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6945. {
  6946. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6947. {
  6948. json_object *certificateHashData = json_object_new_object();
  6949. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6950. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6951. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6952. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6953. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6954. }
  6955. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6956. }
  6957. else
  6958. {
  6959. json_object_put(certificateHashDataDatas);
  6960. }
  6961. sprintf(message,"[%d,\"%s\",%s]"
  6962. ,MESSAGE_TYPE_CALLRESULT
  6963. ,uuid
  6964. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6965. json_object_put(GetInstalledCertificateIds);
  6966. LWS_Send(message);
  6967. return result;
  6968. }
  6969. int sendGetLogConfirmation(char *uuid)
  6970. {
  6971. mtrace();
  6972. int result = PASS;
  6973. char message[4096]={0};
  6974. json_object *GetLog = json_object_new_object();
  6975. DEBUG_INFO("sendGetLogConfirmation...\n");
  6976. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6977. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6978. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6979. sprintf(message,"[%d,\"%s\",%s]"
  6980. ,MESSAGE_TYPE_CALLRESULT
  6981. ,uuid
  6982. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6983. json_object_put(GetLog);
  6984. LWS_Send(message);
  6985. return result;
  6986. }
  6987. int sendInstallCertificateConfirmation(char *uuid)
  6988. {
  6989. mtrace();
  6990. int result = PASS;
  6991. char message[4096]={0};
  6992. json_object *InstallCertificate = json_object_new_object();
  6993. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6994. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6995. sprintf(message,"[%d,\"%s\",%s]"
  6996. ,MESSAGE_TYPE_CALLRESULT
  6997. ,uuid
  6998. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6999. json_object_put(InstallCertificate);
  7000. LWS_Send(message);
  7001. return result;
  7002. }
  7003. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  7004. {
  7005. mtrace();
  7006. int result = PASS;
  7007. char message[4096]={0};
  7008. json_object *SignedUpdateFirmware = json_object_new_object();
  7009. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  7010. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  7011. sprintf(message,"[%d,\"%s\",%s]"
  7012. ,MESSAGE_TYPE_CALLRESULT
  7013. ,uuid
  7014. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  7015. json_object_put(SignedUpdateFirmware);
  7016. LWS_Send(message);
  7017. return result;
  7018. }
  7019. int sendUnknownConfirmation(char *uuid)
  7020. {
  7021. mtrace();
  7022. int result = PASS;
  7023. char message[256]={0};
  7024. DEBUG_INFO("sendUnknownConfirmation...\n");
  7025. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  7026. LWS_Send(message);
  7027. return result;
  7028. }
  7029. //==========================================
  7030. // Handle server request routine Start
  7031. //==========================================
  7032. int handleCancelReservationRequest(char *uuid, char *payload)
  7033. {
  7034. mtrace();
  7035. int result = FAIL;
  7036. int gunNO = 0;
  7037. int reservationIdInt = -1;
  7038. char comfirmstr[20];
  7039. DEBUG_INFO("handleCancelReservationRequest...\n");
  7040. json_object *CancelReservation;
  7041. CancelReservation = json_tokener_parse(payload);
  7042. if(!is_error(CancelReservation))
  7043. {
  7044. // Required data
  7045. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7046. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7047. }
  7048. json_object_put(CancelReservation);
  7049. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7050. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7051. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7052. if(reservationIdInt != -1)
  7053. {
  7054. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7055. //check Transaction active
  7056. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7057. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7058. {
  7059. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7060. {
  7061. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7062. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7063. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7064. {
  7065. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7066. }
  7067. else
  7068. {
  7069. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7070. }
  7071. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7072. goto end;
  7073. }
  7074. }
  7075. for (int index = 0; index < CCS_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7078. {
  7079. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7080. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7081. if(gunType[2] == GUN_TYPE_CCS)
  7082. {
  7083. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7084. }
  7085. else
  7086. {
  7087. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7088. }
  7089. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7090. goto end;
  7091. }
  7092. }
  7093. for (int index = 0; index < GB_QUANTITY; index++)
  7094. {
  7095. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7096. {
  7097. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7098. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7099. if(gunType[2] == GUN_TYPE_GBT)
  7100. {
  7101. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7102. }
  7103. else
  7104. {
  7105. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7106. }
  7107. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7108. goto end;
  7109. }
  7110. }
  7111. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7112. {
  7113. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7114. {
  7115. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7116. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7117. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7118. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7119. goto end;
  7120. }
  7121. }
  7122. for (int index = 0; index < AC_QUANTITY; index++)
  7123. {
  7124. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7125. {
  7126. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7127. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7128. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7129. {
  7130. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7131. }
  7132. else
  7133. {
  7134. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7135. }
  7136. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7137. goto end;
  7138. }
  7139. }
  7140. }
  7141. //The reservationId does NOT match the reservationId
  7142. sendCancelReservationConfirmation(uuid, comfirmstr);
  7143. end:
  7144. // Fill in ocpp packet uuid
  7145. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7146. return result;
  7147. }
  7148. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7149. {
  7150. mtrace();
  7151. int result = FAIL;
  7152. int gunIndex = 0;
  7153. char typeStr[16]={0};
  7154. char comfirmstr[20];
  7155. int specificId = FALSE;
  7156. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7157. json_object *ChangeAvailability;
  7158. ChangeAvailability = json_tokener_parse(payload);
  7159. if(!is_error(ChangeAvailability))
  7160. {
  7161. // Required data
  7162. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7163. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7164. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7165. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7166. }
  7167. json_object_put(ChangeAvailability);
  7168. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7169. {
  7170. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7171. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7172. }
  7173. else if(gunIndex == 0)
  7174. {
  7175. for(int i=0; i < gunTotalNumber; i++)
  7176. {
  7177. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7178. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7179. }
  7180. }
  7181. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7182. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7183. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7184. {
  7185. specificId = TRUE;
  7186. }
  7187. if(specificId == FALSE)
  7188. goto end;
  7189. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7190. {
  7191. //----------------------gunIndex is 0 ------------------------------------------------//
  7192. if(gunIndex == 0)
  7193. {
  7194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7195. {
  7196. for(int i=0; i < gunTotalNumber; i++)
  7197. {
  7198. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7199. {
  7200. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7201. {
  7202. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7203. {
  7204. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7205. goto end;
  7206. }
  7207. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7208. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7209. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7210. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7211. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7212. {
  7213. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7214. goto end;
  7215. }
  7216. }
  7217. }//END FOR CHAdeMO_QUANTITY
  7218. for (int index = 0; index < CCS_QUANTITY; index++)
  7219. {
  7220. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7221. {
  7222. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7223. {
  7224. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7225. goto end;
  7226. }
  7227. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7228. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7229. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7230. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7231. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7232. {
  7233. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7234. goto end;
  7235. }
  7236. }
  7237. }//END FOR CCS_QUANTITY
  7238. for (int index = 0; index < GB_QUANTITY; index++)
  7239. {
  7240. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7241. {
  7242. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7243. {
  7244. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7245. goto end;
  7246. }
  7247. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7248. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7249. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7250. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7251. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7252. {
  7253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7254. goto end;
  7255. }
  7256. }
  7257. }// END FOR GB_QUANTITY
  7258. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7259. {
  7260. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7261. {
  7262. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7263. {
  7264. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7265. goto end;
  7266. }
  7267. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7268. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7269. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7270. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7271. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7272. {
  7273. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7274. goto end;
  7275. }
  7276. }
  7277. }// END FOR GENERAL_GUN_QUANTITY
  7278. for (int index = 0; index < AC_QUANTITY; index++)
  7279. {
  7280. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7281. {
  7282. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7283. {
  7284. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7285. goto end;
  7286. }
  7287. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7288. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7289. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7290. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7291. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7292. {
  7293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7294. goto end;
  7295. }
  7296. }
  7297. }//END FOR AC_QUANTITY
  7298. }// END FOR gunTotalNumber
  7299. }
  7300. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7301. {
  7302. for(int i=0; i < gunTotalNumber; i++)
  7303. {
  7304. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7305. {
  7306. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7307. goto end;
  7308. }
  7309. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7310. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7311. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7312. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7313. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7314. {
  7315. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7316. goto end;
  7317. }
  7318. }
  7319. }
  7320. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7321. goto end;
  7322. }
  7323. //----------------------gunIndex is not 0 ------------------------------------------------//
  7324. //check Transaction active
  7325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7326. {
  7327. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7328. {
  7329. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7330. {
  7331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7332. goto end;
  7333. }
  7334. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7335. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7336. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7337. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7338. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7339. {
  7340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7341. goto end;
  7342. }
  7343. else
  7344. {
  7345. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7347. goto end;
  7348. }
  7349. }
  7350. }//END FOR CHAdeMO_QUANTITY
  7351. for (int index = 0; index < CCS_QUANTITY; index++)
  7352. {
  7353. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7354. {
  7355. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7356. {
  7357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7358. goto end;
  7359. }
  7360. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7361. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7362. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7363. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7364. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7365. {
  7366. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7367. goto end;
  7368. }
  7369. else
  7370. {
  7371. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7373. goto end;
  7374. }
  7375. }
  7376. }//END FOR CCS_QUANTITY
  7377. for (int index = 0; index < GB_QUANTITY; index++)
  7378. {
  7379. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7380. {
  7381. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7382. {
  7383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7384. goto end;
  7385. }
  7386. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7387. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7388. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7389. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7390. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7391. {
  7392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7393. goto end;
  7394. }
  7395. else
  7396. {
  7397. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7399. goto end;
  7400. }
  7401. }
  7402. }// END FOR GB_QUANTITY
  7403. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7404. {
  7405. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7406. {
  7407. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7408. {
  7409. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7410. goto end;
  7411. }
  7412. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7413. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7414. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7415. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7416. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7417. {
  7418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7419. goto end;
  7420. }
  7421. else
  7422. {
  7423. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7424. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7425. goto end;
  7426. }
  7427. }
  7428. }// END FOR GENERAL_GUN_QUANTITY
  7429. for (int index = 0; index < AC_QUANTITY; index++)
  7430. {
  7431. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7432. {
  7433. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7434. {
  7435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7436. goto end;
  7437. }
  7438. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7439. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7440. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7441. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7442. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7443. {
  7444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7445. goto end;
  7446. }
  7447. else
  7448. {
  7449. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7451. goto end;
  7452. }
  7453. }
  7454. }//END FOR AC_QUANTITY
  7455. }//END FOR AvailabilityTypeStr[Inoperative]
  7456. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7457. {
  7458. //----------------------gunIndex is 0 ------------------------------------------------//
  7459. if(gunIndex == 0)
  7460. {
  7461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7462. {
  7463. for(int i=0; i < gunTotalNumber; i++)
  7464. {
  7465. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7466. {
  7467. 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
  7468. {
  7469. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7470. goto end;
  7471. }
  7472. }//END FOR CHAdeMO_QUANTITY
  7473. for (int index = 0; index < CCS_QUANTITY; index++)
  7474. {
  7475. 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
  7476. {
  7477. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7478. goto end;
  7479. }
  7480. }//END FOR CCS_QUANTITY
  7481. for (int index = 0; index < GB_QUANTITY; index++)
  7482. {
  7483. 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
  7484. {
  7485. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7487. goto end;
  7488. }
  7489. }// END FOR GB_QUANTITY
  7490. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7491. {
  7492. 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
  7493. {
  7494. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7496. goto end;
  7497. }
  7498. }// END FOR GENERAL_GUN_QUANTITY
  7499. for (int index = 0; index < AC_QUANTITY; index++)
  7500. {
  7501. 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
  7502. {
  7503. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7504. goto end;
  7505. }
  7506. }//END FOR CHAdeMO_QUANTITY
  7507. }// END FOR gunTotalNumber
  7508. }
  7509. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7510. {
  7511. for(int i=0; i < gunTotalNumber; i++)
  7512. {
  7513. for (int index = 0; index < AC_QUANTITY; index++)
  7514. {
  7515. 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
  7516. {
  7517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7518. goto end;
  7519. }
  7520. }//END FOR CHAdeMO_QUANTITY
  7521. } // END FOR gunTotalNumber
  7522. }
  7523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7524. goto end;
  7525. }
  7526. //----------------------gunIndex is not 0 ------------------------------------------------//
  7527. //check Transaction active
  7528. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7529. {
  7530. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7531. {
  7532. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7533. goto end;
  7534. }
  7535. }//END FOR CHAdeMO_QUANTITY
  7536. for (int index = 0; index < CCS_QUANTITY; index++)
  7537. {
  7538. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7539. {
  7540. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7541. goto end;
  7542. }
  7543. }//END FOR CCS_QUANTITY
  7544. for (int index = 0; index < GB_QUANTITY; index++)
  7545. {
  7546. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7547. {
  7548. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7549. goto end;
  7550. }
  7551. }// END FOR GB_QUANTITY
  7552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7553. {
  7554. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7555. {
  7556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7557. goto end;
  7558. }
  7559. }// END FOR GENERAL_GUN_QUANTITY
  7560. for (int index = 0; index < AC_QUANTITY; index++)
  7561. {
  7562. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7563. {
  7564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7565. goto end;
  7566. }
  7567. }//END FOR AC_QUANTITY
  7568. }//END FOR AvailabilityTypeStr[Operative]
  7569. end:
  7570. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7571. {
  7572. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7573. }
  7574. else
  7575. {
  7576. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7577. }
  7578. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7579. {
  7580. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7581. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7582. }
  7583. else if(gunIndex == 0)
  7584. {
  7585. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7586. {
  7587. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7588. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7589. }
  7590. }
  7591. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7592. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7593. return result;
  7594. }
  7595. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7596. {
  7597. mtrace();
  7598. int result = FAIL;
  7599. char keystr[40]={0};
  7600. char valuestr[256]={0};
  7601. char comfirmstr[20]={0};
  7602. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7603. json_object *ChangeConfiguration;
  7604. ChangeConfiguration = json_tokener_parse(payload);
  7605. if(!is_error(ChangeConfiguration))
  7606. {
  7607. // Required data
  7608. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7609. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7610. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7611. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7612. }
  7613. json_object_put(ChangeConfiguration);
  7614. if((uuid==NULL) || (payload ==NULL) )
  7615. {
  7616. DEBUG_ERROR("Payload is null\n");
  7617. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7618. }
  7619. else
  7620. {
  7621. int status = setKeyValue(keystr, valuestr);
  7622. switch(status)
  7623. {
  7624. case ConfigurationStatus_Accepted:
  7625. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7626. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7627. StoreConfigurationTable();
  7628. break;
  7629. case RebootRequired:
  7630. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7631. StoreConfigurationTable();
  7632. break;
  7633. case NotSupported:
  7634. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7635. break;
  7636. case ConfigurationStatus_Rejected:
  7637. default:
  7638. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7639. break;
  7640. }
  7641. }
  7642. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7643. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7644. if((strcmp(keystr,"WebSocketPingInterval")==0) && (strcmp(comfirmstr,"Accepted")==0))
  7645. {
  7646. ChageWebSocketPingInterval(atoi(valuestr));
  7647. }
  7648. if(((strcmp(keystr,"AuthorizationKey")==0) || (strcmp(keystr,"SecurityProfile")==0)) && (strcmp(comfirmstr,"Accepted")==0))
  7649. {
  7650. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7651. SetOcppConnStatus(FALSE);
  7652. }
  7653. return result;
  7654. }
  7655. int handleClearCacheRequest(char *uuid, char *payload)
  7656. {
  7657. mtrace();
  7658. int result = FAIL;
  7659. char comfirmstr[20];
  7660. char rmFileCmd[100]={0};
  7661. struct stat stats;
  7662. DEBUG_INFO("handleClearCacheRequest...\n");
  7663. stat("/Storage/OCPP_PH", &stats);
  7664. // Check for directory existence
  7665. if (S_ISDIR(stats.st_mode) == 1)
  7666. {}
  7667. else
  7668. {
  7669. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7670. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  7671. system(rmFileCmd);
  7672. }
  7673. if(OCPP_cleanLocalCache())
  7674. {
  7675. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7676. }
  7677. else
  7678. {
  7679. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7680. }
  7681. sendClearCacheConfirmation(uuid, comfirmstr);
  7682. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7683. return result;
  7684. }
  7685. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7686. {
  7687. mtrace();
  7688. int result = FAIL;
  7689. int resultRename;
  7690. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7691. char chargingProfilePurposeStr[26]={0};
  7692. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7693. char tempchargingProfilePurposeStr[26]={0};
  7694. char str[100]={0};
  7695. char fname[200]={0};
  7696. char comfirmstr[20]={0};
  7697. char word[1600]={0};
  7698. int clearflag = FALSE;
  7699. int chargingProfileIdIsNULL = FALSE;
  7700. int connectorIsNULL = FALSE;
  7701. int chargingProfilePurposeIsNULL = FALSE;
  7702. int stackLevelIsNULL = FALSE;
  7703. //int GotoEnd = FALSE;
  7704. FILE *fptr1, *fptr2;
  7705. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  7706. int n_chargingProfile=0;
  7707. int isEmptyFile = FALSE;
  7708. char sLineWord[1600]={0};
  7709. char chargingProfiles[10][100]={0};
  7710. int ChargeProfileCount = 0;
  7711. int ch;
  7712. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7713. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7714. json_object *ClearChargingProfile;
  7715. ClearChargingProfile = json_tokener_parse(payload);
  7716. if(!is_error(ClearChargingProfile))
  7717. {
  7718. // Optional data
  7719. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7720. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7721. else
  7722. chargingProfileIdIsNULL = TRUE;
  7723. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7724. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7725. else
  7726. connectorIsNULL = TRUE;
  7727. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7728. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7729. else
  7730. chargingProfilePurposeIsNULL = TRUE;
  7731. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7732. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7733. else
  7734. stackLevelIsNULL = TRUE;
  7735. }
  7736. json_object_put(ClearChargingProfile);
  7737. if(connectorIsNULL == FALSE)
  7738. {
  7739. switch(connectorIdInt)
  7740. {
  7741. case 0:
  7742. if(chargingProfilePurposeIsNULL == TRUE)
  7743. {
  7744. int l = 0;
  7745. strcpy(fname, ChargePointMaxProfile_JSON);
  7746. if((access(fname,F_OK))!=-1)
  7747. {
  7748. strcpy(chargingProfiles[l], fname);
  7749. l = l + 1;
  7750. }
  7751. strcpy(fname, TxDefaultProfile_0_JSON);
  7752. if((access(fname,F_OK))!=-1)
  7753. {
  7754. strcpy(chargingProfiles[l], fname);
  7755. l = l + 1;
  7756. }
  7757. ChargeProfileCount = l;
  7758. }
  7759. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7760. {
  7761. strcpy(fname, ChargePointMaxProfile_JSON);
  7762. if((access(fname,F_OK))!=-1)
  7763. {
  7764. strcpy(chargingProfiles[0], fname);
  7765. ChargeProfileCount = 1;
  7766. }
  7767. }
  7768. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7769. {
  7770. strcpy(fname, TxDefaultProfile_0_JSON);
  7771. if((access(fname,F_OK))!=-1)
  7772. {
  7773. strcpy(chargingProfiles[0], fname);
  7774. ChargeProfileCount = 1;
  7775. }
  7776. }
  7777. break;
  7778. default:
  7779. if(chargingProfilePurposeIsNULL == TRUE)
  7780. {
  7781. int m = 0;
  7782. memset(fname, 0, ARRAY_SIZE(fname));
  7783. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7784. if((access(fname,F_OK))!=-1)
  7785. {
  7786. strcpy(chargingProfiles[m], fname);
  7787. m = m + 1;
  7788. }
  7789. memset(fname, 0, ARRAY_SIZE(fname));
  7790. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7791. if((access(fname,F_OK))!=-1)
  7792. {
  7793. strcpy(chargingProfiles[m], fname);
  7794. m = m + 1;
  7795. }
  7796. ChargeProfileCount = m;
  7797. }
  7798. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7799. {
  7800. //strcpy(fname, TxDefaultProfile_1_JSON);
  7801. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7802. if((access(fname,F_OK))!=-1)
  7803. {
  7804. strcpy(chargingProfiles[0], fname);
  7805. ChargeProfileCount = 1;
  7806. }
  7807. }
  7808. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7809. {
  7810. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7811. if((access(fname,F_OK))!=-1)
  7812. {
  7813. strcpy(chargingProfiles[0], fname);
  7814. ChargeProfileCount = 1;
  7815. }
  7816. //strcpy(fname, TxProfile_1_JSON);
  7817. }
  7818. //strcpy(fname, ChargePointMaxProfile_JSON );
  7819. break;
  7820. }
  7821. }
  7822. else // Check all Charging Profiles
  7823. {
  7824. int i = 0;
  7825. char fnametemp[200]={0};
  7826. ChargeProfileCount = 0;
  7827. //Check ChargePointMaxProfile.json exit
  7828. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7829. {
  7830. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7831. i = i + 1;
  7832. }
  7833. //Check TxDefaultProfile_0.json exit
  7834. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7835. {
  7836. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7837. i = i + 1;
  7838. }
  7839. //Check TxDefaultProfile_%d.json
  7840. for(int j=1; j <= gunTotalNumber; j++)
  7841. {
  7842. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7843. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7844. if((access(fnametemp,F_OK))!=-1)
  7845. {
  7846. strcpy(chargingProfiles[i], fnametemp);
  7847. i = i + 1;
  7848. }
  7849. }
  7850. //Check TxProfile_%d.json
  7851. for(int j=1; j <= gunTotalNumber; j++)
  7852. {
  7853. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7854. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7855. if((access(fnametemp,F_OK))!=-1)
  7856. {
  7857. strcpy(chargingProfiles[i], fnametemp);
  7858. i = i + 1;
  7859. }
  7860. }
  7861. ChargeProfileCount = i;
  7862. }// End connectorIsNULL is TRUE
  7863. if(ChargeProfileCount == 0)
  7864. {
  7865. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7866. goto end;
  7867. }
  7868. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7869. {
  7870. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7871. goto end;
  7872. }
  7873. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7874. {
  7875. memset(str, 0, ARRAY_SIZE(str));
  7876. // clear temp file
  7877. sprintf(str,"rm -f %s",temp);
  7878. system(str);
  7879. for(int k=0; k < ChargeProfileCount; k++)
  7880. {
  7881. memset(str, 0, ARRAY_SIZE(str));
  7882. //clear file in C
  7883. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7884. system(str);
  7885. }
  7886. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7887. goto end;
  7888. }
  7889. else if(connectorIsNULL == TRUE)
  7890. {
  7891. for(int k=0; k < ChargeProfileCount; k++)
  7892. {
  7893. fptr1 = fopen(chargingProfiles[k], "r");
  7894. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7895. //Check Charging Profile Count
  7896. while(fscanf(fptr1, "%s", word) != EOF)
  7897. {
  7898. //DEBUG_INFO("word=%s\n",word);
  7899. if(strstr(word, "chargingProfileId")!= NULL)
  7900. {
  7901. //DEBUG_INFO("test chargingProfileId \n");
  7902. n_chargingProfile = n_chargingProfile + 1;
  7903. //DEBUG_INFO("chargingProfileId Found\n");
  7904. }
  7905. }
  7906. rewind(fptr1);
  7907. //search Charging Profile Element
  7908. //int i= 0;
  7909. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7910. {
  7911. json_object *tmpProfilee;
  7912. tmpProfilee = json_tokener_parse(sLineWord);
  7913. if(!is_error(tmpProfilee))
  7914. {
  7915. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7916. {
  7917. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7918. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7919. }
  7920. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7921. {
  7922. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7923. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7924. }
  7925. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7926. {
  7927. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7928. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7929. }
  7930. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7931. {
  7932. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7933. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7934. }
  7935. }
  7936. json_object_put(tmpProfilee);
  7937. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7938. {
  7939. //------- not write to fptr2-------//
  7940. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7941. //clearflag = TRUE;
  7942. }
  7943. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7944. {
  7945. //------- not write to fptr2-------//
  7946. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7947. }
  7948. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7949. {
  7950. //------- not write to fptr2-------//
  7951. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7952. }
  7953. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7954. {
  7955. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7956. }
  7957. else
  7958. {
  7959. fprintf(fptr2, sLineWord);//writing data into file
  7960. }
  7961. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7962. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7963. if(clearflag == TRUE)
  7964. {
  7965. fclose(fptr1);
  7966. fclose(fptr2);
  7967. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7968. system(str);
  7969. // clear temp file
  7970. sprintf(str,"rm -f %s",temp);
  7971. system(str);
  7972. }
  7973. else
  7974. {
  7975. fclose(fptr1);
  7976. fclose(fptr2);
  7977. memset(str, 0, ARRAY_SIZE(str));
  7978. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7979. system(str);
  7980. resultRename = rename(temp, chargingProfiles[k]);
  7981. if(resultRename == 0)
  7982. {
  7983. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7984. }
  7985. else
  7986. {
  7987. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7988. }
  7989. if(comfirmstr[0]== 0)
  7990. {
  7991. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7992. }
  7993. //Check chargingProfile is empty file
  7994. /*------ Read the file ----------------*/
  7995. fptr1=fopen(chargingProfiles[k],"r");
  7996. ch=fgetc(fptr1);
  7997. rewind(fptr1);
  7998. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7999. if(ch!=EOF)
  8000. {
  8001. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8002. {
  8003. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8004. if(sLineWord[0]=='\0')
  8005. {
  8006. isEmptyFile = TRUE;
  8007. break;
  8008. }
  8009. else
  8010. {
  8011. isEmptyFile = FALSE;
  8012. break;
  8013. }
  8014. }
  8015. }
  8016. else
  8017. isEmptyFile = TRUE;
  8018. fclose(fptr1);
  8019. if(isEmptyFile == TRUE)
  8020. {
  8021. memset(str, 0, ARRAY_SIZE(str));
  8022. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8023. system(str);
  8024. }
  8025. }
  8026. }// End of while(int k=0; k < ChargePointCount; k++)
  8027. }
  8028. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  8029. {
  8030. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8031. for(int k=0; k < ChargeProfileCount; k++)
  8032. {
  8033. fptr1 = fopen(chargingProfiles[k], "r");
  8034. fptr2 = fopen(temp, "w+");
  8035. //Check Charging Profile Count
  8036. while(fscanf(fptr1, "%s", word) != EOF)
  8037. {
  8038. //DEBUG_INFO("word=%s\n",word);
  8039. if(strstr(word, "chargingProfileId")!= NULL)
  8040. {
  8041. n_chargingProfile = n_chargingProfile + 1;
  8042. }
  8043. }
  8044. rewind(fptr1);
  8045. //search Charging Profile Element
  8046. //int i= 0;
  8047. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8048. {
  8049. json_object *tmpProfilee;
  8050. tmpProfilee = json_tokener_parse(sLineWord);
  8051. if(!is_error(tmpProfilee))
  8052. {
  8053. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8054. {
  8055. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8056. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8057. }
  8058. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8059. {
  8060. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8061. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8062. }
  8063. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8064. {
  8065. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8066. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8067. }
  8068. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8069. {
  8070. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8071. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8072. }
  8073. }
  8074. json_object_put(tmpProfilee);
  8075. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8076. {
  8077. //------- not write to fptr2-------//
  8078. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8079. //clearflag = TRUE;
  8080. }
  8081. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8082. {
  8083. //------- not write to fptr2-------//
  8084. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8085. }
  8086. else if(stackLevelIsNULL == TRUE)
  8087. {
  8088. //Clear Whole File
  8089. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8090. clearflag = TRUE;
  8091. break;
  8092. }
  8093. else
  8094. {
  8095. fprintf(fptr2, sLineWord);//writing data into file
  8096. }
  8097. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8098. }
  8099. if(clearflag == TRUE)
  8100. {
  8101. fclose(fptr1);
  8102. fclose(fptr2);
  8103. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8104. system(str);
  8105. // clear temp file
  8106. sprintf(str,"rm -f %s",temp);
  8107. system(str);
  8108. }
  8109. else
  8110. {
  8111. fclose(fptr1);
  8112. fclose(fptr2);
  8113. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8114. system(str);
  8115. resultRename = rename(temp, chargingProfiles[k]);
  8116. if(resultRename == 0)
  8117. {
  8118. DEBUG_INFO("File ChargingProfile renamed successfully");
  8119. }
  8120. else
  8121. {
  8122. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8123. }
  8124. if(comfirmstr[0]== 0)
  8125. {
  8126. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8127. }
  8128. //Check chargingProfile is empty file
  8129. /*------ Read the file ----------------*/
  8130. fptr1=fopen(chargingProfiles[k],"r");
  8131. ch=fgetc(fptr1);
  8132. rewind(fptr1);
  8133. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8134. if(ch!=EOF)
  8135. {
  8136. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8137. {
  8138. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8139. if(sLineWord[0]=='\0')
  8140. {
  8141. isEmptyFile = TRUE;
  8142. break;
  8143. }
  8144. else
  8145. {
  8146. isEmptyFile = FALSE;
  8147. break;
  8148. }
  8149. }
  8150. }
  8151. else
  8152. isEmptyFile = TRUE;
  8153. fclose(fptr1);
  8154. if(isEmptyFile == TRUE)
  8155. {
  8156. memset(str, 0, ARRAY_SIZE(str));
  8157. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8158. system(str);
  8159. }
  8160. /*------- End of reading ---------------*/
  8161. }
  8162. } // while(int k=0; k < ChargeProfileCount; k++)
  8163. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8164. end:
  8165. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8166. {
  8167. if(connectorIdInt == 0)
  8168. {
  8169. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8170. {
  8171. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8172. }
  8173. }
  8174. else
  8175. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8176. }
  8177. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8178. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8179. return result;
  8180. }
  8181. void createFirmwareVersionByDataTransfer(void)
  8182. {
  8183. json_object *FirmwareDataTransfer = json_object_new_object();
  8184. // AC & DC model
  8185. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8186. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8187. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8188. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8189. // DC model
  8190. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8191. {
  8192. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8193. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8194. (gunType[3] != GUN_TYPE_UNKNOWN))
  8195. {
  8196. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8197. }
  8198. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8199. {
  8200. // DS DM DW
  8201. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8202. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8203. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8204. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8205. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8206. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8207. }
  8208. else
  8209. {
  8210. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8211. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8212. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8213. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8214. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8215. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8216. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8217. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8218. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8219. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8220. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8221. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8222. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8223. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8224. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8225. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8226. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8227. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8228. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8229. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8230. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8231. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8232. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8233. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8234. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8235. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8236. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8237. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8238. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8239. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8240. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8241. }
  8242. }
  8243. // 4G model
  8244. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8245. {
  8246. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8247. }
  8248. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8249. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8250. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8251. json_object_put(FirmwareDataTransfer);
  8252. }
  8253. int handleDataTransferRequest(char *uuid, char *payload)
  8254. {
  8255. mtrace();
  8256. json_object *response = json_object_new_object();
  8257. int result = FAIL;
  8258. char tempvendorId[255]={0};
  8259. char tempmessageId[50]={0};
  8260. char tempdata[512]={0};
  8261. char message[2048]={0};
  8262. DEBUG_INFO("handleDataTransferRequest...\n");
  8263. if((uuid != NULL) && (payload != NULL))
  8264. {
  8265. json_object *DataTransfer;
  8266. DataTransfer = json_tokener_parse(payload);
  8267. if(!is_error(DataTransfer))
  8268. {
  8269. // Required data
  8270. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8271. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8272. // Optional data
  8273. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8274. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8275. if(json_object_object_get(DataTransfer, "data") != NULL)
  8276. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8277. result = PASS;
  8278. }
  8279. json_object_put(DataTransfer);
  8280. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8281. {
  8282. // Send all moudle firmware version on EVSE
  8283. createFirmwareVersionByDataTransfer();
  8284. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8285. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  8286. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8287. json_object_put(response);
  8288. }
  8289. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8290. {
  8291. system("/usr/bin/run_tmate_restart.sh &");
  8292. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8293. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8294. json_object_put(response);
  8295. }
  8296. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8297. {
  8298. json_object *data;
  8299. data = json_tokener_parse(tempdata);
  8300. if(!is_error(data))
  8301. {
  8302. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8303. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8304. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8305. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8306. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8307. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8308. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8309. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8310. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8311. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8312. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8313. }
  8314. else
  8315. {
  8316. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8317. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8318. }
  8319. json_object_put(data);
  8320. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8321. json_object_put(response);
  8322. }
  8323. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8324. {
  8325. json_object *data;
  8326. data = json_tokener_parse(tempdata);
  8327. if(!is_error(data))
  8328. {
  8329. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8330. if(json_object_object_get(data, "idToken") != NULL)
  8331. {
  8332. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8333. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8334. }
  8335. if(json_object_object_get(data, "price") != NULL)
  8336. {
  8337. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8338. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8339. }
  8340. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8341. }
  8342. else
  8343. {
  8344. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8345. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8346. }
  8347. json_object_put(data);
  8348. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8349. json_object_put(response);
  8350. }
  8351. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8352. {
  8353. json_object *data;
  8354. data = json_tokener_parse(tempdata);
  8355. if(!is_error(data))
  8356. {
  8357. if(json_object_object_get(data, "txId") != NULL)
  8358. {
  8359. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8360. for(int idx = 0;idx<gunTotalNumber;idx++)
  8361. {
  8362. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8363. {
  8364. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8365. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8366. if(json_object_object_get(data, "description") != NULL)
  8367. {
  8368. // California pricing V1.0
  8369. DEBUG_INFO("California pricing V1.0\n");
  8370. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8371. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8372. }
  8373. else
  8374. {
  8375. // California pricing V1.1
  8376. DEBUG_INFO("California pricing V1.1\n");
  8377. if(json_object_object_get(data, "timestamp") != NULL)
  8378. {
  8379. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8380. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8381. }
  8382. if(json_object_object_get(data, "meterValue") != NULL)
  8383. {
  8384. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8385. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8386. }
  8387. if(json_object_object_get(data, "cost") != NULL)
  8388. {
  8389. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8390. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8391. }
  8392. if(json_object_object_get(data, "state") != NULL)
  8393. {
  8394. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8395. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8396. }
  8397. if(json_object_object_get(data, "chargingPrice") != NULL)
  8398. {
  8399. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8400. {
  8401. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8402. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8403. }
  8404. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8405. {
  8406. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8407. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8408. }
  8409. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8410. {
  8411. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8412. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8413. }
  8414. }
  8415. if(json_object_object_get(data, "idlePrice") != NULL)
  8416. {
  8417. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8418. {
  8419. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8420. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8421. }
  8422. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8423. {
  8424. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8425. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8426. }
  8427. }
  8428. if(json_object_object_get(data, "nextPeriod") != NULL)
  8429. {
  8430. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8431. {
  8432. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8433. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8434. }
  8435. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8436. {
  8437. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8438. {
  8439. 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")));
  8440. 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"));
  8441. }
  8442. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8443. {
  8444. 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")));
  8445. 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"));
  8446. }
  8447. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8448. {
  8449. 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")));
  8450. 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"));
  8451. }
  8452. }
  8453. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8454. {
  8455. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8456. {
  8457. 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")));
  8458. 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"));
  8459. }
  8460. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8461. {
  8462. 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")));
  8463. 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"));
  8464. }
  8465. }
  8466. }
  8467. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8468. {
  8469. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8470. {
  8471. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8472. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8473. }
  8474. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8475. {
  8476. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8477. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8478. }
  8479. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8480. {
  8481. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8482. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8483. }
  8484. }
  8485. }
  8486. }
  8487. }
  8488. }
  8489. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8490. }
  8491. else
  8492. {
  8493. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8494. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8495. }
  8496. json_object_put(data);
  8497. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8498. json_object_put(response);
  8499. }
  8500. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8501. {
  8502. json_object *data;
  8503. data = json_tokener_parse(tempdata);
  8504. if(!is_error(data))
  8505. {
  8506. if(json_object_object_get(data, "txId") != NULL)
  8507. {
  8508. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8509. for(int idx = 0;idx<gunTotalNumber;idx++)
  8510. {
  8511. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8512. {
  8513. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8514. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8515. if(json_object_object_get(data, "description") != NULL)
  8516. {
  8517. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8518. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8519. }
  8520. }
  8521. }
  8522. }
  8523. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8524. }
  8525. else
  8526. {
  8527. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8528. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8529. }
  8530. json_object_put(data);
  8531. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8532. json_object_put(response);
  8533. }
  8534. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8535. {
  8536. json_object *data;
  8537. data = json_tokener_parse(tempdata);
  8538. if(!is_error(data))
  8539. {
  8540. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8541. if(json_object_object_get(data, "Content_Type") != NULL)
  8542. {
  8543. 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))
  8544. {
  8545. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8546. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8547. {
  8548. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8549. }
  8550. }
  8551. else
  8552. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8553. }
  8554. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8555. }
  8556. else
  8557. {
  8558. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8559. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8560. }
  8561. json_object_put(data);
  8562. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8563. json_object_put(response);
  8564. }
  8565. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  8566. {
  8567. json_object *data;
  8568. data = json_tokener_parse(tempdata);
  8569. if(!is_error(data))
  8570. {
  8571. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8572. if(json_object_object_get(data, "Page_Index") != NULL)
  8573. {
  8574. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8575. }
  8576. if(json_object_object_get(data, "Duration") != NULL)
  8577. {
  8578. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8579. }
  8580. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8581. }
  8582. else
  8583. {
  8584. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8585. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8586. }
  8587. json_object_put(data);
  8588. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8589. json_object_put(response);
  8590. }
  8591. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8592. {
  8593. json_object *data;
  8594. data = json_tokener_parse(tempdata);
  8595. if(!is_error(data))
  8596. {
  8597. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8598. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8599. {
  8600. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8601. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8602. else
  8603. {
  8604. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8605. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8606. }
  8607. }
  8608. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8609. {
  8610. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8611. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8612. else
  8613. {
  8614. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8615. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8616. }
  8617. }
  8618. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8619. {
  8620. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8621. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8622. else
  8623. {
  8624. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8625. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8626. }
  8627. }
  8628. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8629. {
  8630. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8631. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8632. else
  8633. {
  8634. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8635. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8636. }
  8637. }
  8638. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8639. {
  8640. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8641. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8642. else
  8643. {
  8644. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8645. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8646. }
  8647. }
  8648. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8649. {
  8650. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8651. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8652. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8653. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8654. else
  8655. {
  8656. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8657. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8658. }
  8659. }
  8660. if(json_object_object_get(data, "isAuthentication") != NULL)
  8661. {
  8662. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8663. {
  8664. case 0:
  8665. case 1:
  8666. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8667. break;
  8668. default:
  8669. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8670. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8671. break;
  8672. }
  8673. }
  8674. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8675. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8676. }
  8677. else
  8678. {
  8679. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8680. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8681. }
  8682. json_object_put(data);
  8683. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8684. json_object_put(response);
  8685. }
  8686. else
  8687. {
  8688. // Can not find valid message id
  8689. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8690. }
  8691. }
  8692. else
  8693. {
  8694. // Payload is null
  8695. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8696. }
  8697. LWS_Send(message);
  8698. return result;
  8699. }
  8700. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8701. {
  8702. mtrace();
  8703. int result = FAIL;
  8704. int connectorIdInt, durationInt;
  8705. char chargingRateUnitStr[4]={0};
  8706. char comfirmstr[20];
  8707. int confirmPeriods = 0;
  8708. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8709. json_object *GetCompositeSchedule;
  8710. GetCompositeSchedule = json_tokener_parse(payload);
  8711. if(!is_error(GetCompositeSchedule))
  8712. {
  8713. // Required data
  8714. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8715. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8716. else
  8717. connectorIdInt = -1;
  8718. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8719. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8720. else
  8721. durationInt = 86400;
  8722. // Optional data
  8723. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8724. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8725. }
  8726. json_object_put(GetCompositeSchedule);
  8727. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8728. if((connectorIdInt == 0) ||
  8729. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8730. {
  8731. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8732. struct StructChargingProfile tmpProfile[1];
  8733. if(strstr(chargingRateUnitStr, "W") != NULL)
  8734. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8735. else
  8736. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8737. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8738. {
  8739. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8740. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8741. }
  8742. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8743. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8744. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8745. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8746. {
  8747. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8748. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8749. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8750. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8751. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8752. {
  8753. confirmPeriods = idx;
  8754. break;
  8755. }
  8756. }
  8757. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8758. {
  8759. confirmPeriods += 1;
  8760. }
  8761. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8762. }
  8763. else
  8764. {
  8765. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8766. }
  8767. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8768. return result;
  8769. }
  8770. int handleGetConfigurationRequest(char *uuid, char *payload)
  8771. {
  8772. mtrace();
  8773. int result = FAIL;
  8774. int MaxKeySupported = 0;
  8775. int n_keys = 0;
  8776. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8777. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8778. json_object *GetConfiguration;
  8779. GetConfiguration = json_tokener_parse(payload);
  8780. if(!is_error(GetConfiguration))
  8781. {
  8782. // Optional data
  8783. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8784. {
  8785. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8786. {
  8787. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8788. n_keys = idx + 1;
  8789. }
  8790. }
  8791. }
  8792. json_object_put(GetConfiguration);
  8793. UnknownKeynum = 0;
  8794. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8795. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8796. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8797. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8798. if(n_keys != 0)
  8799. {
  8800. for(int i=0;i<n_keys;i++)
  8801. {
  8802. getKeyValue(requestKey[i]);
  8803. }
  8804. }
  8805. else
  8806. {
  8807. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8808. getKeyValue("");
  8809. }
  8810. processUnkownKey();
  8811. sendGetConfigurationConfirmation(uuid);
  8812. return result;
  8813. }
  8814. static char fnamePlusPath[100]={0};
  8815. static char fnamePWithNoPath[60]={0};
  8816. void checkUploadLog(void)
  8817. {
  8818. FILE *fp;
  8819. /* Open the command for reading. */
  8820. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8821. if (fp == NULL) {
  8822. DEBUG_WARN("Failed to run command\n" );
  8823. exit(1);
  8824. }
  8825. int ftppathlen = 0;
  8826. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8827. int i = 0;
  8828. /* Read the output a line at a time - output it. */
  8829. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8830. if(i==0)
  8831. {
  8832. ftppathlen = strlen(fnamePlusPath);
  8833. DEBUG_INFO("%s\n", fnamePlusPath);
  8834. fnamePlusPath[ftppathlen]='\0';
  8835. break;
  8836. }
  8837. i= i+1;
  8838. }
  8839. /* close */
  8840. pclose(fp);
  8841. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8842. {
  8843. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8844. {
  8845. fnamePlusPath[k]='\0';
  8846. }
  8847. }
  8848. i=1;
  8849. //char fname[60]={0};
  8850. while(i < ftppathlen)
  8851. {
  8852. int len=ftppathlen-i;
  8853. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8854. {
  8855. DEBUG_INFO("compare '/' all right\n");
  8856. break;
  8857. }
  8858. i=i+1;
  8859. }
  8860. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8861. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8862. fnamePWithNoPath[i+1] = '\0';
  8863. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8864. {
  8865. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8866. {
  8867. fnamePWithNoPath[j]='\0';
  8868. }
  8869. }
  8870. FILE* fp1 = fopen(fnamePlusPath, "r");
  8871. if (fp1)
  8872. {
  8873. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8874. // file exists
  8875. fclose(fp1);
  8876. }
  8877. else
  8878. {
  8879. // file doesn't exist
  8880. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8881. }
  8882. }
  8883. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8884. {
  8885. mtrace();
  8886. int result = FAIL;
  8887. time_t CurrentTime;
  8888. struct tm *tm;
  8889. pthread_t th_Status;
  8890. CurrentTime = time(NULL);
  8891. tm = localtime(&CurrentTime);
  8892. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  8893. 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);
  8894. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8895. if(!interLock.isGetDiagnosticGoing)
  8896. {
  8897. interLock.isGetDiagnosticGoing = 1;
  8898. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8899. sleep(1);
  8900. }
  8901. else
  8902. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  8903. return result;
  8904. }
  8905. void* GetDiagnosticsProcess(void* data)
  8906. {
  8907. pthread_detach(pthread_self());
  8908. mtrace();
  8909. int retriesInt=0, retryIntervalInt=0;
  8910. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8911. 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};
  8912. int port=0;
  8913. int isSuccess = FALSE;
  8914. char ftpbuf[200]={0};
  8915. char cmdBuf[2048];
  8916. struct tm *tmNow;
  8917. time_t CurrentTime;
  8918. struct tm tmStart;
  8919. struct tm tmStop;
  8920. CurrentTime = time(NULL);
  8921. tmNow=localtime(&CurrentTime);
  8922. uint16_t targetYear, targetMonth;
  8923. json_object *GetDiagnostics;
  8924. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8925. GetDiagnostics = json_tokener_parse(data);
  8926. if(!is_error(GetDiagnostics))
  8927. {
  8928. // Required data
  8929. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8930. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8931. // Optional data
  8932. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8933. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8934. else
  8935. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8936. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8937. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8938. else
  8939. retryIntervalInt = 30;
  8940. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8941. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8942. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8943. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8944. }
  8945. json_object_put(GetDiagnostics);
  8946. // Pack log to compress file
  8947. 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) &&
  8948. (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))
  8949. {
  8950. // Pack system log
  8951. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8952. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8953. targetYear = tmStart.tm_year;
  8954. targetMonth = tmStart.tm_mon;
  8955. do
  8956. {
  8957. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8958. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8959. if(targetMonth+1>=13)
  8960. {
  8961. targetYear += 1;
  8962. targetMonth = 1;
  8963. }
  8964. else
  8965. {
  8966. targetMonth += 1;
  8967. }
  8968. }while((targetYear < (tmNow->tm_year+1900)) ||
  8969. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8970. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8971. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8972. system(cmdBuf);
  8973. // Pack charging & event log
  8974. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8975. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8976. targetYear = tmStart.tm_year;
  8977. targetMonth = tmStart.tm_mon;
  8978. do
  8979. {
  8980. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8981. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8982. if(targetMonth+1>=13)
  8983. {
  8984. targetYear += 1;
  8985. targetMonth = 1;
  8986. }
  8987. else
  8988. {
  8989. targetMonth += 1;
  8990. }
  8991. }while((targetYear < (tmNow->tm_year+1900)) ||
  8992. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8993. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8994. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8995. system(cmdBuf);
  8996. // Combine log file
  8997. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8998. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8999. }
  9000. else
  9001. {
  9002. system("exec /root/logPackTools 'log' 6");
  9003. }
  9004. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  9005. system(cmdBuf);
  9006. checkUploadLog();
  9007. //****************location*******************/
  9008. if(strcmp(locationstr,"")==0)
  9009. {
  9010. DEBUG_INFO("location is <Empty>!\n");
  9011. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9012. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9013. goto end;
  9014. }
  9015. memset(protocol, 0, ARRAY_SIZE(protocol));
  9016. memset(user, 0, ARRAY_SIZE(user) );
  9017. memset(password, 0, ARRAY_SIZE(password));
  9018. memset(host, 0, ARRAY_SIZE(host));
  9019. memset(path, 0, ARRAY_SIZE(path));
  9020. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9021. memset(host1, 0, ARRAY_SIZE(host1));
  9022. memset(path1, 0, ARRAY_SIZE(path1));
  9023. /*location: ftp://user:password@host:port/path*/
  9024. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  9025. if((access(fnamePlusPath,F_OK))!=-1)
  9026. {
  9027. DEBUG_INFO("fnamePlusPath exist.\n");
  9028. }
  9029. else
  9030. {
  9031. DEBUG_INFO("fnamePlusPath not exist!\n");
  9032. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9033. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9034. goto end;
  9035. }
  9036. if(strchr(locationstr,'@')==NULL)
  9037. {
  9038. sscanf(locationstr,
  9039. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9040. protocol, host, &port, path);
  9041. strcpy(user,"anonymous");
  9042. strcpy(password,"");
  9043. }
  9044. else
  9045. {
  9046. //DEBUG_INFO("pch=%s\n", pch);
  9047. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9048. protocol, user, password, host, &port, path);
  9049. }
  9050. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9051. {
  9052. DEBUG_INFO("protocol is not ftp/http ! \n");
  9053. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9054. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9055. goto end;
  9056. }
  9057. if(strncmp(locationstr,"http", 4) == 0)
  9058. {
  9059. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9060. sprintf(ftppath,"/%s", path);
  9061. do
  9062. {
  9063. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9064. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9065. sleep(3);
  9066. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9067. if(!isSuccess)
  9068. {
  9069. DEBUG_INFO("Diagnostics fail.\n");
  9070. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9071. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9072. sleep(retryIntervalInt);
  9073. }
  9074. else
  9075. {
  9076. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9077. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9078. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9079. }
  9080. retriesInt--;
  9081. }while((isSuccess == 0)&&(retriesInt >= 0));
  9082. }
  9083. else
  9084. {
  9085. sscanf(host,"%[^/]%s",host1, path1);
  9086. if(strlen(path) > 0)
  9087. sprintf(ftppath,"/%s", path);
  9088. else
  9089. sprintf(ftppath,"/%s", path1);
  9090. int ftppathlen=strlen(ftppath);
  9091. int i=1;
  9092. char filenametemp[50];
  9093. while(i < ftppathlen)
  9094. {
  9095. int len=ftppathlen-i;
  9096. if(ftppath[len]== 47) // '/' ascll code: 47
  9097. {
  9098. DEBUG_INFO("find '/' all right\n");
  9099. break;
  9100. }
  9101. i=i+1;
  9102. }
  9103. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9104. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9105. filenametemp[i+1] = 0;
  9106. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9107. if(port == 0)
  9108. port = 21;
  9109. do
  9110. {
  9111. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9112. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9113. sleep(3);
  9114. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9115. if(!isSuccess)
  9116. {
  9117. DEBUG_INFO("Diagnostics fail.\n");
  9118. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9119. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9120. sleep(retryIntervalInt);
  9121. }
  9122. else
  9123. {
  9124. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9125. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9126. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9127. }
  9128. retriesInt--;
  9129. }while((!isSuccess)&&(retriesInt >= 0));
  9130. }
  9131. end:
  9132. system("rm -f /mnt/*");
  9133. sleep(5);
  9134. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9135. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9136. interLock.isGetDiagnosticGoing = 0;
  9137. pthread_exit(NULL);
  9138. }
  9139. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9140. {
  9141. mtrace();
  9142. int result = FAIL;
  9143. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9144. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9145. {
  9146. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9147. locallistVersion = -1;
  9148. }
  9149. else
  9150. {
  9151. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9152. OCPP_getListVerion();
  9153. }
  9154. //from db.OCPP_getListVerion
  9155. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9156. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9157. sendGetLocalListVersionConfirmation(uuid,"");
  9158. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9159. return result;
  9160. }
  9161. int handleRemoteStartRequest(char *uuid, char *payload)
  9162. {
  9163. mtrace();
  9164. int result = FAIL;
  9165. int connectorIdInt=-1;
  9166. int tempIndex = 0;
  9167. int connectorIdIsNULL, chargingProfileIsNULL;
  9168. char comfirmstr[20]={0};
  9169. char cmdBuf[512];
  9170. json_object *RemoteStartTransaction;
  9171. FILE *fp;
  9172. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9173. if(server_pending == TRUE)
  9174. {
  9175. return 0;
  9176. }
  9177. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9178. RemoteStartTransaction = json_tokener_parse(payload);
  9179. if(!is_error(RemoteStartTransaction))
  9180. {
  9181. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9182. {
  9183. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9184. }
  9185. else
  9186. {
  9187. connectorIdIsNULL = TRUE;
  9188. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9189. {
  9190. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9191. {
  9192. connectorIdIsNULL = FALSE;
  9193. connectorIdInt = (gun_index+1);
  9194. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9195. break;
  9196. }
  9197. }
  9198. }
  9199. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9200. {
  9201. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9202. // Required data
  9203. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9204. // Optional data
  9205. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9206. {
  9207. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9208. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9209. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9210. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9211. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9212. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9213. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9214. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9215. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9216. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9217. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9218. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9219. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9220. {
  9221. 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")));
  9222. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9223. 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"));
  9224. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9225. 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"));
  9226. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9227. 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")));
  9228. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9229. {
  9230. 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++)
  9231. {
  9232. 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"));
  9233. 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"));
  9234. 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)
  9235. 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"));
  9236. }
  9237. }
  9238. }
  9239. }
  9240. else
  9241. {
  9242. chargingProfileIsNULL = TRUE;
  9243. }
  9244. }
  9245. }
  9246. else
  9247. {
  9248. connectorIdIsNULL = TRUE;
  9249. }
  9250. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9251. {
  9252. DEBUG_WARN("Connector id is NULL\n.");
  9253. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9254. goto end;
  9255. }
  9256. /*
  9257. enum _SYSTEM_STATUS
  9258. {
  9259. S_BOOTING = 0,
  9260. S_IDLE, = 1
  9261. S_AUTHORIZING, = 2
  9262. S_REASSIGN_CHECK, = 3
  9263. S_REASSIGN, = 4
  9264. S_PRECHARGE, = 5
  9265. S_PREPARING_FOR_EV, = 6
  9266. S_PREPARING_FOR_EVSE, = 7
  9267. S_CHARGING, = 8
  9268. S_TERMINATING, = 9
  9269. S_COMPLETE, = 10
  9270. S_ALARM, = 11
  9271. S_FAULT = 12
  9272. }
  9273. */
  9274. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9275. {
  9276. //check Transaction active
  9277. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9278. {
  9279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9280. {
  9281. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9282. }
  9283. else
  9284. {
  9285. tempIndex = connectorIdInt -1;
  9286. }
  9287. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9288. {
  9289. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9290. {
  9291. 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))
  9292. {
  9293. //Reserved
  9294. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9295. }
  9296. 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))
  9297. {
  9298. //Reserved
  9299. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9300. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9301. goto end;
  9302. }
  9303. else
  9304. {
  9305. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9306. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9307. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9308. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9309. {
  9310. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9311. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9312. goto end;
  9313. }
  9314. }//END FOR ELSE
  9315. }
  9316. }// END FOR CHAdeMO_QUANTITY
  9317. }
  9318. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9319. {
  9320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9321. {
  9322. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9323. }
  9324. else
  9325. {
  9326. tempIndex = connectorIdInt -1;
  9327. }
  9328. for (int index = 0; index < CCS_QUANTITY; index++)
  9329. {
  9330. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9331. {
  9332. 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))
  9333. {
  9334. //Reserved
  9335. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9336. }
  9337. 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))
  9338. {
  9339. //Reserved
  9340. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9341. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9342. goto end;
  9343. }
  9344. else
  9345. {
  9346. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9347. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9348. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9349. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9350. {
  9351. DEBUG_WARN("CCS connector not allow start\n.");
  9352. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9353. goto end;
  9354. }
  9355. }// END FOR ELSE
  9356. }
  9357. }// END FOR CCS_QUANTITY
  9358. }
  9359. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9360. {
  9361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9362. {
  9363. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9364. }
  9365. else
  9366. {
  9367. tempIndex = connectorIdInt -1;
  9368. }
  9369. for (int index = 0; index < GB_QUANTITY; index++)
  9370. {
  9371. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9372. {
  9373. 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))
  9374. {
  9375. //Reserved
  9376. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9377. }
  9378. 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))
  9379. {
  9380. //Reserved
  9381. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9382. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9383. goto end;
  9384. }
  9385. else
  9386. {
  9387. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9388. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9389. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9390. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9391. {
  9392. DEBUG_WARN("GB connector not allow start\n.");
  9393. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9394. goto end;
  9395. }
  9396. }// END FOR ELSE
  9397. }
  9398. } // END FOR GB_QUANTITY
  9399. }
  9400. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9401. {
  9402. tempIndex = connectorIdInt -1;
  9403. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9404. {
  9405. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9406. {
  9407. 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))
  9408. {
  9409. //Reserved
  9410. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9411. }
  9412. 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))
  9413. {
  9414. //Reserved
  9415. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9416. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9417. goto end;
  9418. }
  9419. else
  9420. {
  9421. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9422. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9423. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9424. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9425. {
  9426. DEBUG_WARN("GB connector not allow start\n.");
  9427. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9428. goto end;
  9429. }
  9430. }// END FOR ELSE
  9431. }
  9432. } // END FOR GB_QUANTITY
  9433. }
  9434. else
  9435. {
  9436. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9437. {
  9438. tempIndex = 2;
  9439. }
  9440. else
  9441. {
  9442. tempIndex = connectorIdInt -1;
  9443. }
  9444. for (int index = 0; index < AC_QUANTITY; index++)
  9445. {
  9446. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9447. {
  9448. 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))
  9449. {
  9450. //Reserved
  9451. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9452. }
  9453. 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))
  9454. {
  9455. //Reserved
  9456. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9457. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9458. goto end;
  9459. }
  9460. else
  9461. {
  9462. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9463. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9464. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9465. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9466. {
  9467. DEBUG_WARN("AC connector not allow start\n.");
  9468. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9469. goto end;
  9470. }
  9471. }//END FOR ELSE
  9472. }
  9473. }// END FOR AC_QUANTITY
  9474. }
  9475. if(chargingProfileIsNULL == FALSE)
  9476. {
  9477. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9478. {
  9479. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9480. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9481. //memset idTag
  9482. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9483. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9484. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9486. // Save profile to file
  9487. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9488. system(cmdBuf);
  9489. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9490. fp = fopen(cmdBuf, "w");
  9491. 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));
  9492. fclose(fp);
  9493. }
  9494. else
  9495. {
  9496. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9497. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9498. }
  9499. }
  9500. else
  9501. {
  9502. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9503. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9504. //memset idTag
  9505. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9506. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9507. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9509. }
  9510. }
  9511. else
  9512. {
  9513. DEBUG_WARN("Connector id over\n.");
  9514. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9515. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9516. }
  9517. end:
  9518. json_object_put(RemoteStartTransaction);
  9519. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9520. {
  9521. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9522. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9523. }
  9524. //OCPP send RemoteStartConfirmation by first.
  9525. sendRemoteStartConfirmation(uuid, comfirmstr);
  9526. return result;
  9527. }
  9528. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9529. {
  9530. mtrace();
  9531. int result = FAIL;
  9532. int match = FALSE;
  9533. int GunNO = 0;
  9534. int tempIndex = 0;
  9535. int transactionIdInt=0;
  9536. int transactionIdIsNULL= TRUE;
  9537. char comfirmstr[20];
  9538. json_object *RemoteStopTransaction;
  9539. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9540. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9541. if(server_pending == TRUE)
  9542. {
  9543. return 0;
  9544. }
  9545. RemoteStopTransaction = json_tokener_parse(payload);
  9546. if(!is_error(RemoteStopTransaction))
  9547. {
  9548. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9549. {
  9550. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9551. transactionIdIsNULL = FALSE;
  9552. }
  9553. }
  9554. json_object_put(RemoteStopTransaction);
  9555. if(transactionIdIsNULL == FALSE)
  9556. {
  9557. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9558. {
  9559. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9560. {
  9561. //check Transaction active
  9562. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9563. {
  9564. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9565. {
  9566. tempIndex = ((gun_index==2) ? 1: 0);
  9567. }
  9568. else
  9569. {
  9570. tempIndex = gun_index;
  9571. }
  9572. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9573. {
  9574. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9575. {
  9576. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9577. {
  9578. match = TRUE;
  9579. GunNO = gun_index;
  9580. }
  9581. }
  9582. }// END FOR CHAdeMO_QUANTITY
  9583. }
  9584. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9585. {
  9586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9587. {
  9588. tempIndex = ((gun_index==2) ? 1: 0);
  9589. }
  9590. else
  9591. {
  9592. tempIndex = gun_index;
  9593. }
  9594. for (int index = 0; index < CCS_QUANTITY; index++)
  9595. {
  9596. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9597. {
  9598. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9599. {
  9600. match = TRUE;
  9601. GunNO = gun_index;
  9602. }
  9603. }
  9604. }// END FOR CCS_QUANTITY
  9605. }
  9606. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9607. {
  9608. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9609. {
  9610. tempIndex = ((gun_index==2) ? 1: 0);
  9611. }
  9612. else
  9613. {
  9614. tempIndex = gun_index;
  9615. }
  9616. for (int index = 0; index < GB_QUANTITY; index++)
  9617. {
  9618. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9619. {
  9620. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9621. {
  9622. match = TRUE;
  9623. GunNO = gun_index;
  9624. }
  9625. }
  9626. }// END FOR GB_QUANTITY
  9627. }
  9628. else if(gunType[gun_index] == GUN_TYPE_DO)
  9629. {
  9630. tempIndex = gun_index;
  9631. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9632. {
  9633. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9634. {
  9635. 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
  9636. {
  9637. match = TRUE;
  9638. GunNO = gun_index;
  9639. }
  9640. }
  9641. }// END FOR GB_QUANTITY
  9642. }
  9643. else
  9644. {
  9645. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9646. {
  9647. tempIndex = 2;
  9648. }
  9649. else
  9650. {
  9651. tempIndex = gun_index;
  9652. }
  9653. for (int index = 0; index < AC_QUANTITY; index++)
  9654. {
  9655. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9656. {
  9657. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9658. {
  9659. match = TRUE;
  9660. GunNO = gun_index;
  9661. }
  9662. }
  9663. }// END FOR CHAdeMO_QUANTITY
  9664. } // END FOR AC ELSE
  9665. }// CHECK IF ResponseTransactionId == transactionIdInt
  9666. }//END FOR
  9667. if( match == TRUE)
  9668. {
  9669. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9670. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9671. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9672. }
  9673. else
  9674. {
  9675. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9676. }
  9677. }
  9678. else
  9679. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9680. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9681. return result;
  9682. }
  9683. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9684. {
  9685. mtrace();
  9686. int result = FAIL;
  9687. int connectorIdInt=0, reservationIdInt=0;
  9688. int tempIndex = 0;
  9689. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9690. char comfirmstr[20]={0};
  9691. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9692. int c = 0;
  9693. char *loc;
  9694. //char *ptr;
  9695. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9696. strcpy(sstrtemp, stringtrimspace(payload));
  9697. //***(1)connectorId ****/
  9698. c=0;
  9699. loc = strstr(sstrtemp, "connectorId");
  9700. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9701. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9702. {
  9703. sstr[c] = loc[strlen("connectorId")+2+c];
  9704. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9705. c++;
  9706. }
  9707. sstr[c] = '\0';
  9708. connectorIdInt = atoi(sstr);
  9709. //***(2)expiryDate ****/
  9710. loc = strstr(sstrtemp, "expiryDate");
  9711. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9712. c = 0;
  9713. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9714. {
  9715. sstr[c] = loc[3+strlen("expiryDate")+c];
  9716. c++;
  9717. }
  9718. sstr[c] = '\0';
  9719. strcpy(expiryDatestr, sstr);
  9720. //***(3)idTag ****/
  9721. loc = strstr(sstrtemp, "idTag");
  9722. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9723. c = 0;
  9724. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9725. {
  9726. sstr[c] = loc[3+strlen("idTag")+c];
  9727. c++;
  9728. }
  9729. sstr[c] = '\0';
  9730. strcpy(idTagstr, sstr);
  9731. //***(4)parentIdTag ****/
  9732. loc = strstr(sstrtemp, "parentIdTag");
  9733. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9734. c = 0;
  9735. if(loc == NULL)
  9736. {
  9737. strcpy(parentIdTagstr, "");
  9738. }
  9739. else
  9740. {
  9741. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9742. {
  9743. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9744. c++;
  9745. }
  9746. sstr[c] = '\0';
  9747. strcpy(parentIdTagstr, sstr);
  9748. }
  9749. //***(5)reservationId ****/
  9750. c=0;
  9751. loc = strstr(sstrtemp, "reservationId");
  9752. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9753. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9754. {
  9755. sstr[c] = loc[strlen("reservationId")+2+c];
  9756. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9757. c++;
  9758. }
  9759. sstr[c] = '\0';
  9760. reservationIdInt = atoi(sstr);
  9761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9762. /*
  9763. enum SYSTEM_STATUS
  9764. {
  9765. SYS_MODE_BOOTING = 0,
  9766. SYS_MODE_IDLE = 1,
  9767. SYS_MODE_AUTHORIZING = 2,
  9768. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9769. SYS_MODE_REASSIGN = 4,
  9770. SYS_MODE_PREPARING = 5,
  9771. SYS_MODE_PREPARE_FOR_EV = 6,
  9772. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9773. SYS_MODE_CHARGING = 8,
  9774. SYS_MODE_TERMINATING = 9,
  9775. SYS_MODE_COMPLETE = 10,
  9776. SYS_MODE_ALARM = 11,
  9777. SYS_MODE_FAULT = 12,
  9778. SYS_MODE_RESERVATION = 13,
  9779. SYS_MODE_BOOKING = 14,
  9780. SYS_MODE_MAINTAIN = 15,
  9781. SYS_MODE_DEBUG = 16,
  9782. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9783. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9784. SYS_MODE_UPDATE = 19
  9785. };
  9786. */
  9787. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9788. {
  9789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9790. goto end;
  9791. }
  9792. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9793. {
  9794. //check Transaction active
  9795. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9796. {
  9797. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9798. {
  9799. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9800. }
  9801. else
  9802. {
  9803. tempIndex = connectorIdInt -1;
  9804. }
  9805. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9806. {
  9807. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9808. {
  9809. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9810. {
  9811. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9812. {
  9813. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9814. {
  9815. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9817. }
  9818. 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'))
  9819. {
  9820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9821. }
  9822. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9823. {
  9824. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9825. }
  9826. else
  9827. {
  9828. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9829. }
  9830. }
  9831. 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
  9832. {
  9833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9834. }
  9835. }
  9836. else
  9837. {
  9838. //replace reservation
  9839. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9841. }
  9842. }
  9843. } // END FOR CHAdeMO_QUANTITY
  9844. }
  9845. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9846. {
  9847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9848. {
  9849. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9850. }
  9851. else
  9852. {
  9853. tempIndex = connectorIdInt -1;
  9854. }
  9855. for (int index = 0; index < CCS_QUANTITY; index++)
  9856. {
  9857. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9858. {
  9859. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9860. {
  9861. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9862. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9863. {
  9864. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9865. {
  9866. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9867. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9868. }
  9869. 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'))
  9870. {
  9871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9872. }
  9873. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9874. {
  9875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9876. }
  9877. else
  9878. {
  9879. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9880. }
  9881. }
  9882. 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
  9883. {
  9884. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9885. }
  9886. }
  9887. else
  9888. {
  9889. //replace reservation
  9890. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9892. }
  9893. }
  9894. } // END FOR CCS_QUANTITY
  9895. }
  9896. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9897. {
  9898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9899. {
  9900. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9901. }
  9902. else
  9903. {
  9904. tempIndex = connectorIdInt -1;
  9905. }
  9906. for (int index = 0; index < GB_QUANTITY; index++)
  9907. {
  9908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9909. {
  9910. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9911. {
  9912. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9913. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9914. {
  9915. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9916. {
  9917. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9918. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9919. }
  9920. 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'))
  9921. {
  9922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9923. }
  9924. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9925. {
  9926. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9927. }
  9928. else
  9929. {
  9930. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9931. }
  9932. }
  9933. 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
  9934. {
  9935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9936. }
  9937. }
  9938. else
  9939. {
  9940. //replace reservation
  9941. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9943. }
  9944. }
  9945. }// END FOR GB_QUANTITY
  9946. }
  9947. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9948. {
  9949. tempIndex = connectorIdInt -1;
  9950. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9951. {
  9952. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9953. {
  9954. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9955. {
  9956. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9957. 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
  9958. {
  9959. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9960. {
  9961. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9963. }
  9964. 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'))
  9965. {
  9966. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9967. }
  9968. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9969. {
  9970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9971. }
  9972. else
  9973. {
  9974. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9975. }
  9976. }
  9977. else if((ShmSysConfigAndInfo->SysInfo.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
  9978. {
  9979. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9980. }
  9981. }
  9982. else
  9983. {
  9984. //replace reservation
  9985. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9987. }
  9988. }
  9989. }// END FOR GB_QUANTITY
  9990. }
  9991. else
  9992. {
  9993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9994. {
  9995. tempIndex = 2;
  9996. }
  9997. else
  9998. {
  9999. tempIndex = (connectorIdInt -1);
  10000. }
  10001. for (int index = 0; index < AC_QUANTITY; index++)
  10002. {
  10003. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10004. {
  10005. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10006. {
  10007. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  10008. {
  10009. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10010. {
  10011. 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))
  10012. {
  10013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10014. }
  10015. else
  10016. {
  10017. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10018. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10019. }
  10020. }
  10021. 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'))
  10022. {
  10023. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10024. }
  10025. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  10026. {
  10027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10028. }
  10029. else
  10030. {
  10031. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10032. }
  10033. }
  10034. 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
  10035. {
  10036. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10037. }
  10038. }
  10039. else
  10040. {
  10041. //replace reservation
  10042. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10044. }
  10045. }
  10046. } // END FOR AC_QUANTITY
  10047. }
  10048. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10049. }
  10050. else if(connectorIdInt == 0)
  10051. {
  10052. //check Transaction active
  10053. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10054. {
  10055. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10056. {
  10057. 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'))
  10058. {
  10059. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10060. goto end;
  10061. }
  10062. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10063. {
  10064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10065. goto end;
  10066. }
  10067. 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
  10068. {
  10069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10070. goto end;
  10071. }
  10072. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10073. {
  10074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10075. goto end;
  10076. }
  10077. }
  10078. }// END FOR CHAdeMO_QUANTITY
  10079. for (int index = 0; index < CCS_QUANTITY; index++)
  10080. {
  10081. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10082. {
  10083. 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'))
  10084. {
  10085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10086. goto end;
  10087. }
  10088. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10089. {
  10090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10091. goto end;
  10092. }
  10093. 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
  10094. {
  10095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10096. goto end;
  10097. }
  10098. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10099. {
  10100. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10101. goto end;
  10102. }
  10103. }
  10104. } // END FOR CCS_QUANTITY
  10105. for (int index = 0; index < GB_QUANTITY; index++)
  10106. {
  10107. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10108. {
  10109. 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'))
  10110. {
  10111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10112. goto end;
  10113. }
  10114. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10115. {
  10116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10117. goto end;
  10118. }
  10119. 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
  10120. {
  10121. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10122. goto end;
  10123. }
  10124. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10125. {
  10126. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10127. goto end;
  10128. }
  10129. }
  10130. } // END FOR GB_QUANTITY
  10131. for (int index = 0; index < AC_QUANTITY; index++)
  10132. {
  10133. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10134. {
  10135. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == 11) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == '9'))
  10136. {
  10137. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10138. goto end;
  10139. }
  10140. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10141. {
  10142. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10143. goto end;
  10144. }
  10145. 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
  10146. {
  10147. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10148. goto end;
  10149. }
  10150. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10151. {
  10152. 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))
  10153. {
  10154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10155. goto end;
  10156. }
  10157. }
  10158. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10159. {
  10160. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10161. goto end;
  10162. }
  10163. }
  10164. }// END FOR AC_QUANTITY
  10165. //The connectorId is 0
  10166. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10168. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10169. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10170. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10171. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10172. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10173. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  10174. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  10175. result = TRUE;
  10176. return result;
  10177. }
  10178. else
  10179. {
  10180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10181. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10182. }
  10183. if(strcmp(comfirmstr,"Accepted") == 0)
  10184. {
  10185. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10186. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10187. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10188. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10189. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10190. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  10191. result = TRUE;
  10192. return result;
  10193. }
  10194. end:
  10195. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10196. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10197. return result;
  10198. }
  10199. int handleResetRequest(char *uuid, char *payload)
  10200. {
  10201. mtrace();
  10202. int result = FAIL;
  10203. char sstr[10]={0},sstrtemp[30]={ 0 };
  10204. char typestr[10]={0};
  10205. char comfirmstr[20]={0};
  10206. int c = 0;
  10207. char *loc;
  10208. DEBUG_INFO("handleResetRequest...\n");
  10209. strcpy(sstrtemp, stringtrimspace(payload));
  10210. loc = strstr(sstrtemp, "type");
  10211. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10212. c = 0;
  10213. while (loc[3+strlen("type")+c] != '\"')
  10214. {
  10215. sstr[c] = loc[3+strlen("type")+c];
  10216. c++;
  10217. }
  10218. sstr[c] = '\0';
  10219. strcpy(typestr,sstr);
  10220. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  10221. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10222. {
  10223. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  10224. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  10225. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10226. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10227. }
  10228. else
  10229. {
  10230. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10231. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10232. result = PASS;
  10233. }
  10234. sendResetConfirmation(uuid, comfirmstr);
  10235. return result;
  10236. }
  10237. int handleSendLocalListRequest(char *uuid, char *payload)
  10238. {
  10239. mtrace();
  10240. int result = FAIL;
  10241. char comfirmstr[20];
  10242. int checkState_Faulted = FALSE;
  10243. json_object *SendLocalList;
  10244. DEBUG_INFO("handleSendLocalListRequest...\n");
  10245. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10246. {
  10247. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10248. goto end;
  10249. }
  10250. //check Charge Point state
  10251. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10252. {
  10253. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10254. {
  10255. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10256. }
  10257. }
  10258. for (int index = 0; index < CCS_QUANTITY; index++)
  10259. {
  10260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10261. {
  10262. checkState_Faulted = TRUE; //OCPP Status
  10263. }
  10264. }
  10265. for (int index = 0; index < GB_QUANTITY; index++)
  10266. {
  10267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10268. {
  10269. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10270. }
  10271. }
  10272. //check Charge Point state
  10273. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10274. {
  10275. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10276. {
  10277. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10278. }
  10279. }
  10280. //check Charge Point state
  10281. for (int index = 0; index < AC_QUANTITY; index++)
  10282. {
  10283. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10284. {
  10285. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10286. }
  10287. }
  10288. if(checkState_Faulted == TRUE)
  10289. {
  10290. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10291. goto end;
  10292. }
  10293. // Parsing payload
  10294. SendLocalList = json_tokener_parse(payload);
  10295. if(!is_error(SendLocalList))
  10296. {
  10297. // Required data
  10298. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10299. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10300. // Optional data
  10301. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10302. {
  10303. //Check UpdateType
  10304. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10305. {
  10306. //Local list full update
  10307. DEBUG_INFO("Local list full update.\n");
  10308. OCPP_getListVerion();
  10309. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10310. {
  10311. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10312. goto end;
  10313. }
  10314. OCPP_cleanLocalList();
  10315. }
  10316. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10317. {
  10318. //Local list different update
  10319. DEBUG_INFO("Local list different update.\n");
  10320. OCPP_getListVerion();
  10321. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10322. {
  10323. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10324. goto end;
  10325. }
  10326. }
  10327. else
  10328. {
  10329. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10330. goto end;
  10331. }
  10332. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10333. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10334. {
  10335. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  10336. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10337. {
  10338. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  10339. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10340. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  10341. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10342. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  10343. }
  10344. // Add to db
  10345. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10346. {
  10347. //Local list full update
  10348. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10349. idx,
  10350. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10351. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10352. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10353. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10354. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10355. // update list
  10356. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10357. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10358. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10359. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10360. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10361. }
  10362. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10363. {
  10364. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10365. idx,
  10366. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10367. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10368. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10369. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10370. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10371. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10372. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10373. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10374. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10375. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10376. }
  10377. }
  10378. }
  10379. else
  10380. {
  10381. //Check UpdateType
  10382. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10383. {
  10384. //Local list full update
  10385. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10386. OCPP_cleanLocalList();
  10387. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10388. goto end;
  10389. }
  10390. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10391. {
  10392. //Local list different update
  10393. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10394. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10395. goto end;
  10396. }
  10397. }
  10398. result = PASS;
  10399. }
  10400. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10401. end:
  10402. json_object_put(SendLocalList);
  10403. sendSendLocalListConfirmation(uuid, comfirmstr);
  10404. return result;
  10405. }
  10406. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10407. {
  10408. mtrace();
  10409. int result = FAIL;
  10410. struct StructSetChargingProfile SetProfileReq = {0};
  10411. int tempchargingProfileIdInt;
  10412. int chargingSchedulePeriodCount = 0;
  10413. char comfirmstr[20]={0};
  10414. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10415. char rmFileCmd[128]={0};
  10416. int profileQuantity = 0;
  10417. json_object *SetChargingProfile;
  10418. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10419. SetChargingProfile = json_tokener_parse(payload);
  10420. if(!is_error(SetChargingProfile))
  10421. {
  10422. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10423. {
  10424. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10425. }
  10426. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10427. {
  10428. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10429. {
  10430. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10431. }
  10432. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10433. {
  10434. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10435. }
  10436. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10437. {
  10438. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10439. }
  10440. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10441. {
  10442. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10443. }
  10444. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10445. {
  10446. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10447. }
  10448. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10449. {
  10450. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10451. }
  10452. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10453. {
  10454. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10455. }
  10456. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10457. {
  10458. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10459. }
  10460. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10461. {
  10462. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10463. {
  10464. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.ChargingRateUnit, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  10465. }
  10466. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10467. {
  10468. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10469. }
  10470. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10471. {
  10472. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10473. }
  10474. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10475. {
  10476. strcpy((char*)SetProfileReq.ChargingProfile.ChargingSchedule.StartSchedule, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  10477. }
  10478. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10479. {
  10480. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10481. if(chargingSchedulePeriodCount <= 10)
  10482. {
  10483. 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++)
  10484. {
  10485. 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)
  10486. {
  10487. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  10488. }
  10489. 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)
  10490. {
  10491. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  10492. }
  10493. 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)
  10494. {
  10495. SetProfileReq.ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  10496. }
  10497. }
  10498. }
  10499. }
  10500. }
  10501. }
  10502. }
  10503. // Profile periods quantity check
  10504. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10505. {
  10506. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10507. goto end;
  10508. }
  10509. // Profile purpose info check
  10510. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10511. {
  10512. FILE *fp;
  10513. char dataLine[4096]={0};
  10514. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  10515. if(SetProfileReq.ConnectorId != 0)
  10516. {
  10517. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10518. goto end;
  10519. }
  10520. fp = fopen(ChargePointMaxProfile_JSON, "r");
  10521. if (!fp)
  10522. {
  10523. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  10524. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  10525. }
  10526. else
  10527. {
  10528. while(fscanf(fp, "%s", dataLine) != EOF)
  10529. {
  10530. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10531. {
  10532. profileQuantity += 1;
  10533. }
  10534. }
  10535. }
  10536. fclose(fp);
  10537. }
  10538. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10539. {
  10540. FILE *fp;
  10541. char dataLine[4096]={0};
  10542. char filename[128]={0};
  10543. int tmpProfileQuantity;
  10544. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  10545. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10546. {
  10547. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10548. goto end;
  10549. }
  10550. if(SetProfileReq.ConnectorId == 0)
  10551. {
  10552. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  10553. {
  10554. tmpProfileQuantity = 0;
  10555. memset(filename, 0, ARRAY_SIZE(filename));
  10556. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10557. fp = fopen(filename, "r");
  10558. if (!fp)
  10559. {
  10560. DEBUG_INFO("%s does not create.\n", filename);
  10561. fp = fopen(filename, "w+");
  10562. }
  10563. else
  10564. {
  10565. while(fscanf(fp, "%s", dataLine) != EOF)
  10566. {
  10567. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10568. {
  10569. tmpProfileQuantity += 1;
  10570. }
  10571. }
  10572. }
  10573. fclose(fp);
  10574. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  10575. }
  10576. }
  10577. else
  10578. {
  10579. memset(filename, 0, ARRAY_SIZE(filename));
  10580. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10581. fp = fopen(filename, "r");
  10582. if (!fp)
  10583. {
  10584. DEBUG_INFO("%s does not create.\n", filename);
  10585. fp = fopen(filename, "w+");
  10586. }
  10587. else
  10588. {
  10589. while(fscanf(fp, "%s", dataLine) != EOF)
  10590. {
  10591. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10592. {
  10593. profileQuantity += 1;
  10594. }
  10595. }
  10596. }
  10597. fclose(fp);
  10598. }
  10599. }
  10600. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10601. {
  10602. int isMatchTransactiodId= FALSE;
  10603. FILE *fp;
  10604. char dataLine[4096]={0};
  10605. char filename[128]={0};
  10606. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  10607. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10608. if(SetProfileReq.ConnectorId == 0)
  10609. {
  10610. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10611. goto end;
  10612. }
  10613. int tempIndex = 0;
  10614. //check Transaction active
  10615. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  10616. {
  10617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10618. {
  10619. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10620. }
  10621. else
  10622. {
  10623. tempIndex = SetProfileReq.ConnectorId -1;
  10624. }
  10625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10626. {
  10627. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10628. {
  10629. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10630. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10631. {
  10632. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10633. {
  10634. isMatchTransactiodId = TRUE;
  10635. break;
  10636. }
  10637. }
  10638. }
  10639. }
  10640. }
  10641. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  10642. {
  10643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10644. {
  10645. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10646. }
  10647. else
  10648. {
  10649. tempIndex = SetProfileReq.ConnectorId -1;
  10650. }
  10651. for (int index = 0; index < CCS_QUANTITY; index++)
  10652. {
  10653. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10654. {
  10655. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10656. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10657. {
  10658. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10659. {
  10660. isMatchTransactiodId = TRUE;
  10661. break;
  10662. }
  10663. }
  10664. }
  10665. }
  10666. }
  10667. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  10668. {
  10669. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10670. {
  10671. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10672. }
  10673. else
  10674. {
  10675. tempIndex = SetProfileReq.ConnectorId -1;
  10676. }
  10677. for (int index = 0; index < GB_QUANTITY; index++)
  10678. {
  10679. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10680. {
  10681. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10682. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10683. {
  10684. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10685. {
  10686. isMatchTransactiodId = TRUE;
  10687. break;
  10688. }
  10689. }
  10690. }
  10691. }
  10692. }
  10693. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  10694. {
  10695. tempIndex = SetProfileReq.ConnectorId -1;
  10696. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10697. {
  10698. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10699. {
  10700. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10701. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10702. {
  10703. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10704. {
  10705. isMatchTransactiodId = TRUE;
  10706. break;
  10707. }
  10708. }
  10709. }
  10710. }
  10711. }
  10712. else
  10713. {
  10714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10715. {
  10716. tempIndex = 2;
  10717. }
  10718. else
  10719. {
  10720. tempIndex = (SetProfileReq.ConnectorId -1);
  10721. }
  10722. for (int index = 0; index < AC_QUANTITY; index++)
  10723. {
  10724. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10725. {
  10726. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10727. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10728. {
  10729. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10730. {
  10731. isMatchTransactiodId = TRUE;
  10732. break;
  10733. }
  10734. }
  10735. }
  10736. }
  10737. }
  10738. //check Transaction active
  10739. if(isMatchTransactiodId == FALSE)
  10740. {
  10741. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10742. goto end;
  10743. }
  10744. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10745. {
  10746. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10747. goto end;
  10748. }
  10749. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10750. fp = fopen(filename, "r");
  10751. if (!fp)
  10752. {
  10753. DEBUG_INFO("%s does not create.\n", filename);
  10754. fp = fopen(filename, "w+");
  10755. }
  10756. else
  10757. {
  10758. //Check Charging Profile Count
  10759. while(fscanf(fp, "%s", dataLine) != EOF)
  10760. {
  10761. //DEBUG_INFO("word=%s\n",word);
  10762. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10763. {
  10764. profileQuantity += 1;
  10765. }
  10766. }
  10767. }
  10768. fclose(fp);
  10769. }
  10770. // Check ChargeProfileMaxStackLevel
  10771. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  10772. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10773. {
  10774. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10775. goto end;
  10776. }
  10777. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10778. {
  10779. FILE *fp;
  10780. char dataLine[4096]={0};
  10781. char fnametemp[128]={0};
  10782. int tmpProfileQuantity;
  10783. //Check ChargePointMaxProfile.json exit
  10784. profileQuantity = 0;
  10785. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10786. {
  10787. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10788. //Check Charging Profile Count
  10789. tmpProfileQuantity = 0;
  10790. while(fscanf(fp, "%s", dataLine) != EOF)
  10791. {
  10792. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10793. {
  10794. profileQuantity += 1;
  10795. tmpProfileQuantity += 1;
  10796. }
  10797. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10798. }
  10799. fclose(fp);
  10800. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  10801. }
  10802. //Check TxDefaultProfile_%d.json
  10803. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  10804. {
  10805. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10806. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10807. if((access(fnametemp,F_OK))!=-1)
  10808. {
  10809. fp = fopen(fnametemp, "r");
  10810. //Check Charging Profile Count
  10811. tmpProfileQuantity = 0;
  10812. while(fscanf(fp, "%s", dataLine) != EOF)
  10813. {
  10814. //DEBUG_INFO("word=%s\n",word);
  10815. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10816. {
  10817. profileQuantity += 1;
  10818. tmpProfileQuantity += 1;
  10819. }
  10820. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10821. }
  10822. fclose(fp);
  10823. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  10824. }
  10825. }
  10826. //Check TxProfile_%d.json
  10827. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  10828. {
  10829. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10830. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  10831. if((access(fnametemp,F_OK))!=-1)
  10832. {
  10833. fp = fopen(fnametemp, "r");
  10834. //Check Charging Profile Count
  10835. tmpProfileQuantity = 0;
  10836. while(fscanf(fp, "%s", dataLine) != EOF)
  10837. {
  10838. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10839. {
  10840. profileQuantity += 1;
  10841. tmpProfileQuantity += 1;
  10842. }
  10843. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10844. }
  10845. fclose(fp);
  10846. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  10847. }
  10848. }
  10849. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  10850. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10851. {
  10852. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10853. goto end;
  10854. }
  10855. }
  10856. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10857. //**********************************Write to File********************************************************/
  10858. {
  10859. FILE *infile;
  10860. FILE *outfile;
  10861. char dataLine[4096]={0};
  10862. char filename[128]={0};
  10863. int chkChar=0;
  10864. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  10865. {
  10866. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10867. {
  10868. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  10869. }
  10870. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10871. {
  10872. if(SetProfileReq.ConnectorId==0)
  10873. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10874. else
  10875. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10876. }
  10877. else
  10878. {
  10879. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10880. }
  10881. infile = fopen (filename, "r");
  10882. outfile = fopen (tempfile, "w");
  10883. chkChar = fgetc(infile);
  10884. rewind(infile);
  10885. if(chkChar == EOF)
  10886. {
  10887. // Profile is empty
  10888. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10889. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10890. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10891. fclose(infile);
  10892. fclose(outfile);
  10893. sprintf(rmFileCmd,"rm -f %s",filename);
  10894. system(rmFileCmd);
  10895. rename(tempfile, filename);
  10896. }
  10897. else
  10898. {
  10899. // Profile is not empty
  10900. int ChargingProfileAdded = FALSE;
  10901. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  10902. {
  10903. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  10904. json_object *tmpChargingProfile;
  10905. tmpChargingProfile = json_tokener_parse(dataLine);
  10906. if(!is_error(SetChargingProfile))
  10907. {
  10908. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10909. {
  10910. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10911. {
  10912. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10913. }
  10914. }
  10915. }
  10916. json_object_put(tmpChargingProfile);
  10917. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  10918. {
  10919. if(ChargingProfileAdded == FALSE)
  10920. {
  10921. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10922. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10923. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10924. ChargingProfileAdded = TRUE;
  10925. }
  10926. }
  10927. else
  10928. {
  10929. fprintf(outfile,"%s\n",dataLine);
  10930. if(ChargingProfileAdded == FALSE)
  10931. {
  10932. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10933. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10934. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10935. ChargingProfileAdded = TRUE;
  10936. }
  10937. }
  10938. } // end of while loop
  10939. fclose(infile);
  10940. fclose(outfile);
  10941. sprintf(rmFileCmd,"rm -f %s",filename);
  10942. system(rmFileCmd);
  10943. rename(tempfile, filename);
  10944. }
  10945. }
  10946. sleep(1);
  10947. result = TRUE;
  10948. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10949. }
  10950. end:
  10951. json_object_put(SetChargingProfile);
  10952. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10953. {
  10954. if(SetProfileReq.ConnectorId == 0)
  10955. {
  10956. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10957. {
  10958. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10959. }
  10960. }
  10961. else
  10962. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  10963. }
  10964. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10965. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10966. return result;
  10967. }
  10968. int handleTriggerMessageRequest(char *uuid, char *payload)
  10969. {
  10970. mtrace();
  10971. int result = FAIL;
  10972. int connectorIdIsNULL = FALSE;
  10973. int connectorIdInt =0;
  10974. char sstr[40]={0},sstrtemp[100]={ 0 };
  10975. char requestedMessagestr[40]={0};
  10976. char comfirmstr[20]={0};
  10977. int c = 0;
  10978. char *loc;
  10979. DEBUG_INFO("handleTriggerMessageRequest\n");
  10980. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10981. strcpy(sstrtemp, stringtrimspace(payload));
  10982. c = 0;
  10983. loc = strstr(sstrtemp, "requestedMessage");
  10984. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10985. {
  10986. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10987. c++;
  10988. }
  10989. sstr[c] = '\0';
  10990. strcpy(requestedMessagestr, sstr);
  10991. c = 0;
  10992. loc = strstr(sstrtemp, "connectorId");
  10993. if(loc == NULL)
  10994. {
  10995. connectorIdIsNULL = TRUE;
  10996. }
  10997. else
  10998. {
  10999. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11000. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  11001. {
  11002. sstr[c] = loc[strlen("connectorId")+2+c];
  11003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11004. c++;
  11005. }
  11006. sstr[c] = '\0';
  11007. connectorIdInt = atoi(sstr);
  11008. }
  11009. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  11010. {
  11011. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  11012. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  11013. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11014. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  11015. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  11016. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  11017. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  11018. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  11019. {
  11020. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11021. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11022. return TRUE;
  11023. }
  11024. else
  11025. {
  11026. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11027. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11028. }
  11029. }
  11030. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11031. {
  11032. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11033. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11034. return TRUE;
  11035. }
  11036. //==========================
  11037. // Trigger message
  11038. //==========================
  11039. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11040. {
  11041. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11042. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11043. {
  11044. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11045. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11046. }
  11047. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11048. }
  11049. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11050. {
  11051. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11052. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11053. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11054. }
  11055. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11056. {
  11057. //sendBootNotificationRequest();
  11058. server_sign = FALSE;
  11059. }
  11060. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11061. {
  11062. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11063. }
  11064. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11065. {
  11066. if(connectorIdIsNULL == FALSE)
  11067. {
  11068. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11069. {
  11070. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11071. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11072. }
  11073. }
  11074. else
  11075. {
  11076. for(int idx=0;idx< gunTotalNumber;idx++)
  11077. {
  11078. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11079. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11080. }
  11081. }
  11082. }
  11083. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11084. {
  11085. if(connectorIdIsNULL == FALSE)
  11086. {
  11087. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11088. {
  11089. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11090. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11091. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11092. }
  11093. }
  11094. else
  11095. {
  11096. for(int idx=0;idx< gunTotalNumber;idx++)
  11097. {
  11098. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11099. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11100. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11101. }
  11102. }
  11103. }
  11104. return result;
  11105. }
  11106. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11107. {
  11108. mtrace();
  11109. int result = FAIL;
  11110. int connectorIdInt =0;
  11111. char comfirmstr[20]={0};
  11112. int tempIndex = 0;
  11113. json_object *UnlockConnector;
  11114. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11115. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11116. UnlockConnector = json_tokener_parse(payload);
  11117. if(!is_error(UnlockConnector))
  11118. {
  11119. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11120. {
  11121. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11122. }
  11123. }
  11124. json_object_put(UnlockConnector);
  11125. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11126. if(gunTotalNumber == 0)
  11127. {
  11128. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11129. goto end;
  11130. }
  11131. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11132. {
  11133. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11134. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11135. goto end;
  11136. }
  11137. else
  11138. {
  11139. //check Transaction active
  11140. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11141. {
  11142. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11143. {
  11144. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11145. }
  11146. else
  11147. {
  11148. tempIndex = connectorIdInt -1;
  11149. }
  11150. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11151. {
  11152. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  11153. {
  11154. //stop Transaction
  11155. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11156. }
  11157. }
  11158. }
  11159. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11160. {
  11161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11162. {
  11163. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11164. }
  11165. else
  11166. {
  11167. tempIndex = connectorIdInt -1;
  11168. }
  11169. for (int index = 0; index < CCS_QUANTITY; index++)
  11170. {
  11171. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  11172. {
  11173. //stop Transaction
  11174. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11175. }
  11176. }
  11177. }
  11178. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11179. {
  11180. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11181. {
  11182. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11183. }
  11184. else
  11185. {
  11186. tempIndex = connectorIdInt -1;
  11187. }
  11188. for (int index = 0; index < GB_QUANTITY; index++)
  11189. {
  11190. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  11191. {
  11192. //stop Transaction
  11193. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11194. }
  11195. }
  11196. }
  11197. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11198. {
  11199. tempIndex = connectorIdInt -1;
  11200. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11201. {
  11202. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  11203. {
  11204. //stop Transaction
  11205. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11206. }
  11207. }
  11208. }
  11209. else
  11210. {
  11211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11212. {
  11213. tempIndex = 2;
  11214. }
  11215. else
  11216. {
  11217. tempIndex = connectorIdInt-1;
  11218. }
  11219. for (int index = 0; index < AC_QUANTITY; index++)
  11220. {
  11221. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  11222. {
  11223. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11224. }
  11225. }
  11226. }
  11227. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11228. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  11229. result = TRUE;
  11230. return result;
  11231. }
  11232. end:
  11233. //json_object_put(obj); --- remove temporally
  11234. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11235. return result;
  11236. }
  11237. static char UpdateFirmwarepayloadData[300]={0};
  11238. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11239. {
  11240. mtrace();
  11241. int result = FAIL;
  11242. pthread_t t;
  11243. sendUpdateFirmwareConfirmation(uuid);
  11244. memset(UpdateFirmwarepayloadData, 0, 300);
  11245. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11246. if(!interLock.isUpdateFirmwareGoing)
  11247. {
  11248. interLock.isUpdateFirmwareGoing = 1;
  11249. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11250. sleep(1);
  11251. }
  11252. else
  11253. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11254. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  11255. return result;
  11256. }
  11257. void *UpdateFirmwareProcess(void *data)
  11258. {
  11259. pthread_detach(pthread_self());
  11260. mtrace();
  11261. int retriesInt =0, retryIntervalInt=0;
  11262. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  11263. int port=0;
  11264. char locationstr[512]={0}, retrieveDatestr[36]={0};
  11265. int isSuccess = 0;
  11266. char ftpbuf[512];
  11267. char temp[100];
  11268. char * pch;
  11269. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11270. json_object *UpdateFirmware;
  11271. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11272. if(!is_error(UpdateFirmware))
  11273. {
  11274. // Required data
  11275. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11276. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11277. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11278. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11279. // Optional data
  11280. if(json_object_object_get(UpdateFirmware, "retries"))
  11281. {
  11282. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11283. }
  11284. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11285. {
  11286. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11287. }
  11288. }
  11289. json_object_put(UpdateFirmware);
  11290. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11291. memset(path, 0, ARRAY_SIZE(path));
  11292. // Wait retrieveData
  11293. if(strlen(retrieveDatestr) > 10)
  11294. {
  11295. do
  11296. {
  11297. sleep(1);
  11298. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11299. }
  11300. // Ready to download
  11301. system("rm -f /mnt/*");
  11302. if(strncmp(locationstr,"http", 4) == 0)
  11303. {
  11304. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11305. sprintf(ftppath,"/%s", path);
  11306. DEBUG_INFO("locationstr: %s\n", locationstr);
  11307. DEBUG_INFO("protocol: %s\n",protocol);
  11308. DEBUG_INFO("host: %s\n",host);
  11309. DEBUG_INFO("path: %s\n",path);
  11310. DEBUG_INFO("ftppath: %s\n",ftppath);
  11311. int ftppathlen=strlen(ftppath);
  11312. int i=1;
  11313. char filenametemp[50];
  11314. while(i < ftppathlen)
  11315. {
  11316. int len=ftppathlen-i;
  11317. if(ftppath[len]== 47) // '/' ascll code: 47
  11318. {
  11319. DEBUG_INFO("compare '/' all right\n");
  11320. break;
  11321. }
  11322. i=i+1;
  11323. }
  11324. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11325. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11326. filenametemp[i+1] = 0;
  11327. do
  11328. {
  11329. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11330. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11331. sleep(1);
  11332. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11333. if(!isSuccess)
  11334. {
  11335. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11336. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11337. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11338. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11339. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11340. }
  11341. else
  11342. {
  11343. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11344. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11345. }
  11346. retriesInt--;
  11347. }while((isSuccess == 0)&&(retriesInt >= 0));
  11348. }
  11349. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11350. {
  11351. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11352. memset(temp, 0, ARRAY_SIZE(temp));
  11353. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11354. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11355. int ftppathlen=strlen(ftpbuf);
  11356. int i=1;
  11357. char filenametemp[50];
  11358. while(i < ftppathlen)
  11359. {
  11360. int len=ftppathlen-i;
  11361. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11362. {
  11363. DEBUG_INFO(" compare '/' all right\n");
  11364. break;
  11365. }
  11366. i=i+1;
  11367. }
  11368. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11369. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11370. filenametemp[i+1] = 0;
  11371. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11372. pch=strchr(temp,'@');
  11373. if(pch==NULL)
  11374. {
  11375. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11376. protocol, host, &port, path);
  11377. strcpy(user,"anonymous");
  11378. strcpy(password,"");
  11379. }
  11380. else
  11381. {
  11382. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11383. protocol, user, password, host, &port, path);
  11384. }
  11385. sscanf(host,"%[^/]%s",host1, path1);
  11386. sprintf(ftppath,"%s", path1);
  11387. //DEBUG_INFO("protocol =%s\n",protocol);
  11388. //DEBUG_INFO("user =%s\n",user);
  11389. //DEBUG_INFO("password =%s\n",password);
  11390. //DEBUG_INFO("host1 =%s\n",host1);
  11391. //DEBUG_INFO("port =%d\n",port);
  11392. //DEBUG_INFO("path1 =%s\n",path1);
  11393. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11394. //ftpFile(host, user, password, port, ftppath, fname);
  11395. //download firmware pthred
  11396. if(port == 0)
  11397. {
  11398. port = 21;
  11399. }
  11400. do
  11401. {
  11402. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11403. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11404. sleep(1);
  11405. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11406. if(!isSuccess)
  11407. {
  11408. //BulldogUtil.sleepMs(interval*1000);
  11409. DEBUG_INFO("Update firmware request and download file fail.\n");
  11410. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11411. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11412. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11413. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11414. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11415. }
  11416. else
  11417. {
  11418. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11419. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11420. }
  11421. retriesInt--;
  11422. }while((!isSuccess)&&(retriesInt >= 0));
  11423. }
  11424. else
  11425. {
  11426. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11427. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11428. sleep(1);
  11429. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11430. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11431. }
  11432. // OCPPPH only, must announce CSU upgrade firmware
  11433. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  11434. interLock.isUpdateFirmwareGoing = 0;
  11435. pthread_exit(NULL);
  11436. }
  11437. int handleCertificateSignedRequest(char *uuid, char *payload)
  11438. {
  11439. mtrace();
  11440. int result = PASS;
  11441. json_object *CertificateSigned;
  11442. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11443. CertificateSigned = json_tokener_parse(payload);
  11444. if(!is_error(CertificateSigned))
  11445. {
  11446. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11447. }
  11448. json_object_put(CertificateSigned);
  11449. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  11450. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  11451. fclose(fp);
  11452. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11453. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  11454. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  11455. sendCertificateSignedConfirmation(uuid);
  11456. return result;
  11457. }
  11458. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11459. {
  11460. mtrace();
  11461. int result = PASS;
  11462. json_object *DeleteCertificate;
  11463. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11464. DeleteCertificate = json_tokener_parse(payload);
  11465. if(!is_error(DeleteCertificate))
  11466. {
  11467. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11468. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11469. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11470. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11471. }
  11472. json_object_put(DeleteCertificate);
  11473. /*
  11474. * TODO: Delete certificateSigned process
  11475. */
  11476. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  11477. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  11478. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  11479. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  11480. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  11481. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  11482. sendDeleteCertificateConfirmation(uuid);
  11483. return result;
  11484. }
  11485. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11486. {
  11487. mtrace();
  11488. int result = PASS;
  11489. json_object *ExtendedTriggerMessage;
  11490. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11491. ExtendedTriggerMessage = json_tokener_parse(payload);
  11492. if(!is_error(ExtendedTriggerMessage))
  11493. {
  11494. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11495. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11496. {
  11497. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11498. }
  11499. else
  11500. {
  11501. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  11502. }
  11503. }
  11504. json_object_put(ExtendedTriggerMessage);
  11505. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  11506. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  11507. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11508. {
  11509. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11510. }
  11511. else
  11512. {
  11513. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11514. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11515. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11516. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11517. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11518. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11519. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11520. {
  11521. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11522. }
  11523. else
  11524. {
  11525. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11526. }
  11527. }
  11528. sendExtendedTriggerMessageConfirmation(uuid);
  11529. //==========================
  11530. // Trigger message
  11531. //==========================
  11532. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11533. {
  11534. //sendBootNotificationRequest();
  11535. server_sign = FALSE;
  11536. }
  11537. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11538. {
  11539. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  11540. }
  11541. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11542. {
  11543. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11544. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11545. {
  11546. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11547. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11548. }
  11549. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11550. }
  11551. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11552. {
  11553. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11554. }
  11555. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11556. {
  11557. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11558. {
  11559. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11560. }
  11561. else
  11562. {
  11563. for(int idx=0;idx< gunTotalNumber;idx++)
  11564. {
  11565. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11566. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11567. }
  11568. }
  11569. }
  11570. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11571. {
  11572. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  11573. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  11574. {
  11575. 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\" &");
  11576. }
  11577. }
  11578. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11579. {
  11580. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11581. {
  11582. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11583. }
  11584. else
  11585. {
  11586. for(int idx=0;idx< gunTotalNumber;idx++)
  11587. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11588. }
  11589. }
  11590. return result;
  11591. }
  11592. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11593. {
  11594. mtrace();
  11595. int result = PASS;
  11596. json_object *GetInstalledCertificateIds;
  11597. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11598. GetInstalledCertificateIds = json_tokener_parse(payload);
  11599. if(!is_error(GetInstalledCertificateIds))
  11600. {
  11601. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11602. }
  11603. json_object_put(GetInstalledCertificateIds);
  11604. /*
  11605. * TODO: Return installed certificate process
  11606. */
  11607. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11608. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  11609. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11610. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  11611. sendGetInstalledCertificateIdsConfirmation(uuid);
  11612. return result;
  11613. }
  11614. int handleGetLogRequest(char *uuid, char *payload)
  11615. {
  11616. mtrace();
  11617. int result = PASS;
  11618. json_object *GetLog;
  11619. DEBUG_INFO("handleGetLogRequest...\n");
  11620. GetLog = json_tokener_parse(payload);
  11621. if(!is_error(GetLog))
  11622. {
  11623. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11624. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11625. if(json_object_object_get(GetLog, "retries") != NULL)
  11626. {
  11627. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11628. }
  11629. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11630. {
  11631. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11632. }
  11633. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11634. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11635. {
  11636. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11637. }
  11638. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11639. {
  11640. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11641. }
  11642. }
  11643. json_object_put(GetLog);
  11644. /*
  11645. * TODO: Upload log process
  11646. */
  11647. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  11648. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  11649. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  11650. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  11651. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  11652. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  11653. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  11654. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  11655. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  11656. sendGetLogConfirmation(uuid);
  11657. return result;
  11658. }
  11659. int handleInstallCertificateRequest(char *uuid, char *payload)
  11660. {
  11661. mtrace();
  11662. int result = PASS;
  11663. json_object *InstallCertificate;
  11664. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11665. InstallCertificate = json_tokener_parse(payload);
  11666. if(!is_error(InstallCertificate))
  11667. {
  11668. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11669. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11670. /*
  11671. * TODO: Install certificate process
  11672. */
  11673. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11674. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11675. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11676. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11677. sendInstallCertificateConfirmation(uuid);
  11678. }
  11679. json_object_put(InstallCertificate);
  11680. return result;
  11681. }
  11682. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11683. {
  11684. mtrace();
  11685. int result = PASS;
  11686. json_object *SignedUpdateFirmware;
  11687. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11688. SignedUpdateFirmware = json_tokener_parse(payload);
  11689. if(!is_error(SignedUpdateFirmware))
  11690. {
  11691. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11692. {
  11693. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11694. }
  11695. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11696. {
  11697. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11698. }
  11699. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11700. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11701. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11702. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11703. {
  11704. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11705. }
  11706. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11707. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11708. }
  11709. json_object_put(SignedUpdateFirmware);
  11710. /*
  11711. * TODO: Upgrade firmware process
  11712. */
  11713. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11714. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11715. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11716. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11717. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11718. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11719. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11720. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11721. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11722. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11723. sendInstallCertificateConfirmation(uuid);
  11724. return result;
  11725. }
  11726. int handleUnknownRequest(char *uuid, char *payload)
  11727. {
  11728. mtrace();
  11729. int result = PASS;
  11730. DEBUG_INFO("handleUnknownRequest...\n");
  11731. sendUnknownConfirmation(uuid);
  11732. result = PASS;
  11733. return result;
  11734. }
  11735. //==========================================
  11736. // Handle server response routine
  11737. //==========================================
  11738. void handleAuthorizeResponse(char *payload, int gun_index)
  11739. {
  11740. mtrace();
  11741. char expiryDatestr[30]={0};
  11742. char parentIdTagstr[20]={0};
  11743. char statusstr[20]={0};
  11744. int expiryDateISNULL=FALSE;
  11745. int parentIdTagISNULL=FALSE;
  11746. DEBUG_INFO("handleAuthorizeResponse...\n");
  11747. json_object *Authorize;
  11748. Authorize = json_tokener_parse(payload);
  11749. if(!is_error(Authorize))
  11750. {
  11751. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11752. {
  11753. // Required data
  11754. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11755. // Optional data
  11756. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11757. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11758. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11759. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11760. }
  11761. }
  11762. json_object_put(Authorize);
  11763. if(expiryDateISNULL == FALSE)
  11764. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11765. if(parentIdTagISNULL == FALSE)
  11766. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11767. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11768. //Update idTag information to authorization cache if supproted
  11769. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11770. {
  11771. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11772. }
  11773. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11774. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11775. authorizeRetryTimes = 0;
  11776. }
  11777. void handleBootNotificationResponse(char *payload, int gun_index)
  11778. {
  11779. mtrace();
  11780. char statusStr[12]={0};
  11781. char currentTimeStr[30]={0};
  11782. int intervalInt = 0;
  11783. DEBUG_INFO("handleBootNotificationResponse...\n");
  11784. json_object *BootNotification;
  11785. BootNotification = json_tokener_parse(payload);
  11786. if(!is_error(BootNotification))
  11787. {
  11788. // Required data
  11789. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11790. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11791. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11792. }
  11793. json_object_put(BootNotification);
  11794. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11795. BootNotificationInterval = intervalInt;
  11796. HeartBeatWaitTime = intervalInt;
  11797. //write back to ShmOCPP16DataPH->BootNotification
  11798. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11799. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11800. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11801. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11802. {
  11803. server_sign = TRUE;
  11804. server_pending =FALSE;
  11805. }
  11806. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11807. {
  11808. server_pending = TRUE;
  11809. }
  11810. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11811. srand(time(NULL));
  11812. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11813. SetOcppConnStatus(TRUE);
  11814. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11815. }
  11816. void handleDataTransferResponse(char *payload, int gun_index)
  11817. {
  11818. char sstr[160]={0};//sstr[200]={ 0 };
  11819. int c = 0;
  11820. char *loc;
  11821. DEBUG_INFO("handleDataTransferResponse ...\n");
  11822. loc = strstr(payload, "status");
  11823. c = 0;
  11824. while (loc[3+strlen("status")+c] != '\"')
  11825. {
  11826. sstr[c] = loc[3+strlen("status")+c];
  11827. c++;
  11828. }
  11829. sstr[c] = '\0';
  11830. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11831. }
  11832. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11833. {
  11834. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11835. //struct json_object *obj;
  11836. // obj = json_tokener_parse(payload);
  11837. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11838. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11839. //No fields are defined.
  11840. }
  11841. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11842. {
  11843. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11844. //struct json_object *obj;
  11845. // obj = json_tokener_parse(payload);
  11846. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11847. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11848. //No fields are defined.
  11849. }
  11850. void handleHeartbeatResponse(char *payload, int gun_index)
  11851. {
  11852. mtrace();
  11853. DEBUG_INFO("handleHeartbeatResponse...\n");
  11854. json_object *Heartbeat;
  11855. Heartbeat = json_tokener_parse(payload);
  11856. if(!is_error(Heartbeat))
  11857. {
  11858. // Required data
  11859. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11860. }
  11861. json_object_put(Heartbeat);
  11862. if(FirstHeartBeat == 0)
  11863. {
  11864. FirstHeartBeat = 1;
  11865. DEBUG_INFO("FirstHeartBeat \n");
  11866. }
  11867. HeartBeatWithNOResponse = 0;
  11868. clientTime.Heartbeat=time((time_t*)NULL);
  11869. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11870. }
  11871. void handleMeterValuesResponse(char *payload, int gun_index)
  11872. {
  11873. mtrace();
  11874. DEBUG_INFO("handleMeterValuesResponse...\n");
  11875. }
  11876. void handleStartTransactionResponse(char *payload, int gun_index)
  11877. {
  11878. mtrace();
  11879. //int transactionIdInt = 0;
  11880. FILE *outfile;
  11881. char data[100]={0};
  11882. DEBUG_INFO("handleStartTransactionResponse...\n");
  11883. json_object *StartTransaction;
  11884. StartTransaction = json_tokener_parse(payload);
  11885. if(!is_error(StartTransaction))
  11886. {
  11887. // Required data
  11888. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11889. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11890. // Optional data
  11891. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11892. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11893. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11894. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11895. }
  11896. json_object_put(StartTransaction);
  11897. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11898. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11899. //-----------Start : write to the Queue TransactionId file -----------------//
  11900. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11901. {}
  11902. else
  11903. {
  11904. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11905. if(log == NULL)
  11906. {
  11907. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11908. return ;
  11909. }
  11910. else
  11911. {
  11912. fclose(log);
  11913. }
  11914. }
  11915. // open file for writing
  11916. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11917. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11918. {
  11919. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11920. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11921. fputs(data, outfile);
  11922. fclose (outfile);
  11923. }
  11924. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11925. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11926. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11927. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11928. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11929. }
  11930. void handleStatusNotificationResponse(char *payload, int gun_index)
  11931. {
  11932. mtrace();
  11933. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11934. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11935. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11936. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11937. }
  11938. void handleStopTransactionnResponse(char *payload, int gun_index)
  11939. {
  11940. mtrace();
  11941. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11942. json_object *StopTransaction;
  11943. StopTransaction = json_tokener_parse(payload);
  11944. if(!is_error(StopTransaction))
  11945. {
  11946. // Optional data
  11947. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11948. {
  11949. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11950. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11951. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11952. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11953. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11954. }
  11955. }
  11956. json_object_put(StopTransaction);
  11957. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11958. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11959. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11960. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11961. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11962. }
  11963. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11964. {
  11965. mtrace();
  11966. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11967. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11968. }
  11969. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11970. {
  11971. mtrace();
  11972. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11973. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11974. }
  11975. void handleSignCertificateResponse(char *payload, int gun_index)
  11976. {
  11977. mtrace();
  11978. DEBUG_INFO("handleSignCertificateResponse...\n");
  11979. json_object *SignCertificate;
  11980. SignCertificate = json_tokener_parse(payload);
  11981. if(!is_error(SignCertificate))
  11982. {
  11983. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11984. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11985. }
  11986. json_object_put(SignCertificate);
  11987. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11988. }
  11989. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11990. {
  11991. mtrace();
  11992. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11993. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11994. }
  11995. //==========================================
  11996. // Handle Error routine
  11997. //==========================================
  11998. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11999. {
  12000. mtrace();
  12001. #ifdef SystemLogMessage
  12002. DEBUG_INFO("errorCode: %s\n", errorCode);
  12003. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  12004. DEBUG_INFO("errorDetails: %s\n", payload);
  12005. #endif
  12006. }
  12007. //===============================================
  12008. // Common routine
  12009. //===============================================
  12010. int initialConfigurationTable(void)
  12011. {
  12012. //clock_t start_t, end_t, total_t;
  12013. FILE *fp;
  12014. FILE *outfile;
  12015. char str[512]={0};
  12016. char sstr[256]={0};
  12017. int c = 0;
  12018. char *loc;
  12019. int confVersion = 8;
  12020. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  12021. //start_t = clock();
  12022. //printf("Starting of the program, start_t = %ld\n", start_t);
  12023. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  12024. // Check configuration file size is correct
  12025. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  12026. {
  12027. struct stat st;
  12028. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  12029. if(st.st_size < 3100)
  12030. {
  12031. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12032. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12033. }
  12034. }
  12035. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12036. {
  12037. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12038. if(outfile == NULL)
  12039. {
  12040. DEBUG_INFO("Error opening file\n");
  12041. return FALSE;
  12042. }
  12043. /*Core Profile*/
  12044. //AllowOfflineTxForUnknownId
  12045. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12046. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12047. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12048. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12049. //AuthorizationCacheEnabled
  12050. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12052. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12054. //AuthorizeRemoteTxRequests
  12055. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12058. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12059. //BlinkRepeat
  12060. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12062. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12063. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12064. //ClockAlignedDataInterval
  12065. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12067. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12068. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12069. //ConnectionTimeOut
  12070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12074. //GetConfigurationMaxKeys
  12075. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12076. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12077. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12079. // HeartbeatInterval
  12080. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12081. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12082. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12084. // LightIntensity
  12085. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12089. // LocalAuthorizeOffline
  12090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12094. // LocalPreAuthorize
  12095. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12096. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12097. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12099. // MaxEnergyOnInvalidId
  12100. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12102. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12104. // MeterValuesAlignedData
  12105. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12107. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12109. else
  12110. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12112. // MeterValuesAlignedDataMaxLength
  12113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12115. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12116. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12117. else
  12118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12119. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12120. // MeterValuesSampledData
  12121. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12124. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC,Current.Offered,Power.Offered" );
  12125. else
  12126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12128. // MeterValuesSampledDataMaxLength
  12129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12131. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12132. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12133. else
  12134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12136. // MeterValueSampleInterval
  12137. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12138. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12139. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12141. // MinimumStatusDuration
  12142. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12144. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12145. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12147. // NumberOfConnectors
  12148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12151. {
  12152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12153. }
  12154. else
  12155. {
  12156. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12157. }
  12158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12159. // ResetRetries
  12160. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12164. // ConnectorPhaseRotation
  12165. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12166. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12168. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12169. // ConnectorPhaseRotationMaxLength
  12170. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12172. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12174. // StopTransactionOnEVSideDisconnect
  12175. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12179. // StopTransactionOnInvalidId
  12180. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12181. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12184. // StopTxnAlignedData
  12185. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12187. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12189. // StopTxnAlignedDataMaxLength
  12190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12194. // StopTxnSampledData
  12195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12197. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12199. else
  12200. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12202. // StopTxnSampledDataMaxLength
  12203. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12206. {
  12207. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12208. }
  12209. else
  12210. {
  12211. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12212. }
  12213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12214. // SupportedFeatureProfiles
  12215. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12216. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12218. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12219. // SupportedFeatureProfilesMaxLength
  12220. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12221. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12223. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12224. // TransactionMessageAttempts
  12225. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12228. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12230. // TransactionMessageRetryInterval
  12231. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12233. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12234. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12236. // UnlockConnectorOnEVSideDisconnect
  12237. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12238. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12241. // WebSocketPingInterval
  12242. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12243. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12244. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12246. // QueueOffLineMeterValues
  12247. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12249. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12251. // AuthorizationKey
  12252. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12253. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  12255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12256. // SecurityProfile
  12257. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12258. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12259. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12261. // DefaultPrice
  12262. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12263. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12264. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12265. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12266. // CustomDisplayCostAndPrice
  12267. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12271. // CustomIdleFeeAfterStop
  12272. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12273. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12274. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12276. // Configuration Version
  12277. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12278. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12279. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12281. //* Local Auth List Management Profile*/
  12282. #if 0
  12283. //For OCTT Test Case
  12284. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12285. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12286. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12287. #endif
  12288. #if 1
  12289. //LocalAuthListEnabled
  12290. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12294. #endif
  12295. //LocalAuthListMaxLength
  12296. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12300. //SendLocalListMaxLength
  12301. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12305. //ReserveConnectorZeroSupported
  12306. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12308. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12310. //* Smart Charging Profile */
  12311. //ChargeProfileMaxStackLevel
  12312. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12313. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12314. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12316. // ChargingScheduleAllowedChargingRateUnit
  12317. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12321. // ChargingScheduleMaxPeriods
  12322. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12323. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12324. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12326. // ConnectorSwitch3to1PhaseSupported
  12327. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12328. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12329. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12331. // MaxChargingProfilesInstalled
  12332. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12334. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12336. fclose(outfile);
  12337. }
  12338. else
  12339. {
  12340. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  12341. char keystr[60]={0};
  12342. char readonlystr[10]={0};
  12343. char valuestr[256]={0};
  12344. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  12345. if(fp == NULL) {
  12346. DEBUG_INFO("Error opening file");
  12347. return FALSE;
  12348. }
  12349. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12350. {
  12351. //DEBUG_INFO("Get Configuration \n");
  12352. if(strlen(str) > 0)
  12353. {
  12354. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12355. //*************************key*********************************/
  12356. if(strstr(str, "key") != NULL)
  12357. {
  12358. loc = strstr(str, "key");
  12359. c = 0;
  12360. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12361. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12362. {
  12363. sstr[c] = loc[strlen("key")+3+c];
  12364. c++;
  12365. }
  12366. sstr[c] = '\0';
  12367. strcpy(keystr,sstr);
  12368. }
  12369. //*************************readonly*********************************/
  12370. if(strstr(str, "readonly") != NULL)
  12371. {
  12372. loc = strstr(str, "readonly");
  12373. c = 0;
  12374. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12375. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12376. {
  12377. sstr[c] = loc[strlen("readonly")+2+c];
  12378. c++;
  12379. }
  12380. sstr[c] = '\0';
  12381. strcpy(readonlystr,sstr);
  12382. }
  12383. //*************************value*********************************/
  12384. if(strstr(str, "value") != NULL)
  12385. {
  12386. loc = strstr(str, "value");
  12387. c = 0;
  12388. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12389. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12390. {
  12391. sstr[c] = loc[strlen("value")+3+c];
  12392. c++;
  12393. }
  12394. sstr[c] = '\0';
  12395. strcpy(valuestr,sstr);
  12396. }
  12397. // DEBUG_INFO("keystr=%s\n",keystr);
  12398. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12399. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12400. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12401. {
  12402. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12403. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12404. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12405. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12406. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12407. }
  12408. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12409. {
  12410. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12413. }
  12414. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12415. {
  12416. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12417. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12418. }
  12419. if(strcmp(keystr, "BlinkRepeat") == 0)
  12420. {
  12421. //Charger.BlinkRepeat = Integer.parseInt(value);
  12422. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12423. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12424. }
  12425. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12426. {
  12427. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12428. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12429. }
  12430. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12431. {
  12432. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12433. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12434. }
  12435. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12436. {
  12437. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12438. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12439. }
  12440. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12441. {
  12442. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12443. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12444. HeartBeatWaitTime = atoi(valuestr);
  12445. }
  12446. if(strcmp(keystr, "LightIntensity") == 0)
  12447. {
  12448. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12449. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12450. }
  12451. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12452. {
  12453. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12454. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12455. }
  12456. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12457. {
  12458. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12459. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12460. }
  12461. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12462. {
  12463. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12464. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12465. }
  12466. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12467. {
  12468. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12470. }
  12471. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12472. {
  12473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12475. }
  12476. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12477. {
  12478. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12479. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12480. }
  12481. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12482. {
  12483. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12484. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12485. }
  12486. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12487. {
  12488. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12490. }
  12491. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12492. {
  12493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12495. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12496. }
  12497. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12498. {
  12499. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12501. }
  12502. if(strcmp(keystr, "ResetRetries") == 0)
  12503. {
  12504. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12505. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12506. }
  12507. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12508. {
  12509. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12510. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12511. }
  12512. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12513. {
  12514. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12515. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12516. }
  12517. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12518. {
  12519. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12520. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12521. }
  12522. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12523. {
  12524. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12525. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12526. }
  12527. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12528. {
  12529. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12530. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12531. }
  12532. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12533. {
  12534. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12536. }
  12537. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12538. {
  12539. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12540. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12541. }
  12542. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12543. {
  12544. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12545. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12546. }
  12547. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12548. {
  12549. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12550. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12551. }
  12552. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12553. {
  12554. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12555. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12556. }
  12557. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12558. {
  12559. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12560. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12561. TransactionMessageAttemptsValue = atoi(valuestr);
  12562. }
  12563. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12564. {
  12565. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12566. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12567. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12568. }
  12569. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12570. {
  12571. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12572. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12573. }
  12574. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12575. {
  12576. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12577. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12578. }
  12579. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12580. {
  12581. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12582. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12583. }
  12584. if(strcmp(keystr, "AuthorizationKey") == 0)
  12585. {
  12586. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12587. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12588. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12589. }
  12590. if(strcmp(keystr, "SecurityProfile") == 0)
  12591. {
  12592. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12593. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  12594. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12595. }
  12596. if(strcmp(keystr, "DefaultPrice") == 0)
  12597. {
  12598. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12599. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12600. }
  12601. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12602. {
  12603. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12604. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12605. }
  12606. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12607. {
  12608. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12609. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12610. }
  12611. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12612. {
  12613. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12614. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12615. }
  12616. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12617. {
  12618. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12619. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12620. }
  12621. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12622. {
  12623. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12624. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12625. }
  12626. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12627. {
  12628. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12629. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12630. }
  12631. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12632. {
  12633. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12634. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12635. }
  12636. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12637. {
  12638. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12639. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12640. }
  12641. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12642. {
  12643. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12644. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12645. }
  12646. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12647. {
  12648. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12649. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12650. }
  12651. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12652. {
  12653. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12654. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12655. }
  12656. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12657. {
  12658. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12659. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12660. }
  12661. }
  12662. }
  12663. fclose(fp);
  12664. }
  12665. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12666. {
  12667. return PASS;
  12668. }
  12669. else
  12670. {
  12671. return FAIL;
  12672. }
  12673. }
  12674. void StoreConfigurationTable(void)
  12675. {
  12676. FILE *outfile;
  12677. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12678. if(outfile == NULL)
  12679. {
  12680. DEBUG_INFO("Error opening file");
  12681. return ;
  12682. }
  12683. /*Core Profile*/
  12684. //AllowOfflineTxForUnknownId
  12685. /*
  12686. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12687. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12688. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12689. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12690. */
  12691. //DEBUG_INFO("data=%s\n",data);
  12692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12693. //AuthorizationCacheEnabled
  12694. /*
  12695. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12696. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12697. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12698. */
  12699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12700. //AuthorizeRemoteTxRequests
  12701. /*
  12702. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12703. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12704. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12705. */
  12706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12707. //BlinkRepeat
  12708. /*
  12709. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12710. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12711. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12712. */
  12713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12714. //ClockAlignedDataInterval
  12715. /*
  12716. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12717. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12718. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12719. */
  12720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12721. //ConnectionTimeOut
  12722. /*
  12723. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12724. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12725. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12726. */
  12727. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12728. //GetConfigurationMaxKeys
  12729. /*
  12730. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12731. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12732. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12733. */
  12734. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12735. // HeartbeatInterval
  12736. /*
  12737. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12738. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12739. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12740. */
  12741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12742. // LightIntensity
  12743. /*
  12744. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12745. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12746. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12747. */
  12748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12749. // LocalAuthorizeOffline
  12750. /*
  12751. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12752. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12753. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12754. */
  12755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12756. // LocalPreAuthorize
  12757. /*
  12758. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12759. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12760. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12761. */
  12762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12763. // MaxEnergyOnInvalidId
  12764. /*
  12765. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12766. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12767. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12768. */
  12769. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12770. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12771. // MeterValuesAlignedData
  12772. /*
  12773. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12774. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12775. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12776. */
  12777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12778. // MeterValuesAlignedDataMaxLength
  12779. /*
  12780. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12781. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12782. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12783. */
  12784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12785. // MeterValuesSampledData
  12786. /*
  12787. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12788. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12789. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12790. */
  12791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12792. // MeterValuesSampledDataMaxLength
  12793. /*
  12794. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12795. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12796. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12797. */
  12798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12799. // MeterValueSampleInterval
  12800. /*
  12801. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12802. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12803. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12804. */
  12805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12806. // MinimumStatusDuration
  12807. /*
  12808. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12809. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12810. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12811. */
  12812. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12813. // NumberOfConnectors
  12814. /*
  12815. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12816. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12817. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12818. {
  12819. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12820. }
  12821. else
  12822. {
  12823. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12824. }
  12825. */
  12826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12827. // ResetRetries
  12828. /*
  12829. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12830. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12831. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12832. */
  12833. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12834. // ConnectorPhaseRotation
  12835. /*
  12836. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12837. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12838. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12839. */
  12840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12841. // ConnectorPhaseRotationMaxLength
  12842. /*
  12843. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12844. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12845. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12846. */
  12847. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12848. // StopTransactionOnEVSideDisconnect
  12849. /*
  12850. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12851. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12852. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12853. */
  12854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12855. // StopTransactionOnInvalidId
  12856. /*
  12857. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12858. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12859. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12860. */
  12861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12862. // StopTxnAlignedData
  12863. /*
  12864. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12865. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12866. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12867. */
  12868. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12869. // StopTxnAlignedDataMaxLength
  12870. /*
  12871. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12872. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12873. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12874. */
  12875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12876. // StopTxnSampledData
  12877. /*
  12878. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12879. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12880. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12881. */
  12882. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12883. // StopTxnSampledDataMaxLength
  12884. /*
  12885. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12886. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12887. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12888. */
  12889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12890. // SupportedFeatureProfiles
  12891. /*
  12892. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12893. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12894. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12895. */
  12896. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12897. // SupportedFeatureProfilesMaxLength
  12898. /*
  12899. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12900. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12901. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12902. */
  12903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12904. // TransactionMessageAttempts
  12905. /*
  12906. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12907. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12908. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12909. */
  12910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12911. // TransactionMessageRetryInterval
  12912. /*
  12913. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12914. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12915. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12916. */
  12917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12918. // UnlockConnectorOnEVSideDisconnect
  12919. /*
  12920. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12921. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12922. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12923. */
  12924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12925. // WebSocketPingInterval
  12926. /*
  12927. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12930. */
  12931. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12932. // QueueOffLineMeterValues
  12933. /*
  12934. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  12935. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  12937. */
  12938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12939. // AuthorizationKey
  12940. /*
  12941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12942. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12944. */
  12945. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12946. // SecurityProfile
  12947. /*
  12948. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12949. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12951. */
  12952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12953. // DefaultPrice
  12954. /*
  12955. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12956. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12958. */
  12959. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12960. // CustomDisplayCostAndPrice
  12961. /*
  12962. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12963. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12965. */
  12966. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12967. // CustomIdleFeeAfterStop
  12968. /*
  12969. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12970. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12972. */
  12973. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12974. // ConfigurationVersion
  12975. /*
  12976. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12977. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12979. */
  12980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12981. //* Local Auth List Management Profile*/
  12982. //LocalAuthListEnabled
  12983. /*
  12984. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12987. */
  12988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12989. //LocalAuthListMaxLength
  12990. /*
  12991. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12993. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12994. */
  12995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12996. //SendLocalListMaxLength
  12997. /*
  12998. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  13000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  13001. */
  13002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  13003. //ReserveConnectorZeroSupported
  13004. /*
  13005. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  13006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  13007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  13008. */
  13009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13010. //* Smart Charging Profile */
  13011. //ChargeProfileMaxStackLevel
  13012. /*
  13013. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  13014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  13015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  13016. */
  13017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13018. // ChargingScheduleAllowedChargingRateUnit
  13019. /*
  13020. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  13021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  13022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  13023. */
  13024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13025. // ChargingScheduleMaxPeriods
  13026. /*
  13027. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  13028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  13029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  13030. */
  13031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13032. // ConnectorSwitch3to1PhaseSupported
  13033. /*
  13034. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13037. */
  13038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13039. // MaxChargingProfilesInstalled
  13040. /*
  13041. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13044. */
  13045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13046. fclose(outfile);
  13047. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13048. }
  13049. void getKeyValue(char *keyReq)
  13050. {
  13051. int isEmpty = FALSE;
  13052. int isKnowKey = FALSE;
  13053. DEBUG_INFO("keyReq = %s\n", keyReq);
  13054. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13055. isEmpty = TRUE;
  13056. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13057. {
  13058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13060. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13061. {
  13062. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13063. }
  13064. else
  13065. {
  13066. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13067. }
  13068. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13069. isKnowKey = TRUE;
  13070. }
  13071. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13072. {
  13073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13074. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13075. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13076. {
  13077. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13078. }
  13079. else
  13080. {
  13081. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13082. }
  13083. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13084. isKnowKey = TRUE;
  13085. }
  13086. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13087. {
  13088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13090. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13091. {
  13092. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13093. }
  13094. else
  13095. {
  13096. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13097. }
  13098. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13099. isKnowKey = TRUE;
  13100. }
  13101. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13102. {
  13103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13104. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13105. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13106. {
  13107. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13108. }
  13109. else
  13110. {
  13111. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13112. }
  13113. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13114. isKnowKey = TRUE;
  13115. }
  13116. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13117. {
  13118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13119. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13120. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13121. {
  13122. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13123. }
  13124. else
  13125. {
  13126. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13127. }
  13128. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13129. isKnowKey = TRUE;
  13130. }
  13131. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13132. {
  13133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13134. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13135. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13136. {
  13137. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13138. }
  13139. else
  13140. {
  13141. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13142. }
  13143. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13144. isKnowKey = TRUE;
  13145. }
  13146. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13147. {
  13148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13149. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13150. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13151. {
  13152. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13153. }
  13154. else
  13155. {
  13156. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13157. }
  13158. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13159. isKnowKey = TRUE;
  13160. }
  13161. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13162. {
  13163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13164. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13165. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13166. {
  13167. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13168. }
  13169. else
  13170. {
  13171. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13172. }
  13173. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13174. isKnowKey = TRUE;
  13175. }
  13176. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13177. {
  13178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13179. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13180. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13181. {
  13182. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13183. }
  13184. else
  13185. {
  13186. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13187. }
  13188. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13189. isKnowKey = TRUE;
  13190. }
  13191. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13192. {
  13193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13194. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13195. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13196. {
  13197. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13198. }
  13199. else
  13200. {
  13201. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13202. }
  13203. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13204. isKnowKey = TRUE;
  13205. }
  13206. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13207. {
  13208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13209. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13210. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13211. {
  13212. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13213. }
  13214. else
  13215. {
  13216. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13217. }
  13218. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13219. isKnowKey = TRUE;
  13220. }
  13221. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13222. {
  13223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13224. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13225. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13226. {
  13227. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13228. }
  13229. else
  13230. {
  13231. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13232. }
  13233. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13234. isKnowKey = TRUE;
  13235. }
  13236. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13237. {
  13238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13239. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13240. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13241. {
  13242. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13243. }
  13244. else
  13245. {
  13246. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13247. }
  13248. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13249. isKnowKey = TRUE;
  13250. }
  13251. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13252. {
  13253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13254. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13255. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13256. {
  13257. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13258. }
  13259. else
  13260. {
  13261. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13262. }
  13263. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13264. isKnowKey = TRUE;
  13265. }
  13266. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13267. {
  13268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13269. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13270. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13271. {
  13272. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13273. }
  13274. else
  13275. {
  13276. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13277. }
  13278. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13279. isKnowKey = TRUE;
  13280. }
  13281. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13282. {
  13283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13284. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13285. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13286. {
  13287. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13288. }
  13289. else
  13290. {
  13291. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13292. }
  13293. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13294. isKnowKey = TRUE;
  13295. }
  13296. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13297. {
  13298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13300. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13301. {
  13302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13303. }
  13304. else
  13305. {
  13306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13307. }
  13308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13309. isKnowKey = TRUE;
  13310. }
  13311. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13312. {
  13313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13315. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13316. {
  13317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13318. }
  13319. else
  13320. {
  13321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13322. }
  13323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  13324. isKnowKey = TRUE;
  13325. }
  13326. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13327. {
  13328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13330. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13331. {
  13332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13333. }
  13334. else
  13335. {
  13336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13337. }
  13338. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13339. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13340. isKnowKey = TRUE;
  13341. }
  13342. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13343. {
  13344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13345. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13346. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13347. {
  13348. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13349. }
  13350. else
  13351. {
  13352. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13353. }
  13354. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13355. isKnowKey = TRUE;
  13356. }
  13357. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13358. {
  13359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13360. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13361. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13362. {
  13363. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13364. }
  13365. else
  13366. {
  13367. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13368. }
  13369. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13370. isKnowKey = TRUE;
  13371. }
  13372. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13373. {
  13374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13375. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13377. {
  13378. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13379. }
  13380. else
  13381. {
  13382. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13383. }
  13384. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13385. isKnowKey = TRUE;
  13386. }
  13387. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13388. {
  13389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13390. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13391. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13392. {
  13393. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13394. }
  13395. else
  13396. {
  13397. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13398. }
  13399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13400. isKnowKey = TRUE;
  13401. }
  13402. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13403. {
  13404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13405. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13406. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13407. {
  13408. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13409. }
  13410. else
  13411. {
  13412. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13413. }
  13414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13415. isKnowKey = TRUE;
  13416. }
  13417. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13418. {
  13419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13420. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13421. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13422. {
  13423. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13424. }
  13425. else
  13426. {
  13427. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13428. }
  13429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13430. isKnowKey = TRUE;
  13431. }
  13432. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13433. {
  13434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13435. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13436. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13437. {
  13438. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13439. }
  13440. else
  13441. {
  13442. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13443. }
  13444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13445. isKnowKey = TRUE;
  13446. }
  13447. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13448. {
  13449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13450. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13451. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13452. {
  13453. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13454. }
  13455. else
  13456. {
  13457. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13458. }
  13459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13460. isKnowKey = TRUE;
  13461. }
  13462. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13463. {
  13464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13465. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13466. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13467. {
  13468. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13469. }
  13470. else
  13471. {
  13472. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13473. }
  13474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13475. isKnowKey = TRUE;
  13476. }
  13477. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13478. {
  13479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13480. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13481. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13482. {
  13483. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13484. }
  13485. else
  13486. {
  13487. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13488. }
  13489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13490. isKnowKey = TRUE;
  13491. }
  13492. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13493. {
  13494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13495. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13496. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13497. {
  13498. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13499. }
  13500. else
  13501. {
  13502. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13503. }
  13504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13505. isKnowKey = TRUE;
  13506. }
  13507. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13508. {
  13509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13510. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13511. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13512. {
  13513. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13514. }
  13515. else
  13516. {
  13517. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13518. }
  13519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13520. isKnowKey = TRUE;
  13521. }
  13522. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13523. {
  13524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13525. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13526. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13527. {
  13528. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13529. }
  13530. else
  13531. {
  13532. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13533. }
  13534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13535. isKnowKey = TRUE;
  13536. }
  13537. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13538. {
  13539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13540. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13541. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13542. {
  13543. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13544. }
  13545. else
  13546. {
  13547. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13548. }
  13549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13550. isKnowKey = TRUE;
  13551. }
  13552. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13553. {
  13554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13557. {
  13558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13559. }
  13560. else
  13561. {
  13562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13563. }
  13564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13565. isKnowKey = TRUE;
  13566. }
  13567. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13568. {
  13569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13571. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13572. {
  13573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13574. }
  13575. else
  13576. {
  13577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13578. }
  13579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13580. isKnowKey = TRUE;
  13581. }
  13582. /*
  13583. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13584. {
  13585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13587. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13588. {
  13589. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13590. }
  13591. else
  13592. {
  13593. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13594. }
  13595. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13596. isKnowKey = TRUE;
  13597. }*/
  13598. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13599. {
  13600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13603. {
  13604. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13605. }
  13606. else
  13607. {
  13608. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13609. }
  13610. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13611. isKnowKey = TRUE;
  13612. }
  13613. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13614. {
  13615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13617. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13618. {
  13619. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13620. }
  13621. else
  13622. {
  13623. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13624. }
  13625. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13626. isKnowKey = TRUE;
  13627. }
  13628. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13629. {
  13630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13632. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13633. {
  13634. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13635. }
  13636. else
  13637. {
  13638. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13639. }
  13640. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13641. isKnowKey = TRUE;
  13642. }
  13643. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13644. {
  13645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13647. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13648. {
  13649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13650. }
  13651. else
  13652. {
  13653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13654. }
  13655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13656. isKnowKey = TRUE;
  13657. }
  13658. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13659. {
  13660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13662. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13663. {
  13664. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13665. }
  13666. else
  13667. {
  13668. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13669. }
  13670. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13671. isKnowKey = TRUE;
  13672. }
  13673. #if 1
  13674. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13675. {
  13676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13678. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13679. {
  13680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13681. }
  13682. else
  13683. {
  13684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13685. }
  13686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13687. isKnowKey = TRUE;
  13688. }
  13689. #endif
  13690. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13691. {
  13692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13694. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13695. {
  13696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13697. }
  13698. else
  13699. {
  13700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13701. }
  13702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13703. isKnowKey = TRUE;
  13704. }
  13705. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13706. {
  13707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13709. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13710. {
  13711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13712. }
  13713. else
  13714. {
  13715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13716. }
  13717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13718. isKnowKey = TRUE;
  13719. }
  13720. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13721. {
  13722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13724. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13725. {
  13726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13727. }
  13728. else
  13729. {
  13730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13731. }
  13732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13733. isKnowKey = TRUE;
  13734. }
  13735. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13736. {
  13737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13739. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13740. {
  13741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13742. }
  13743. else
  13744. {
  13745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13746. }
  13747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13748. isKnowKey = TRUE;
  13749. }
  13750. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13751. {
  13752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13754. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13755. {
  13756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13757. }
  13758. else
  13759. {
  13760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13761. }
  13762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13763. isKnowKey = TRUE;
  13764. }
  13765. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13766. {
  13767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13769. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13770. {
  13771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13772. }
  13773. else
  13774. {
  13775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13776. }
  13777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13778. isKnowKey = TRUE;
  13779. }
  13780. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13781. {
  13782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13784. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13785. {
  13786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13787. }
  13788. else
  13789. {
  13790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13791. }
  13792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13793. isKnowKey = TRUE;
  13794. }
  13795. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13796. {
  13797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13799. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13800. {
  13801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13802. }
  13803. else
  13804. {
  13805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13806. }
  13807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13808. isKnowKey = TRUE;
  13809. }
  13810. //=========================================================
  13811. if(!isEmpty && !isKnowKey)
  13812. {
  13813. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13814. strcpy(unknownkey[UnknownKeynum], keyReq);
  13815. UnknownKeynum = UnknownKeynum + 1;
  13816. }
  13817. }
  13818. void processUnkownKey(void)
  13819. {
  13820. DEBUG_INFO("processUnkownKey...\n");
  13821. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13822. for(int index=0; index < UnknownKeynum; index++)
  13823. {
  13824. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13825. {
  13826. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13827. }
  13828. }
  13829. }
  13830. int setKeyValue(char *key, char *value)
  13831. {
  13832. int isSuccess = NotSupported;
  13833. int check_ascii=0;
  13834. char str[256]={0};
  13835. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13836. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13837. {
  13838. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13839. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13840. {
  13841. strcpy(str, (const char*)value);
  13842. for(int i = 0; str[i]; i++){
  13843. str[i] = tolower(str[i]);
  13844. }
  13845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13846. isSuccess = ConfigurationStatus_Accepted;
  13847. }
  13848. else
  13849. {
  13850. isSuccess = ConfigurationStatus_Rejected;
  13851. }
  13852. }
  13853. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13854. {
  13855. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13856. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13857. {
  13858. strcpy(str, (const char*)value);
  13859. for(int i = 0; str[i]; i++){
  13860. str[i] = tolower(str[i]);
  13861. }
  13862. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13863. isSuccess = ConfigurationStatus_Accepted;
  13864. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13865. }
  13866. else
  13867. {
  13868. isSuccess = ConfigurationStatus_Rejected;
  13869. }
  13870. }
  13871. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13872. {
  13873. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13874. {
  13875. strcpy(str, (const char*)value);
  13876. for(int i = 0; str[i]; i++)
  13877. {
  13878. str[i] = tolower(str[i]);
  13879. }
  13880. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13881. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13882. isSuccess = ConfigurationStatus_Accepted;
  13883. }
  13884. else
  13885. {
  13886. isSuccess = ConfigurationStatus_Rejected;
  13887. }
  13888. }
  13889. if(strcmp(key, "BlinkRepeat") == 0)
  13890. {
  13891. //Charger.BlinkRepeat = Integer.parseInt(value);
  13892. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13893. {
  13894. check_ascii = value[0];
  13895. if( (check_ascii < 48) || (check_ascii > 57) )
  13896. {
  13897. isSuccess = ConfigurationStatus_Rejected;
  13898. }
  13899. else
  13900. {
  13901. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13902. isSuccess = ConfigurationStatus_Accepted;
  13903. }
  13904. }
  13905. else
  13906. {
  13907. isSuccess = ConfigurationStatus_Rejected;
  13908. }
  13909. }
  13910. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13911. {
  13912. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13913. {
  13914. check_ascii = value[0];
  13915. if( (check_ascii < 48) || (check_ascii > 57) )
  13916. {
  13917. isSuccess = ConfigurationStatus_Rejected;
  13918. }
  13919. else
  13920. {
  13921. if((atoi(value) == 0) || (atoi(value) >= 10))
  13922. {
  13923. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13924. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13925. isSuccess = ConfigurationStatus_Accepted;
  13926. }
  13927. else
  13928. isSuccess = ConfigurationStatus_Rejected;
  13929. }
  13930. }
  13931. else
  13932. {
  13933. isSuccess = ConfigurationStatus_Rejected;
  13934. }
  13935. }
  13936. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13937. {
  13938. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13939. {
  13940. check_ascii = value[0];
  13941. if( (check_ascii < 48) || (check_ascii > 57) )
  13942. {
  13943. isSuccess = ConfigurationStatus_Rejected;
  13944. }
  13945. else
  13946. {
  13947. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13948. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13949. isSuccess = ConfigurationStatus_Accepted;
  13950. }
  13951. }
  13952. else
  13953. {
  13954. isSuccess = ConfigurationStatus_Rejected;
  13955. }
  13956. }
  13957. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13958. {
  13959. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13960. {
  13961. check_ascii = value[0];
  13962. if( (check_ascii < 48) || (check_ascii > 57) )
  13963. {
  13964. isSuccess = ConfigurationStatus_Rejected;
  13965. }
  13966. else
  13967. {
  13968. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13969. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13970. isSuccess = ConfigurationStatus_Accepted;
  13971. }
  13972. }
  13973. else
  13974. {
  13975. isSuccess = ConfigurationStatus_Rejected;
  13976. }
  13977. }
  13978. if(strcmp(key, "HeartbeatInterval") == 0)
  13979. {
  13980. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13981. {
  13982. check_ascii = value[0];
  13983. if( (check_ascii < 48) || (check_ascii > 57) )
  13984. {
  13985. isSuccess = ConfigurationStatus_Rejected;
  13986. }
  13987. else
  13988. {
  13989. if((atoi(value) == 0) || (atoi(value) >= 10))
  13990. {
  13991. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13992. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13993. HeartBeatWaitTime = atoi(value);
  13994. isSuccess = ConfigurationStatus_Accepted;
  13995. }
  13996. else
  13997. {
  13998. isSuccess = ConfigurationStatus_Rejected;
  13999. }
  14000. }
  14001. }
  14002. else
  14003. {
  14004. isSuccess = ConfigurationStatus_Rejected;
  14005. }
  14006. }
  14007. if(strcmp(key, "LightIntensity") == 0)
  14008. {
  14009. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  14010. {
  14011. check_ascii = value[0];
  14012. if( (check_ascii < 48) || (check_ascii > 57) )
  14013. {
  14014. isSuccess = ConfigurationStatus_Rejected;
  14015. }
  14016. else
  14017. {
  14018. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  14019. isSuccess = ConfigurationStatus_Accepted;
  14020. }
  14021. }
  14022. else
  14023. {
  14024. isSuccess = ConfigurationStatus_Rejected;
  14025. }
  14026. }
  14027. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  14028. {
  14029. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  14030. {
  14031. strcpy(str, (const char*)value);
  14032. for(int i = 0; str[i]; i++)
  14033. {
  14034. str[i] = tolower(str[i]);
  14035. }
  14036. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14037. isSuccess = ConfigurationStatus_Accepted;
  14038. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14039. }
  14040. else
  14041. {
  14042. isSuccess = ConfigurationStatus_Rejected;
  14043. }
  14044. }
  14045. if(strcmp(key, "LocalPreAuthorize") == 0)
  14046. {
  14047. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14048. {
  14049. strcpy(str, (const char*)value);
  14050. for(int i = 0; str[i]; i++)
  14051. {
  14052. str[i] = tolower(str[i]);
  14053. }
  14054. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14055. isSuccess = ConfigurationStatus_Accepted;
  14056. }
  14057. else
  14058. {
  14059. isSuccess = ConfigurationStatus_Rejected;
  14060. }
  14061. }
  14062. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14063. {
  14064. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14065. {
  14066. check_ascii = value[0];
  14067. if( (check_ascii < 48) || (check_ascii > 57) )
  14068. {
  14069. isSuccess = ConfigurationStatus_Rejected;
  14070. }
  14071. else
  14072. {
  14073. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14074. isSuccess = ConfigurationStatus_Accepted;
  14075. }
  14076. }
  14077. else
  14078. {
  14079. isSuccess = ConfigurationStatus_Rejected;
  14080. }
  14081. }
  14082. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14083. {
  14084. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14085. {
  14086. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14087. isSuccess = ConfigurationStatus_Accepted;
  14088. }
  14089. else
  14090. {
  14091. isSuccess = ConfigurationStatus_Rejected;
  14092. }
  14093. }
  14094. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14095. {
  14096. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14097. {
  14098. check_ascii = value[0];
  14099. if( (check_ascii < 48) || (check_ascii > 57) )
  14100. {
  14101. isSuccess = ConfigurationStatus_Rejected;
  14102. }
  14103. else
  14104. {
  14105. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14106. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14107. isSuccess = ConfigurationStatus_Accepted;
  14108. }
  14109. }
  14110. else
  14111. {
  14112. isSuccess = ConfigurationStatus_Rejected;
  14113. }
  14114. }
  14115. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14116. {
  14117. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14118. {
  14119. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14120. isSuccess = ConfigurationStatus_Accepted;
  14121. }
  14122. else
  14123. {
  14124. isSuccess = ConfigurationStatus_Rejected;
  14125. }
  14126. }
  14127. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14128. {
  14129. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14130. {
  14131. check_ascii = value[0];
  14132. if( (check_ascii < 48) || (check_ascii > 57) )
  14133. {
  14134. isSuccess = ConfigurationStatus_Rejected;
  14135. }
  14136. else
  14137. {
  14138. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14139. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14140. isSuccess = ConfigurationStatus_Accepted;
  14141. }
  14142. }
  14143. else
  14144. {
  14145. isSuccess = ConfigurationStatus_Rejected;
  14146. }
  14147. }
  14148. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14149. {
  14150. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14151. {
  14152. check_ascii = value[0];
  14153. if( (check_ascii < 48) || (check_ascii > 57) )
  14154. {
  14155. isSuccess = ConfigurationStatus_Rejected;
  14156. }
  14157. else
  14158. {
  14159. if((atoi(value) == 0) || (atoi(value) >= 10))
  14160. {
  14161. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14162. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14163. isSuccess = ConfigurationStatus_Accepted;
  14164. }
  14165. else
  14166. {
  14167. isSuccess = ConfigurationStatus_Rejected;
  14168. }
  14169. }
  14170. }
  14171. else
  14172. {
  14173. isSuccess = ConfigurationStatus_Rejected;
  14174. }
  14175. }
  14176. if(strcmp(key, "MinimumStatusDuration") == 0)
  14177. {
  14178. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14179. {
  14180. check_ascii = value[0];
  14181. if( (check_ascii < 48) || (check_ascii > 57) )
  14182. {
  14183. isSuccess = ConfigurationStatus_Rejected;
  14184. }
  14185. else
  14186. {
  14187. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14188. {
  14189. isSuccess = ConfigurationStatus_Rejected;
  14190. }
  14191. else
  14192. {
  14193. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14194. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14195. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14196. isSuccess = ConfigurationStatus_Accepted;
  14197. }
  14198. }
  14199. }
  14200. else
  14201. {
  14202. isSuccess = ConfigurationStatus_Rejected;
  14203. }
  14204. }
  14205. if(strcmp(key, "NumberOfConnectors") == 0)
  14206. {
  14207. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14208. {
  14209. check_ascii = value[0];
  14210. if( (check_ascii < 48) || (check_ascii > 57) )
  14211. {
  14212. isSuccess = ConfigurationStatus_Rejected;
  14213. }
  14214. else
  14215. {
  14216. //Charger.ResetRetries = Integer.parseInt(value);
  14217. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14218. isSuccess = ConfigurationStatus_Accepted;
  14219. }
  14220. }
  14221. else
  14222. {
  14223. isSuccess = ConfigurationStatus_Rejected;
  14224. }
  14225. }
  14226. if(strcmp(key, "ResetRetries") == 0)
  14227. {
  14228. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14229. {
  14230. check_ascii = value[0];
  14231. if( (check_ascii < 48) || (check_ascii > 57) )
  14232. {
  14233. isSuccess = ConfigurationStatus_Rejected;
  14234. }
  14235. else
  14236. {
  14237. //Charger.ResetRetries = Integer.parseInt(value);
  14238. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14239. isSuccess = ConfigurationStatus_Accepted;
  14240. }
  14241. }
  14242. else
  14243. {
  14244. isSuccess = ConfigurationStatus_Rejected;
  14245. }
  14246. }
  14247. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14248. {
  14249. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14250. {
  14251. strcpy(str, (const char*)value);
  14252. for(int i = 0; str[i]; i++)
  14253. {
  14254. str[i] = tolower(str[i]);
  14255. }
  14256. if(strcmp(str, "notapplicable")== 0)
  14257. {
  14258. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14259. isSuccess = ConfigurationStatus_Accepted;
  14260. }
  14261. else if(strcmp(str, "unknown")== 0)
  14262. {
  14263. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14264. isSuccess = ConfigurationStatus_Accepted;
  14265. }
  14266. else if(strcmp(str, "rst")== 0)
  14267. {
  14268. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14269. isSuccess = ConfigurationStatus_Accepted;
  14270. }
  14271. else if(strcmp(str, "rts")== 0)
  14272. {
  14273. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14274. isSuccess = ConfigurationStatus_Accepted;
  14275. }
  14276. else if(strcmp(str, "srt")== 0)
  14277. {
  14278. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14279. isSuccess = ConfigurationStatus_Accepted;
  14280. }
  14281. else if(strcmp(str, "str")== 0)
  14282. {
  14283. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14284. isSuccess = ConfigurationStatus_Accepted;
  14285. }
  14286. else if(strcmp(str, "trs")== 0)
  14287. {
  14288. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14289. isSuccess = ConfigurationStatus_Accepted;
  14290. }
  14291. else if(strcmp(str, "tsr")== 0)
  14292. {
  14293. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14294. isSuccess = ConfigurationStatus_Accepted;
  14295. }
  14296. else
  14297. {
  14298. isSuccess = ConfigurationStatus_Rejected;
  14299. }
  14300. }
  14301. else
  14302. {
  14303. isSuccess = ConfigurationStatus_Rejected;
  14304. }
  14305. }
  14306. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14307. {
  14308. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14309. {
  14310. check_ascii = value[0];
  14311. if( (check_ascii < 48) || (check_ascii > 57) )
  14312. {
  14313. isSuccess = ConfigurationStatus_Rejected;
  14314. }
  14315. else
  14316. {
  14317. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14318. isSuccess = ConfigurationStatus_Accepted;
  14319. }
  14320. }
  14321. else
  14322. {
  14323. isSuccess = ConfigurationStatus_Rejected;
  14324. }
  14325. }
  14326. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14327. {
  14328. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14329. {
  14330. strcpy(str, (const char*)value);
  14331. for(int i = 0; str[i]; i++)
  14332. {
  14333. str[i] = tolower(str[i]);
  14334. }
  14335. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14336. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14337. isSuccess = ConfigurationStatus_Accepted;
  14338. }
  14339. else
  14340. {
  14341. isSuccess = ConfigurationStatus_Rejected;
  14342. }
  14343. }
  14344. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14345. {
  14346. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14347. {
  14348. strcpy(str, (const char*)value);
  14349. for(int i = 0; str[i]; i++)
  14350. {
  14351. str[i] = tolower(str[i]);
  14352. }
  14353. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14354. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14355. isSuccess = ConfigurationStatus_Accepted;
  14356. }
  14357. else
  14358. {
  14359. isSuccess = ConfigurationStatus_Rejected;
  14360. }
  14361. }
  14362. if(strcmp(key, "StopTxnAlignedData") == 0)
  14363. {
  14364. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14365. {
  14366. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14367. isSuccess = ConfigurationStatus_Accepted;
  14368. }
  14369. else
  14370. {
  14371. isSuccess = ConfigurationStatus_Rejected;
  14372. }
  14373. }
  14374. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14375. {
  14376. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14377. {
  14378. check_ascii = value[0];
  14379. if( (check_ascii < 48) || (check_ascii > 57) )
  14380. {
  14381. isSuccess = ConfigurationStatus_Rejected;
  14382. }
  14383. else
  14384. {
  14385. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14386. isSuccess = ConfigurationStatus_Accepted;
  14387. }
  14388. }
  14389. else
  14390. {
  14391. isSuccess = ConfigurationStatus_Rejected;
  14392. }
  14393. }
  14394. if(strcmp(key, "StopTxnSampledData") == 0)
  14395. {
  14396. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14397. {
  14398. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14399. isSuccess = ConfigurationStatus_Accepted;
  14400. }
  14401. else
  14402. {
  14403. isSuccess = ConfigurationStatus_Rejected;
  14404. }
  14405. }
  14406. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14407. {
  14408. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14409. {
  14410. check_ascii = value[0];
  14411. if( (check_ascii < 48) || (check_ascii > 57) )
  14412. {
  14413. isSuccess = ConfigurationStatus_Rejected;
  14414. }
  14415. else
  14416. {
  14417. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14418. isSuccess = ConfigurationStatus_Accepted;
  14419. }
  14420. }
  14421. else
  14422. {
  14423. isSuccess = ConfigurationStatus_Rejected;
  14424. }
  14425. }
  14426. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14427. {
  14428. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14429. {
  14430. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14431. isSuccess = ConfigurationStatus_Accepted;
  14432. }
  14433. else
  14434. {
  14435. isSuccess = ConfigurationStatus_Rejected;
  14436. }
  14437. }
  14438. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14439. {
  14440. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14441. {
  14442. check_ascii = value[0];
  14443. if( (check_ascii < 48) || (check_ascii > 57) )
  14444. {
  14445. isSuccess = ConfigurationStatus_Rejected;
  14446. }
  14447. else
  14448. {
  14449. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14450. isSuccess = ConfigurationStatus_Accepted;
  14451. }
  14452. }
  14453. else
  14454. {
  14455. isSuccess = ConfigurationStatus_Rejected;
  14456. }
  14457. }
  14458. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14459. {
  14460. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14461. {
  14462. check_ascii = value[0];
  14463. if( (check_ascii < 48) || (check_ascii > 57) )
  14464. {
  14465. isSuccess = ConfigurationStatus_Rejected;
  14466. }
  14467. else
  14468. {
  14469. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14470. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14471. TransactionMessageAttemptsValue = atoi(value);
  14472. isSuccess = ConfigurationStatus_Accepted;
  14473. }
  14474. }
  14475. else
  14476. {
  14477. isSuccess = ConfigurationStatus_Rejected;
  14478. }
  14479. }
  14480. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14481. {
  14482. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14483. {
  14484. check_ascii = value[0];
  14485. if( (check_ascii < 48) || (check_ascii > 57) )
  14486. {
  14487. isSuccess = ConfigurationStatus_Rejected;
  14488. }
  14489. else
  14490. {
  14491. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14492. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14493. TransactionMessageRetryIntervalValue = atoi(value);
  14494. isSuccess = ConfigurationStatus_Accepted;
  14495. }
  14496. }
  14497. else
  14498. {
  14499. isSuccess = ConfigurationStatus_Rejected;
  14500. }
  14501. }
  14502. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14503. {
  14504. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14505. {
  14506. strcpy(str, (const char*)value);
  14507. for(int i = 0; str[i]; i++)
  14508. {
  14509. str[i] = tolower(str[i]);
  14510. }
  14511. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14512. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14513. isSuccess = ConfigurationStatus_Accepted;
  14514. }
  14515. else
  14516. {
  14517. isSuccess = ConfigurationStatus_Rejected;
  14518. }
  14519. }
  14520. if(strcmp(key, "WebSocketPingInterval") == 0)
  14521. {
  14522. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14523. {
  14524. check_ascii = value[0];
  14525. if( (check_ascii < 48) || (check_ascii > 57) )
  14526. {
  14527. isSuccess = ConfigurationStatus_Rejected;
  14528. }
  14529. else
  14530. {
  14531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14532. isSuccess = ConfigurationStatus_Accepted;
  14533. }
  14534. }
  14535. else
  14536. {
  14537. isSuccess = ConfigurationStatus_Rejected;
  14538. }
  14539. }
  14540. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14541. {
  14542. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14543. {
  14544. strcpy(str, (const char*)value);
  14545. for(int i = 0; str[i]; i++)
  14546. {
  14547. str[i] = tolower(str[i]);
  14548. }
  14549. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14550. isSuccess = ConfigurationStatus_Accepted;
  14551. }
  14552. else
  14553. {
  14554. isSuccess = ConfigurationStatus_Rejected;
  14555. }
  14556. }
  14557. if(strcmp(key, "AuthorizationKey") == 0)
  14558. {
  14559. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14560. {
  14561. strcpy(str, (const char*)value);
  14562. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14563. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14564. isSuccess = ConfigurationStatus_Accepted;
  14565. }
  14566. else
  14567. {
  14568. isSuccess = ConfigurationStatus_Rejected;
  14569. }
  14570. }
  14571. if(strcmp(key, "SecurityProfile") == 0)
  14572. {
  14573. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14574. {
  14575. check_ascii = value[0];
  14576. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14577. {
  14578. isSuccess = ConfigurationStatus_Rejected;
  14579. }
  14580. else if(check_ascii == 0x33)
  14581. {
  14582. isSuccess = NotSupported;
  14583. }
  14584. else
  14585. {
  14586. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14587. {
  14588. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14589. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14590. isSuccess = ConfigurationStatus_Accepted;
  14591. }
  14592. else
  14593. isSuccess = ConfigurationStatus_Rejected;
  14594. }
  14595. }
  14596. else
  14597. {
  14598. isSuccess = ConfigurationStatus_Rejected;
  14599. }
  14600. }
  14601. if(strcmp(key, "DefaultPrice") == 0)
  14602. {
  14603. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14604. {
  14605. strcpy(str, (const char*)value);
  14606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14607. isSuccess = ConfigurationStatus_Accepted;
  14608. }
  14609. else
  14610. {
  14611. isSuccess = ConfigurationStatus_Rejected;
  14612. }
  14613. }
  14614. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14615. {
  14616. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14617. {
  14618. strcpy(str, (const char*)value);
  14619. for(int i = 0; str[i]; i++)
  14620. {
  14621. str[i] = tolower(str[i]);
  14622. }
  14623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14624. isSuccess = ConfigurationStatus_Accepted;
  14625. }
  14626. else
  14627. {
  14628. isSuccess = ConfigurationStatus_Rejected;
  14629. }
  14630. }
  14631. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14632. {
  14633. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14634. {
  14635. strcpy(str, (const char*)value);
  14636. for(int i = 0; str[i]; i++)
  14637. {
  14638. str[i] = tolower(str[i]);
  14639. }
  14640. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14641. isSuccess = ConfigurationStatus_Accepted;
  14642. }
  14643. else
  14644. {
  14645. isSuccess = ConfigurationStatus_Rejected;
  14646. }
  14647. }
  14648. #if 0
  14649. //For OCPP Test Case
  14650. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14651. {
  14652. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14653. {
  14654. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14655. isSuccess = ConfigurationStatus_Accepted;
  14656. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14657. }
  14658. else
  14659. {
  14660. isSuccess = ConfigurationStatus_Rejected;
  14661. }
  14662. }
  14663. #endif
  14664. #if 1
  14665. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14666. {
  14667. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14668. {
  14669. strcpy(str, (const char*)value);
  14670. for(int i = 0; str[i]; i++)
  14671. {
  14672. str[i] = tolower(str[i]);
  14673. }
  14674. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14675. isSuccess = ConfigurationStatus_Accepted;
  14676. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14677. }
  14678. else
  14679. {
  14680. isSuccess = ConfigurationStatus_Rejected;
  14681. }
  14682. }
  14683. #endif
  14684. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14685. {
  14686. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14687. {
  14688. check_ascii = value[0];
  14689. if( (check_ascii < 48) || (check_ascii > 57) )
  14690. {
  14691. isSuccess = ConfigurationStatus_Rejected;
  14692. }
  14693. else
  14694. {
  14695. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14696. isSuccess = ConfigurationStatus_Accepted;
  14697. }
  14698. }
  14699. else
  14700. {
  14701. isSuccess = ConfigurationStatus_Rejected;
  14702. }
  14703. }
  14704. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14705. {
  14706. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14707. {
  14708. check_ascii = value[0];
  14709. if( (check_ascii < 48) || (check_ascii > 57) )
  14710. {
  14711. isSuccess = ConfigurationStatus_Rejected;
  14712. }
  14713. else
  14714. {
  14715. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14716. isSuccess = ConfigurationStatus_Accepted;
  14717. }
  14718. }
  14719. else
  14720. {
  14721. isSuccess = ConfigurationStatus_Rejected;
  14722. }
  14723. }
  14724. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14725. {
  14726. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14727. {
  14728. strcpy(str, (const char*)value);
  14729. for(int i = 0; str[i]; i++)
  14730. {
  14731. str[i] = tolower(str[i]);
  14732. }
  14733. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14734. isSuccess = ConfigurationStatus_Accepted;
  14735. }
  14736. else
  14737. {
  14738. isSuccess = ConfigurationStatus_Rejected;
  14739. }
  14740. }
  14741. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14742. {
  14743. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14744. {
  14745. check_ascii = value[0];
  14746. if( (check_ascii < 48) || (check_ascii > 57) )
  14747. {
  14748. isSuccess = ConfigurationStatus_Rejected;
  14749. }
  14750. else
  14751. {
  14752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14753. isSuccess = ConfigurationStatus_Accepted;
  14754. }
  14755. }
  14756. else
  14757. {
  14758. isSuccess = ConfigurationStatus_Rejected;
  14759. }
  14760. }
  14761. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14762. {
  14763. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14764. {
  14765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14766. isSuccess = ConfigurationStatus_Accepted;
  14767. }
  14768. else
  14769. {
  14770. isSuccess = ConfigurationStatus_Rejected;
  14771. }
  14772. }
  14773. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14774. {
  14775. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14776. {
  14777. check_ascii = value[0];
  14778. if( (check_ascii < 48) || (check_ascii > 57) )
  14779. {
  14780. isSuccess = ConfigurationStatus_Rejected;
  14781. }
  14782. else
  14783. {
  14784. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14785. isSuccess = ConfigurationStatus_Accepted;
  14786. }
  14787. }
  14788. else
  14789. {
  14790. isSuccess = ConfigurationStatus_Rejected;
  14791. }
  14792. }
  14793. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14794. {
  14795. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14796. {
  14797. strcpy(str, (const char*)value);
  14798. for(int i = 0; str[i]; i++)
  14799. {
  14800. str[i] = tolower(str[i]);
  14801. }
  14802. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14803. isSuccess = ConfigurationStatus_Accepted;
  14804. }
  14805. else
  14806. {
  14807. isSuccess = ConfigurationStatus_Rejected;
  14808. }
  14809. }
  14810. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14811. {
  14812. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14813. {
  14814. check_ascii = value[0];
  14815. if( (check_ascii < 48) || (check_ascii > 57) )
  14816. {
  14817. isSuccess = ConfigurationStatus_Rejected;
  14818. }
  14819. else
  14820. {
  14821. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14822. isSuccess = ConfigurationStatus_Accepted;
  14823. }
  14824. }
  14825. else
  14826. {
  14827. isSuccess = ConfigurationStatus_Rejected;
  14828. }
  14829. }
  14830. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14831. return isSuccess;
  14832. }
  14833. int TransactionMessageAttemptsGet(void)
  14834. {
  14835. return TransactionMessageAttemptsValue;
  14836. }
  14837. int FirstHeartBeatResponse(void)
  14838. {
  14839. return FirstHeartBeat;
  14840. }
  14841. int TransactionMessageRetryIntervalGet(void)
  14842. {
  14843. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14844. }
  14845. int ReadHttpStatus(int sock)
  14846. {
  14847. //char c;
  14848. char buff[1024]="",*ptr=buff+1;
  14849. int bytes_received, status;
  14850. DEBUG_INFO("Begin Response ..\n");
  14851. while((bytes_received = recv(sock, ptr, 1, 0))){
  14852. if(bytes_received==-1){
  14853. perror("ReadHttpStatus");
  14854. exit(1);
  14855. }
  14856. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14857. ptr++;
  14858. }
  14859. *ptr=0;
  14860. ptr=buff+1;
  14861. sscanf(ptr,"%*s %d ", &status);
  14862. DEBUG_INFO("%s\n",ptr);
  14863. DEBUG_INFO("status=%d\n",status);
  14864. DEBUG_INFO("End Response ..\n");
  14865. return (bytes_received>0)?status:0;
  14866. }
  14867. //the only filed that it parsed is 'Content-Length'
  14868. int ParseHeader(int sock)
  14869. {
  14870. //char c;
  14871. char buff[1024]="",*ptr=buff+4;
  14872. int bytes_received;
  14873. DEBUG_INFO("Begin HEADER ..\n");
  14874. while((bytes_received = recv(sock, ptr, 1, 0))){
  14875. if(bytes_received==-1){
  14876. perror("Parse Header");
  14877. exit(1);
  14878. }
  14879. if(
  14880. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14881. (ptr[-1]=='\r') && (*ptr=='\n' )
  14882. ) break;
  14883. ptr++;
  14884. }
  14885. *ptr=0;
  14886. ptr=buff+4;
  14887. //printf("%s",ptr);
  14888. if(bytes_received){
  14889. ptr=strstr(ptr,"Content-Length:");
  14890. if(ptr){
  14891. sscanf(ptr,"%*s %d",&bytes_received);
  14892. }else
  14893. bytes_received=-1; //unknown size
  14894. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14895. }
  14896. DEBUG_INFO("End HEADER ..\n");
  14897. return bytes_received ;
  14898. }
  14899. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14900. {
  14901. int result = TRUE;
  14902. char rmFileCmd[100]={0};
  14903. char FilePath[100]={0};
  14904. char ftpbuf[200];
  14905. int systemresult;
  14906. sprintf(FilePath,"/mnt/%s",filename);
  14907. system("ping 8.8.8.8 &");
  14908. if((access(FilePath,F_OK))!=-1)
  14909. {
  14910. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14911. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14912. system(rmFileCmd);
  14913. }
  14914. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14915. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  14916. DEBUG_INFO("Download command: %s\n",ftpbuf);
  14917. systemresult = system(ftpbuf);
  14918. if(systemresult != 0)
  14919. {
  14920. DEBUG_INFO("http DownLoad error!\n");
  14921. result = FALSE;
  14922. }
  14923. system("pkill ping");
  14924. return result;
  14925. }
  14926. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14927. {
  14928. int result = TRUE;
  14929. char rmFileCmd[100]={0};
  14930. char FilePath[100]={0};
  14931. char ftpbuf[200];
  14932. int systemresult;
  14933. sprintf(FilePath,"/mnt/%s",filename);
  14934. system("ping 8.8.8.8 &");
  14935. if((access(FilePath,F_OK))!=-1)
  14936. {
  14937. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14938. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14939. system(rmFileCmd);
  14940. }
  14941. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14942. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14943. DEBUG_INFO("Download command: %s\n",ftpbuf);
  14944. systemresult = system(ftpbuf);
  14945. if(systemresult != 0)
  14946. {
  14947. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  14948. DEBUG_INFO("Download command: %s\n",ftpbuf);
  14949. systemresult = system(ftpbuf);
  14950. if(systemresult != 0)
  14951. {
  14952. DEBUG_WARN("wget error!\n");
  14953. result = FALSE;
  14954. }
  14955. }
  14956. system("pkill ping");
  14957. return result;
  14958. }
  14959. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14960. {
  14961. char rmFileCmd[100]={0};
  14962. char FilePath[100]={0};
  14963. char buf[512];
  14964. int systemresult = 0;
  14965. //DEBUG_INFO("filename=%s\n",filename);
  14966. //DEBUG_INFO("url=%s\n",url);
  14967. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14968. if((access(FilePath,F_OK))!=-1)
  14969. {
  14970. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14971. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14972. system(rmFileCmd);
  14973. }
  14974. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14975. if(fp == NULL)
  14976. {
  14977. DEBUG_INFO("log is NULL\n");
  14978. return FALSE;
  14979. }
  14980. else
  14981. {
  14982. fprintf(fp, "%s\n", url);
  14983. fprintf(fp, "%s\n", filename);
  14984. fclose(fp);
  14985. }
  14986. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14987. if(phpFP == NULL)
  14988. {
  14989. DEBUG_INFO("PHP upload fail.\n");
  14990. return FALSE;
  14991. }
  14992. else
  14993. {
  14994. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14995. {
  14996. if(strstr(buf, "result") != NULL)
  14997. {
  14998. sscanf(buf, "result: %d", &systemresult);
  14999. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  15000. }
  15001. }
  15002. pclose(phpFP);
  15003. }
  15004. if(systemresult != 1)
  15005. {
  15006. DEBUG_INFO("HTTP upload error!\n");
  15007. return FALSE;
  15008. }
  15009. return TRUE;
  15010. }
  15011. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  15012. {
  15013. struct hostent* server;
  15014. char *IPbuffer;
  15015. char ftpbuf[200];
  15016. int systemresult;
  15017. // To retrieve host information
  15018. server = gethostbyname(location);
  15019. // To convert an Internet network
  15020. // address into ASCII string
  15021. IPbuffer = inet_ntoa(*((struct in_addr*)
  15022. server->h_addr_list[0]));
  15023. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15024. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  15025. /* format : ftpput -u username -p passwd IP target source*/
  15026. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  15027. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  15028. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  15029. systemresult = system(ftpbuf);
  15030. DEBUG_INFO("systemresult=%d\n",systemresult);
  15031. if(systemresult != 0)
  15032. {
  15033. DEBUG_INFO("ftpput error!\n");
  15034. return FALSE;
  15035. }
  15036. return TRUE;
  15037. }
  15038. int GetOcppServerURL()
  15039. {
  15040. int result = FALSE;
  15041. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15042. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15043. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15044. struct yuarel url;
  15045. char urlStr[512];
  15046. // OCPPPH only
  15047. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  15048. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  15049. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  15050. {
  15051. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  15052. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15053. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15054. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  15055. if(yuarel_parse(&url, urlStr) != -1)
  15056. {
  15057. sprintf(OcppProtocol, "%s", url.scheme);
  15058. sprintf(OcppHost, "%s", url.host);
  15059. if(url.path == NULL)
  15060. OcppTempPath[0] = '\0';
  15061. else
  15062. sprintf(OcppTempPath, "%s", url.path);
  15063. if(url.port == 0)
  15064. {
  15065. if(strcmp(OcppProtocol, "wss") == 0)
  15066. OcppPort = 443;
  15067. else
  15068. OcppPort = 80;
  15069. }
  15070. else
  15071. OcppPort = url.port;
  15072. result = TRUE;
  15073. }
  15074. }
  15075. else
  15076. {
  15077. strcpy(OcppHost,"");
  15078. }
  15079. return result;
  15080. }
  15081. int GetOcppPath()
  15082. {
  15083. int result = FALSE;
  15084. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  15085. {
  15086. if(OcppTempPath == NULL)
  15087. {
  15088. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  15089. }
  15090. else
  15091. {
  15092. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  15093. }
  15094. result = TRUE;
  15095. goto End;
  15096. }
  15097. else
  15098. {
  15099. strcpy(OcppPath,"");
  15100. }
  15101. End:
  15102. return result;
  15103. }
  15104. int GetOcppPort()
  15105. {
  15106. return OcppPort;
  15107. }
  15108. int GetOcppConnStatus(void)
  15109. {
  15110. return ShmOCPP16DataPH->OcppConnStatus;
  15111. }
  15112. void SetOcppConnStatus(uint8_t status)
  15113. {
  15114. ShmOCPP16DataPH->OcppConnStatus = status;
  15115. }
  15116. int GetHeartBeatWithNOResponse(void)
  15117. {
  15118. return HeartBeatWithNOResponse;
  15119. }
  15120. void SetHeartBeatWithNOResponse(void)
  15121. {
  15122. HeartBeatWithNOResponse = 0;
  15123. }
  15124. void GetStartTransactionIdTag(int gun_index)
  15125. {
  15126. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15127. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15128. }
  15129. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15130. {
  15131. char ch;
  15132. FILE *fptr1;
  15133. int temptransactionId;
  15134. char str[100]={0};
  15135. temptransactionId = 0;
  15136. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15137. {
  15138. DEBUG_INFO("IdTag is empty.\n");
  15139. return temptransactionId;
  15140. }
  15141. /*------ Read the file ----------------*/
  15142. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  15143. if (!fptr1)
  15144. {
  15145. DEBUG_INFO("QueueTransactionId file open error.\n");
  15146. //printf(" File not found or unable to open the input file!!\n");
  15147. return temptransactionId;
  15148. }
  15149. ch=fgetc(fptr1);
  15150. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  15151. rewind(fptr1);
  15152. if(ch!=EOF)
  15153. {
  15154. // printf("%c",ch);
  15155. while (fgets(str, 100, fptr1) != NULL)
  15156. {
  15157. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15158. if(str[0]=='\0')
  15159. {
  15160. break;
  15161. }
  15162. char *revbuf[8] = {0}; // Variable store string split
  15163. int num = 0;// Quantity after string split
  15164. DEBUG_INFO("Transaction queue data= %s\n", str);
  15165. splitstring(str,",",revbuf,&num); // String split
  15166. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15167. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15168. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15169. DEBUG_INFO("------------------------------\n");
  15170. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15171. {
  15172. if(isStopTransaction)
  15173. {
  15174. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15175. {
  15176. temptransactionId = atoi(revbuf[2]);
  15177. //break;
  15178. }
  15179. }
  15180. else
  15181. {
  15182. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15183. {
  15184. temptransactionId = atoi(revbuf[2]);
  15185. //break;
  15186. }
  15187. }
  15188. }
  15189. }
  15190. }
  15191. else
  15192. DEBUG_INFO("EOF\n");
  15193. fclose(fptr1);
  15194. /*------- End of reading ---------------*/
  15195. return temptransactionId;
  15196. }
  15197. void SetTransactionIdZero(int transactionId)
  15198. {
  15199. char ch;
  15200. FILE *fptr1, *fptr2;
  15201. int temptransactionId = 0;
  15202. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  15203. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  15204. if (!fptr1)
  15205. {
  15206. //printf(" File not found or unable to open the input file!!\n");
  15207. return ;
  15208. }
  15209. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15210. if (!fptr2)
  15211. {
  15212. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15213. fclose(fptr1);
  15214. return ;
  15215. }
  15216. ch=fgetc(fptr1);
  15217. rewind(fptr1);
  15218. if(ch!=EOF)
  15219. {
  15220. // copy all contents to the temporary file except the specific line
  15221. while (fgets(str, 100, fptr1) != NULL)
  15222. {
  15223. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15224. if(str[0]=='\0')
  15225. {
  15226. break;
  15227. }
  15228. char *revbuf[8] = {0};
  15229. int num = 0;
  15230. strcpy(strtemp, str);
  15231. splitstring(str,",",revbuf,&num);
  15232. if(revbuf[2][0] != '\0')
  15233. {
  15234. temptransactionId = atoi(revbuf[2]);
  15235. if(transactionId != temptransactionId)
  15236. {
  15237. fprintf(fptr2, "%s\n", strtemp);
  15238. }
  15239. }
  15240. }
  15241. }
  15242. fclose(fptr1);
  15243. fclose(fptr2);
  15244. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  15245. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  15246. /*------ Read the file ----------------*/
  15247. }
  15248. int InternetDisconnect(void)
  15249. {
  15250. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15251. }
  15252. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15253. void storeTempStopTransaction(int gun_index)
  15254. {
  15255. char guid[37]={0};
  15256. int tempIndex = 0;
  15257. char TempStopTransaction[256];
  15258. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15259. DEBUG_INFO("storeTempStopTransaction...\n");
  15260. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15261. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  15262. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15263. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15264. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15265. {
  15266. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15267. {
  15268. tempIndex = ((gun_index==2) ? 1: 0);
  15269. }
  15270. else
  15271. {
  15272. tempIndex = gun_index;
  15273. }
  15274. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15275. {
  15276. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15277. {
  15278. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15279. }
  15280. }// END OF CHAdeMO_QUANTITY
  15281. }
  15282. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15283. {
  15284. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15285. {
  15286. tempIndex = ((gun_index==2) ? 1: 0);
  15287. }
  15288. else
  15289. {
  15290. tempIndex = gun_index;
  15291. }
  15292. for (int index = 0; index < CCS_QUANTITY; index++)
  15293. {
  15294. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15295. {
  15296. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15297. }
  15298. }// END OF CCS_QUANTITY
  15299. }
  15300. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15301. {
  15302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15303. {
  15304. tempIndex = ((gun_index==2) ? 1: 0);
  15305. }
  15306. else
  15307. {
  15308. tempIndex = gun_index;
  15309. }
  15310. for (int index = 0; index < GB_QUANTITY; index++)
  15311. {
  15312. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15313. {
  15314. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15315. }
  15316. }// END OF GB_QUANTITY
  15317. }
  15318. else if(gunType[gun_index] == GUN_TYPE_DO)
  15319. {
  15320. tempIndex = gun_index;
  15321. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15322. {
  15323. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15324. {
  15325. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15326. }
  15327. }
  15328. }
  15329. else
  15330. {
  15331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15332. {
  15333. tempIndex = 2;
  15334. }
  15335. else
  15336. {
  15337. tempIndex = gun_index;
  15338. }
  15339. for (int index = 0; index < AC_QUANTITY; index++)
  15340. {
  15341. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15342. {
  15343. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15344. }
  15345. }// END OF AC_QUANTITY
  15346. }
  15347. //Stop Transaction Time
  15348. struct timeval tmnow;
  15349. struct tm *tm;
  15350. char buf[28];//, usec_buf[6];
  15351. gettimeofday(&tmnow, NULL);
  15352. time_t t;
  15353. t = time(NULL);
  15354. /*UTC time and date*/
  15355. tm = gmtime(&t);
  15356. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15357. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  15358. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  15359. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15360. random_uuid(guid);
  15361. /***********************************transactionData******************************************************/
  15362. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15363. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15364. //=================================
  15365. //1. Transaction_Begin
  15366. //=================================
  15367. //============================== Energy.Active.Import.Interval ===========================================
  15368. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15369. {
  15370. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15371. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15372. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15373. 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*/]);
  15374. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15375. 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))
  15376. {
  15377. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15378. }
  15379. else
  15380. {
  15381. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15382. }
  15383. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15384. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15385. }
  15386. //=================================
  15387. //2. Transaction_End
  15388. //=================================
  15389. //2.1====================================== Current.Import L1 ==============================================
  15390. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15391. {
  15392. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15393. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15394. {
  15395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15396. {
  15397. tempIndex = ((gun_index==2) ? 1: 0);
  15398. }
  15399. else
  15400. {
  15401. tempIndex = gun_index;
  15402. }
  15403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15404. {
  15405. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15406. {
  15407. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15408. }
  15409. }// End of for CHAdeMO_QUANTITY
  15410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15411. }
  15412. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15413. {
  15414. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15415. {
  15416. tempIndex = ((gun_index==2) ? 1: 0);
  15417. }
  15418. else
  15419. {
  15420. tempIndex = gun_index;
  15421. }
  15422. for (int index = 0; index < CCS_QUANTITY; index++)
  15423. {
  15424. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15425. {
  15426. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15427. }
  15428. }// End of for CCS_QUANTITY
  15429. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15430. }
  15431. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15432. {
  15433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15434. {
  15435. tempIndex = ((gun_index==2) ? 1: 0);
  15436. }
  15437. else
  15438. {
  15439. tempIndex = gun_index;
  15440. }
  15441. for (int index = 0; index < GB_QUANTITY; index++)
  15442. {
  15443. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15444. {
  15445. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15446. }
  15447. }// End of for GB_QUANTITY
  15448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15449. }
  15450. else if(gunType[gun_index] == GUN_TYPE_DO)
  15451. {
  15452. tempIndex = gun_index;
  15453. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15454. {
  15455. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15456. {
  15457. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15458. }
  15459. }
  15460. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15461. }
  15462. else
  15463. {
  15464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15465. {
  15466. tempIndex = 2;
  15467. }
  15468. else
  15469. {
  15470. tempIndex = gun_index;
  15471. }
  15472. for (int index = 0; index < AC_QUANTITY; index++)
  15473. {
  15474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15475. {
  15476. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15477. }
  15478. }// End of for AC_QUANTITY
  15479. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15480. }
  15481. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15482. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15483. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15484. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15485. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15486. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15487. }
  15488. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15489. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15490. {
  15491. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15492. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15493. {
  15494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15495. {
  15496. tempIndex = ((gun_index==2) ? 1: 0);
  15497. }
  15498. else
  15499. {
  15500. tempIndex = gun_index;
  15501. }
  15502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15503. {
  15504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15505. {
  15506. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15507. }
  15508. }// END OF CHAdeMO_QUANTITY
  15509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15510. }
  15511. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15512. {
  15513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15514. {
  15515. tempIndex = ((gun_index==2) ? 1: 0);
  15516. }
  15517. else
  15518. {
  15519. tempIndex = gun_index;
  15520. }
  15521. for (int index = 0; index < CCS_QUANTITY; index++)
  15522. {
  15523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15524. {
  15525. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15526. }
  15527. }// END OF CCS_QUANTITY
  15528. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15529. }
  15530. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15531. {
  15532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15533. {
  15534. tempIndex = ((gun_index==2) ? 1: 0);
  15535. }
  15536. else
  15537. {
  15538. tempIndex = gun_index;
  15539. }
  15540. for (int index = 0; index < GB_QUANTITY; index++)
  15541. {
  15542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15543. {
  15544. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15545. }
  15546. }// END OF GB_QUANTITY
  15547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15548. }
  15549. else if(gunType[gun_index] == GUN_TYPE_DO)
  15550. {
  15551. tempIndex = gun_index;
  15552. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15553. {
  15554. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15555. {
  15556. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15557. }
  15558. }
  15559. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15560. }
  15561. else
  15562. {
  15563. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15564. {
  15565. tempIndex = 2;
  15566. }
  15567. else
  15568. {
  15569. tempIndex = gun_index;
  15570. }
  15571. for (int index = 0; index < AC_QUANTITY; index++)
  15572. {
  15573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15574. {
  15575. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15576. }
  15577. }// END OF AC_QUANTITY
  15578. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15579. }
  15580. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15581. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15582. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15583. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15584. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15585. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15586. }
  15587. //2.3====================================== Power.Active.Import =========================================
  15588. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15589. {
  15590. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15591. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15592. {
  15593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15594. {
  15595. tempIndex = ((gun_index==2) ? 1: 0);
  15596. }
  15597. else
  15598. {
  15599. tempIndex = gun_index;
  15600. }
  15601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15602. {
  15603. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15604. {
  15605. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15606. }
  15607. } // End for CHAdeMO_QUANTITY
  15608. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15609. }
  15610. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15611. {
  15612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15613. {
  15614. tempIndex = ((gun_index==2) ? 1: 0);
  15615. }
  15616. else
  15617. {
  15618. tempIndex = gun_index;
  15619. }
  15620. for (int index = 0; index < CCS_QUANTITY; index++)
  15621. {
  15622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15623. {
  15624. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15625. }
  15626. } // END for CCS_QUANTITY
  15627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15628. }
  15629. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15630. {
  15631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15632. {
  15633. tempIndex = ((gun_index==2) ? 1: 0);
  15634. }
  15635. else
  15636. {
  15637. tempIndex = gun_index;
  15638. }
  15639. for (int index = 0; index < GB_QUANTITY; index++)
  15640. {
  15641. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15642. {
  15643. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15644. }
  15645. }// END for GB_QUANTITY
  15646. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15647. }
  15648. else if(gunType[gun_index] == GUN_TYPE_DO)
  15649. {
  15650. tempIndex = gun_index;
  15651. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15652. {
  15653. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15654. {
  15655. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15656. }
  15657. }
  15658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15659. }
  15660. else
  15661. {
  15662. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15663. {
  15664. tempIndex = 2;
  15665. }
  15666. else
  15667. {
  15668. tempIndex = gun_index;
  15669. }
  15670. for (int index = 0; index < AC_QUANTITY; index++)
  15671. {
  15672. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15673. {
  15674. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15675. }
  15676. } // END for AC_QUANTITY
  15677. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15678. }
  15679. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15680. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15682. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15685. }
  15686. //2.4====================================== Voltage L1 ====================================================
  15687. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15688. {
  15689. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15690. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15691. {
  15692. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15693. {
  15694. tempIndex = ((gun_index==2) ? 1: 0);
  15695. }
  15696. else
  15697. {
  15698. tempIndex = gun_index;
  15699. }
  15700. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15701. {
  15702. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15703. {
  15704. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15705. }
  15706. } // END OF FOR CHAdeMO_QUANTITY
  15707. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15708. }
  15709. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15710. {
  15711. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15712. {
  15713. tempIndex = ((gun_index==2) ? 1: 0);
  15714. }
  15715. else
  15716. {
  15717. tempIndex = gun_index;
  15718. }
  15719. for (int index = 0; index < CCS_QUANTITY; index++)
  15720. {
  15721. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15722. {
  15723. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15724. }
  15725. } // END OF FOR CCS_QUANTITY
  15726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15727. }
  15728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15729. {
  15730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15731. {
  15732. tempIndex = ((gun_index==2) ? 1: 0);
  15733. }
  15734. else
  15735. {
  15736. tempIndex = gun_index;
  15737. }
  15738. for (int index = 0; index < GB_QUANTITY; index++)
  15739. {
  15740. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15741. {
  15742. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15743. }
  15744. } // END OF FOR GB_QUANTITY
  15745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15746. }
  15747. else if(gunType[gun_index] == GUN_TYPE_DO)
  15748. {
  15749. tempIndex = gun_index;
  15750. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15751. {
  15752. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15753. {
  15754. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15755. }
  15756. }
  15757. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15758. }
  15759. else
  15760. {
  15761. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15762. {
  15763. tempIndex = 2;
  15764. }
  15765. else
  15766. {
  15767. tempIndex = gun_index;
  15768. }
  15769. for (int index = 0; index < AC_QUANTITY; index++)
  15770. {
  15771. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15772. {
  15773. 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
  15774. }
  15775. } // END OF FOR AC_QUANTITY
  15776. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15777. }
  15778. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15780. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15781. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15782. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15783. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15784. }
  15785. //2.5============================================== End SoC =========================================================
  15786. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  15787. {
  15788. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15789. 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))
  15790. {
  15791. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15792. {
  15793. tempIndex = ((gun_index==2) ? 1: 0);
  15794. }
  15795. else
  15796. {
  15797. tempIndex = gun_index;
  15798. }
  15799. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15800. {
  15801. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15802. {
  15803. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15804. {
  15805. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15806. }
  15807. }
  15808. }
  15809. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15810. {
  15811. for (int index = 0; index < CCS_QUANTITY; index++)
  15812. {
  15813. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15814. {
  15815. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15816. }
  15817. }
  15818. }
  15819. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15820. {
  15821. for (int index = 0; index < GB_QUANTITY; index++)
  15822. {
  15823. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15824. {
  15825. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15826. }
  15827. }
  15828. }
  15829. else if(gunType[gun_index] == GUN_TYPE_DO)
  15830. {
  15831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15832. {
  15833. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15834. {
  15835. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15836. }
  15837. }
  15838. }
  15839. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15840. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15841. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15843. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15844. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15845. } // END FOR DC CASE
  15846. }
  15847. //2.6====================================== Current.Import L2 ==============================================
  15848. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15849. {
  15850. // AC 3 phase L2 current
  15851. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15852. {
  15853. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15854. {
  15855. tempIndex = 2;
  15856. }
  15857. else
  15858. {
  15859. tempIndex = gun_index;
  15860. }
  15861. for (int index = 0; index < AC_QUANTITY; index++)
  15862. {
  15863. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15864. {
  15865. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15866. }
  15867. }// End of for AC_QUANTITY
  15868. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15869. }
  15870. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15871. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15873. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15874. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15875. }
  15876. //2.7====================================== Current.Import L3 ==============================================
  15877. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15878. {
  15879. // AC 3 phase L3 current
  15880. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15881. {
  15882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15883. {
  15884. tempIndex = 2;
  15885. }
  15886. else
  15887. {
  15888. tempIndex = gun_index;
  15889. }
  15890. for (int index = 0; index < AC_QUANTITY; index++)
  15891. {
  15892. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15893. {
  15894. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15895. }
  15896. }// End of for AC_QUANTITY
  15897. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15898. }
  15899. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15900. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15903. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15904. }
  15905. //2.9====================================== Voltage L2 ====================================================
  15906. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15907. {
  15908. // AC 3 phase L2 volatge
  15909. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15910. {
  15911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15912. {
  15913. tempIndex = 2;
  15914. }
  15915. else
  15916. {
  15917. tempIndex = gun_index;
  15918. }
  15919. for (int index = 0; index < AC_QUANTITY; index++)
  15920. {
  15921. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15922. {
  15923. 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
  15924. }
  15925. } // END OF FOR AC_QUANTITY
  15926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15927. }
  15928. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15929. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15930. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15931. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15932. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15933. }
  15934. //2.10====================================== Voltage L3 ====================================================
  15935. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15936. {
  15937. // AC 3 phase L3 volatge
  15938. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15939. {
  15940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15941. {
  15942. tempIndex = 2;
  15943. }
  15944. else
  15945. {
  15946. tempIndex = gun_index;
  15947. }
  15948. for (int index = 0; index < AC_QUANTITY; index++)
  15949. {
  15950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15951. {
  15952. 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
  15953. }
  15954. } // END OF FOR AC_QUANTITY
  15955. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15956. }
  15957. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15958. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15959. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15960. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15961. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15962. }
  15963. //====================== Start SoC ================================
  15964. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  15965. {
  15966. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15967. 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))
  15968. {
  15969. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15970. {
  15971. tempIndex = ((gun_index==2) ? 1: 0);
  15972. }
  15973. else
  15974. {
  15975. tempIndex = gun_index;
  15976. }
  15977. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15978. {
  15979. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15980. {
  15981. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15982. {
  15983. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15984. }
  15985. }
  15986. }
  15987. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15988. {
  15989. for (int index = 0; index < CCS_QUANTITY; index++)
  15990. {
  15991. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15992. {
  15993. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15994. }
  15995. }
  15996. }
  15997. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15998. {
  15999. for (int index = 0; index < GB_QUANTITY; index++)
  16000. {
  16001. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16002. {
  16003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  16004. }
  16005. }
  16006. }
  16007. else if(gunType[gun_index] == GUN_TYPE_DO)
  16008. {
  16009. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16010. {
  16011. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16012. {
  16013. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  16014. }
  16015. }
  16016. }
  16017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  16018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  16019. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  16020. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  16021. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  16022. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  16023. } // END FOR DC CASE
  16024. }
  16025. //======================================== Message create ==============================================
  16026. json_object *StopTransaction = json_object_new_object();
  16027. json_object *transactionDatas = json_object_new_array();
  16028. json_object *sampledValues = json_object_new_array();
  16029. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  16030. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  16031. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  16032. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  16033. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  16034. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16035. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  16036. {
  16037. json_object *transactionData = json_object_new_object();
  16038. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16039. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16040. {
  16041. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16042. {
  16043. json_object *sampledValue = json_object_new_object();
  16044. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16045. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16046. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16047. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16048. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16049. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16050. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16051. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16052. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16053. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16054. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16055. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16056. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16057. json_object_array_add(sampledValues, sampledValue);
  16058. }
  16059. }
  16060. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16061. json_object_array_add(transactionDatas, transactionData);
  16062. }
  16063. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16064. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16065. ,MESSAGE_TYPE_CALL
  16066. ,guid
  16067. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16068. json_object_put(StopTransaction);
  16069. // Check File "TempStopTransaction" Exist
  16070. if((access(TempStopTransaction,F_OK))!=-1)
  16071. {
  16072. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16073. fclose(fopen(TempStopTransaction, "w"));
  16074. }
  16075. else
  16076. {
  16077. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16078. FILE *log = fopen(TempStopTransaction, "w+");
  16079. if(log == NULL)
  16080. {
  16081. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16082. return ;
  16083. }
  16084. else
  16085. {
  16086. fclose(log);
  16087. }
  16088. }
  16089. //Add TempStopTransaction | Update TempStopTransaction
  16090. // open file for writing
  16091. FILE *outfile;
  16092. outfile = fopen (TempStopTransaction, "a");
  16093. //DEBUG_INFO("data = %s\n", queuedata);
  16094. fputs(queuedata, outfile);
  16095. fputs("\n", outfile);
  16096. fclose (outfile);
  16097. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16098. }
  16099. void checkTempStopTransaction(int gun_index)
  16100. {
  16101. FILE *fptr1;
  16102. char ch;
  16103. char str[QUEUE_MESSAGE_LENGTH]={0};
  16104. char guid[37]={0};
  16105. char tempdata[65]={0};
  16106. char connectorStr[2]={0};
  16107. char TempStopTransaction[256];
  16108. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16109. fptr1 = fopen(TempStopTransaction, "r");
  16110. //TempStopTransaction格式: 槍號,StopTransaction封包
  16111. if (!fptr1)
  16112. {
  16113. //printf(" File not found or unable to open the input file!!\n");
  16114. return ;
  16115. }
  16116. ch=fgetc(fptr1);
  16117. //printf(" Now the content of the file %s is : \n",fname);
  16118. rewind(fptr1);
  16119. if(ch!=EOF)
  16120. {
  16121. // copy all contents to the temporary file except the specific line
  16122. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16123. {
  16124. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16125. if(str[0]=='\0')
  16126. {
  16127. break;
  16128. }
  16129. //TempStopTransaction格式: 槍號,StopTransaction封包
  16130. strncpy(connectorStr, str, 1);
  16131. if(atoi(connectorStr) != (gun_index+1))
  16132. {
  16133. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16134. fclose(fptr1);
  16135. return ;
  16136. }
  16137. //random_uuid(guid);
  16138. strncpy(guid, str+6, 36); //copy guid
  16139. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16140. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16141. {
  16142. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16143. }
  16144. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16145. OCPP_insert_transaction_msg(NO, str);
  16146. memset(str,0,ARRAY_SIZE(str));
  16147. }
  16148. }
  16149. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16150. fclose(fptr1);
  16151. remove(TempStopTransaction); // remove the original file
  16152. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16153. }
  16154. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16155. {
  16156. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16157. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16158. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16159. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16160. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16161. }
  16162. int GetWebSocketPingInterval(void)
  16163. {
  16164. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16165. }
  16166. int GetServerSign(void)
  16167. {
  16168. return server_sign;
  16169. }
  16170. uint8_t GetOcppSecurityProfile()
  16171. {
  16172. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16173. }
  16174. void GetOcppChargerBoxId(uint8_t *data)
  16175. {
  16176. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  16177. }
  16178. void GetOcppSecurityPassword(uint8_t *data)
  16179. {
  16180. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16181. }
  16182. void SetOcppVersion(uint8_t *version)
  16183. {
  16184. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16185. DEBUG_INFO("ocpp version: %s\n", version);
  16186. if(strstr((char*)version, "ocpp1.6") != NULL)
  16187. {
  16188. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16189. }
  16190. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16191. {
  16192. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16193. system("pkill OcppBackend");
  16194. }
  16195. }
  16196. void SetServerSign(int value)
  16197. {
  16198. server_sign = value;
  16199. }
  16200. int GetBootNotificationInterval(void)
  16201. {
  16202. return BootNotificationInterval;
  16203. }
  16204. int GetInternetConn(void)
  16205. {
  16206. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16207. }
  16208. int GetBackendConnectionTimeout(void)
  16209. {
  16210. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16211. }
  16212. int isConnectorInitMode(int gun_index)
  16213. {
  16214. int tempIndex = 0;
  16215. int result = TRUE;
  16216. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16217. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16218. {
  16219. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16220. {
  16221. tempIndex = ((gun_index==2) ? 1: 0);
  16222. }
  16223. else
  16224. {
  16225. tempIndex = gun_index;
  16226. }
  16227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16228. {
  16229. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16230. {
  16231. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16232. } //end of the same index
  16233. }//end of for CHAdeMO_QUANTITY
  16234. }
  16235. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16236. {
  16237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16238. {
  16239. tempIndex = ((gun_index==2) ? 1: 0);
  16240. }
  16241. else
  16242. {
  16243. tempIndex = gun_index;
  16244. }
  16245. for (int index = 0; index < CCS_QUANTITY; index++)
  16246. {
  16247. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16248. {
  16249. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16250. } //end of the same index
  16251. } // end of for CCS_QUANTITY
  16252. }
  16253. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16254. {
  16255. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16256. {
  16257. tempIndex = ((gun_index==2) ? 1: 0);
  16258. }
  16259. else
  16260. {
  16261. tempIndex = gun_index;
  16262. }
  16263. for (int index = 0; index < GB_QUANTITY; index++)
  16264. {
  16265. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16266. {
  16267. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16268. } //end of the same index
  16269. } // end of for GB_QUANTITY
  16270. }
  16271. else if(gunType[gun_index] == GUN_TYPE_DO)
  16272. {
  16273. tempIndex = gun_index;
  16274. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16275. {
  16276. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16277. {
  16278. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16279. } //end of the same index
  16280. }
  16281. }
  16282. else
  16283. {
  16284. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16285. {
  16286. tempIndex = 2;
  16287. }
  16288. else
  16289. {
  16290. tempIndex = gun_index;
  16291. }
  16292. for (int index = 0; index < AC_QUANTITY; index++)
  16293. {
  16294. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16295. {
  16296. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16297. }//end of the same index
  16298. }//end of for AC_QUANTITY
  16299. }
  16300. return result;
  16301. }
  16302. void refreshProcDogTimer()
  16303. {
  16304. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  16305. }
  16306. void InitialSystemValue(void)
  16307. {
  16308. int connectorIndex = 0;
  16309. //int valueASCII = 0;
  16310. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16311. gunTotalNumber=0;
  16312. SystemInitial = 0;
  16313. locallistVersion=0;
  16314. BootNotificationInterval = 0;
  16315. authorizeRetryTimes = 0;
  16316. GunStatusInterval = 10;
  16317. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16318. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16319. //Hear Beat
  16320. HeartBeatWithNOResponse = 0;
  16321. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16322. FirstHeartBeat = 0;
  16323. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16324. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16325. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16326. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16327. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16328. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16329. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16330. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16331. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16332. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16333. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16334. memset(gunType, 0, ARRAY_SIZE(gunType));
  16335. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16336. {
  16337. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16338. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16339. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16340. {
  16341. // DO series
  16342. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16343. {
  16344. SystemInitial = SystemInitial + 1;
  16345. gunTotalNumber = gunTotalNumber + 1;
  16346. gunType[connectorIndex] = GUN_TYPE_DO;
  16347. connectorIndex = connectorIndex + 1;
  16348. }
  16349. }
  16350. else
  16351. {
  16352. // DM, DW, DS series
  16353. //check connector / socket type (index: 8, 9, 10)
  16354. for(int index=7; index <10 ; index++)
  16355. {
  16356. if(index != 8)
  16357. {
  16358. // DC Connector
  16359. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16360. {
  16361. SystemInitial = SystemInitial + 1;
  16362. gunTotalNumber = gunTotalNumber + 1;
  16363. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16364. connectorIndex = connectorIndex + 1;
  16365. }
  16366. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16367. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16368. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16369. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16370. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16371. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16372. {
  16373. SystemInitial = SystemInitial + 1;
  16374. gunTotalNumber = gunTotalNumber + 1;
  16375. gunType[connectorIndex] = GUN_TYPE_CCS;
  16376. connectorIndex = connectorIndex + 1;
  16377. }
  16378. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16379. {
  16380. SystemInitial = SystemInitial + 1;
  16381. gunTotalNumber = gunTotalNumber + 1;
  16382. gunType[connectorIndex] = GUN_TYPE_GBT;
  16383. connectorIndex = connectorIndex + 1;
  16384. }
  16385. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16386. {
  16387. SystemInitial = SystemInitial + 1;
  16388. gunTotalNumber = gunTotalNumber + 1;
  16389. gunType[connectorIndex] = GUN_TYPE_DO;
  16390. connectorIndex = connectorIndex + 1;
  16391. }
  16392. }
  16393. else
  16394. {
  16395. // AC Connector
  16396. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16397. {
  16398. SystemInitial = SystemInitial + 1;
  16399. gunTotalNumber = gunTotalNumber + 1;
  16400. gunType[connectorIndex] = GUN_TYPE_AC;
  16401. connectorIndex = connectorIndex + 1;
  16402. }
  16403. }
  16404. }
  16405. }
  16406. //DEBUG_INFO("DC ...\n");
  16407. }
  16408. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16409. {
  16410. //check connector / socket type (index: 8, 9, 10)
  16411. for(int index=7; index <10 ; index++)
  16412. {
  16413. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16414. {
  16415. SystemInitial = SystemInitial + 1;
  16416. gunTotalNumber = gunTotalNumber + 1;
  16417. gunType[connectorIndex] = GUN_TYPE_AC;
  16418. connectorIndex = connectorIndex + 1;
  16419. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16420. }
  16421. }
  16422. }
  16423. //Status && ConnectorPlugIn Setting
  16424. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16425. {
  16426. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16427. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16428. }
  16429. for (int index = 0; index < CCS_QUANTITY; index++)
  16430. {
  16431. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16432. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16433. }
  16434. for (int index = 0; index < GB_QUANTITY; index++)
  16435. {
  16436. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16437. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16438. }
  16439. for (int index = 0; index < AC_QUANTITY; index++)
  16440. {
  16441. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16442. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16443. }
  16444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16445. {
  16446. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16447. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16448. }
  16449. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16450. {
  16451. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16452. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16453. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16454. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16455. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16456. }
  16457. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16458. clientTime.Heartbeat=time((time_t*)NULL);
  16459. sleep(1);
  16460. }
  16461. void LWS_Send(char *str)
  16462. {
  16463. //=====================================================
  16464. // Check InternetConn 0: disconnected, 1: connected
  16465. //====================================================
  16466. if(GetOcppConnStatus() == 0)
  16467. {
  16468. DEBUG_INFO("offline now !!!\n");
  16469. return;
  16470. }
  16471. // Only disable isWebsocketSendable operation initiated by charger
  16472. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16473. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16474. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16475. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16476. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16477. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16478. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16479. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16480. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16481. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16482. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16483. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16484. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16485. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16486. {
  16487. isWebsocketSendable = 0;
  16488. }
  16489. pthread_mutex_lock(&lock_send);
  16490. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16491. sprintf((char *)SendBuffer, "%s", str);
  16492. SendBufLen = strlen(str);
  16493. pthread_mutex_unlock(&lock_send);
  16494. lws_callback_on_writable(wsi_client);
  16495. //lws_service(context, 0);
  16496. //sleep(1);
  16497. }
  16498. void LWS_SendNow(char *str)
  16499. {
  16500. //=====================================================
  16501. // Check InternetConn 0: disconnected, 1: connected
  16502. //====================================================
  16503. if(GetOcppConnStatus() == 0)
  16504. {
  16505. DEBUG_INFO("offline now !!!\n");
  16506. return;
  16507. }
  16508. // Only disable isWebsocketSendable operation initiated by charger
  16509. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16510. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16511. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16512. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16513. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16514. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16515. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16516. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16517. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16518. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16519. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16520. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16521. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16522. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16523. {
  16524. isWebsocketSendable = 0;
  16525. }
  16526. pthread_mutex_lock(&lock_send);
  16527. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16528. sprintf((char *)SendBuffer, "%s", str);
  16529. SendBufLen = strlen(str);
  16530. pthread_mutex_unlock(&lock_send);
  16531. lws_callback_on_writable(wsi_client);
  16532. lws_service(context, 0);
  16533. //sleep(1);
  16534. }