MessageHandler.c 829 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933
  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. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1018. {
  1019. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1020. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1021. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1022. }
  1023. maxProfile.ChargingProfileId = -1;
  1024. maxProfile.StackLevel = -1;
  1025. while(getline(&line, &len, fp) != -1)
  1026. {
  1027. json_object *obj = NULL;
  1028. obj = json_tokener_parse(line);
  1029. if(is_error(obj))
  1030. {
  1031. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1032. }
  1033. else
  1034. {
  1035. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1036. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1037. )
  1038. {
  1039. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1040. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1041. )
  1042. {
  1043. struct tm tmFrom, tmTo;
  1044. struct timeb tbFrom, tbTo;
  1045. 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) &&
  1046. (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))
  1047. {
  1048. tmFrom.tm_year -= 1900;
  1049. tmFrom.tm_mon -= 1;
  1050. tbFrom.time = mktime(&tmFrom);
  1051. tmTo.tm_year -= 1900;
  1052. tmTo.tm_mon -= 1;
  1053. tbTo.time = mktime(&tmTo);
  1054. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1055. {
  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. if(maxProfile.ChargingProfileId == -1)
  1151. DEBUG_INFO("MaxProfile found.\n");
  1152. else
  1153. DEBUG_INFO("MaxProfile updated.\n");
  1154. // Required item
  1155. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1156. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1157. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1158. if(isUnitA)
  1159. {
  1160. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1161. 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++)
  1162. {
  1163. 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"));
  1164. 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?
  1165. 3:
  1166. 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")));
  1167. 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")));
  1168. }
  1169. }
  1170. else
  1171. {
  1172. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1173. 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++)
  1174. {
  1175. 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"));
  1176. 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?
  1177. 3:
  1178. 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")));
  1179. 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));
  1180. }
  1181. }
  1182. // Optional item
  1183. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1184. {
  1185. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1186. }
  1187. else
  1188. {
  1189. sprintf((char*)maxProfile.ValidFrom, " ");
  1190. }
  1191. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1192. {
  1193. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1194. }
  1195. else
  1196. {
  1197. sprintf((char*)maxProfile.ValidTo, " ");
  1198. }
  1199. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1200. {
  1201. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1202. }
  1203. else
  1204. {
  1205. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1206. }
  1207. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1208. {
  1209. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1210. }
  1211. else
  1212. {
  1213. maxProfile.TransactionId = -1;
  1214. }
  1215. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1216. {
  1217. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1218. }
  1219. else
  1220. {
  1221. maxProfile.ChargingSchedule.Duration = 86400;
  1222. }
  1223. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1224. {
  1225. 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")));
  1226. }
  1227. else
  1228. {
  1229. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", compositeProfile->ChargingSchedule.StartSchedule);
  1230. }
  1231. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1232. {
  1233. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1234. }
  1235. else
  1236. {
  1237. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1238. }
  1239. }
  1240. }
  1241. }
  1242. json_object_put(obj);
  1243. }
  1244. fclose(fp);
  1245. /*
  1246. if(maxProfile.ChargingProfileId !=-1)
  1247. {
  1248. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1249. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1250. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1251. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1252. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1253. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1254. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1255. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1256. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1257. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1258. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1259. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1260. {
  1261. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1262. {
  1263. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1264. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1265. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1266. }
  1267. }
  1268. }
  1269. else
  1270. DEBUG_INFO("MaxProfile not found.\n");
  1271. DEBUG_INFO("------------------------------------\n");*/
  1272. }
  1273. if(maxProfile.ChargingProfileId != -1)
  1274. {
  1275. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1276. {
  1277. if(maxProfile.ChargingSchedule.Duration != -1)
  1278. {
  1279. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1280. 0:
  1281. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1282. }
  1283. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1284. {
  1285. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1286. {
  1287. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1288. 0:
  1289. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1290. if(idxPeriod > 0)
  1291. {
  1292. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1293. {
  1294. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1295. }
  1296. }
  1297. }
  1298. }
  1299. }
  1300. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1301. {
  1302. if(maxProfile.ChargingSchedule.Duration != -1)
  1303. {
  1304. maxProfile.ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  1305. }
  1306. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1307. {
  1308. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1309. {
  1310. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod;
  1311. if(idxPeriod > 0)
  1312. {
  1313. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1314. {
  1315. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1316. }
  1317. }
  1318. }
  1319. }
  1320. }
  1321. else
  1322. {
  1323. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1324. {
  1325. if(maxProfile.ChargingSchedule.Duration != -1)
  1326. {
  1327. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1328. 0:
  1329. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1330. }
  1331. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1332. {
  1333. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1334. {
  1335. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1336. 0:
  1337. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1338. if(idxPeriod > 0)
  1339. {
  1340. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1341. {
  1342. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. else
  1349. {
  1350. if(maxProfile.ChargingSchedule.Duration != -1)
  1351. {
  1352. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1353. 0:
  1354. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1355. }
  1356. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1357. {
  1358. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1359. {
  1360. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1361. 0:
  1362. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1363. if(idxPeriod > 0)
  1364. {
  1365. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1366. {
  1367. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1368. }
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. /*
  1375. DEBUG_INFO("MaxProfile after align.\n");
  1376. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1377. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1378. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1379. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1380. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1381. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1382. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1383. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1384. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1385. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1386. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1387. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1388. {
  1389. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1390. {
  1391. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1392. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1393. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1394. }
  1395. }
  1396. DEBUG_INFO("------------------------------------\n");*/
  1397. }
  1398. // Find each profile period quantity
  1399. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1400. {
  1401. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1402. limitMax = idx+1;
  1403. }
  1404. if(maxProfile.ChargingProfileId != -1)
  1405. {
  1406. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1407. {
  1408. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1409. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1410. (maxProfile.ChargingSchedule.Duration > 0))
  1411. {
  1412. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1413. {
  1414. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1415. compositePeriodIdx++;
  1416. }
  1417. else
  1418. {
  1419. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1420. }
  1421. }
  1422. }
  1423. }
  1424. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  1425. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1426. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1427. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1428. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1429. {
  1430. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1431. {
  1432. compositeProfile->ChargingProfileId = 1;
  1433. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1434. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1435. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1436. }
  1437. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1438. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1439. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1440. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1441. }
  1442. if(line)
  1443. free(line);
  1444. }
  1445. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  1446. {
  1447. FILE *fp;
  1448. char profileFileName[128];
  1449. char *line = NULL;
  1450. size_t len = 0;
  1451. time_t CurrentTime;
  1452. struct tm *tmComposite;
  1453. struct StructChargingProfile maxProfile;
  1454. struct StructChargingProfile defaultTxProfile;
  1455. struct StructChargingProfile txProfile;
  1456. struct StructChargingSchedulePeriod tmpPeriod;
  1457. uint8_t limitMax=0;
  1458. uint8_t limitDef=0;
  1459. uint8_t limitTx=0;
  1460. int compositePeriodIdx = 0;
  1461. CurrentTime = time(NULL);
  1462. tmComposite=localtime(&CurrentTime);
  1463. 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);
  1464. if(isUnitA)
  1465. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  1466. else
  1467. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  1468. compositeProfile->ChargingSchedule.Duration = durationReq;
  1469. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1470. {
  1471. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1472. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1473. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1474. }
  1475. compositeProfile->ChargingProfileId = 0;
  1476. compositeProfile->StackLevel = 99 ;
  1477. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  1478. maxProfile.ChargingProfileId = -1;
  1479. defaultTxProfile.ChargingProfileId = -1;
  1480. txProfile.ChargingProfileId = -1;
  1481. maxProfile.ChargingSchedule.Duration = -1;
  1482. defaultTxProfile.ChargingSchedule.Duration = -1;
  1483. txProfile.ChargingSchedule.Duration = -1;
  1484. system("rm -f /tmp/*.json");
  1485. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  1486. /*
  1487. * Search valid charging profile
  1488. */
  1489. //DEBUG_INFO("====================================\n");
  1490. // Search tx profile
  1491. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1492. if((access(profileFileName, F_OK))!=-1)
  1493. {
  1494. fp = fopen(profileFileName, "r");
  1495. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1496. {
  1497. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1498. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1499. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1500. }
  1501. txProfile.ChargingProfileId = -1;
  1502. txProfile.StackLevel = -1;
  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. if(txProfile.ChargingProfileId == -1)
  1535. DEBUG_INFO("TxProfile found.\n");
  1536. else
  1537. DEBUG_INFO("TxProfile updated.\n");
  1538. // Required item
  1539. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1540. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1541. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1542. if(isUnitA)
  1543. {
  1544. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1545. 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++)
  1546. {
  1547. 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"));
  1548. 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?
  1549. 3:
  1550. 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")));
  1551. 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")));
  1552. }
  1553. }
  1554. else
  1555. {
  1556. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1557. 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++)
  1558. {
  1559. 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"));
  1560. 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?
  1561. 3:
  1562. 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")));
  1563. 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));
  1564. }
  1565. }
  1566. // Optional item
  1567. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1568. {
  1569. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1570. }
  1571. else
  1572. {
  1573. sprintf((char*)txProfile.ValidFrom, " ");
  1574. }
  1575. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1576. {
  1577. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1578. }
  1579. else
  1580. {
  1581. sprintf((char*)txProfile.ValidTo, " ");
  1582. }
  1583. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1584. {
  1585. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1586. }
  1587. else
  1588. {
  1589. sprintf((char*)txProfile.RecurrencyKind, " ");
  1590. }
  1591. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1592. {
  1593. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1594. }
  1595. else
  1596. {
  1597. txProfile.TransactionId = -1;
  1598. }
  1599. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1600. {
  1601. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1602. }
  1603. else
  1604. {
  1605. txProfile.ChargingSchedule.Duration = 86400;
  1606. }
  1607. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1608. {
  1609. 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")));
  1610. }
  1611. else
  1612. {
  1613. 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));
  1614. }
  1615. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1616. {
  1617. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1618. }
  1619. else
  1620. {
  1621. txProfile.ChargingSchedule.MinChargingRate = -1;
  1622. }
  1623. }
  1624. }
  1625. }
  1626. else
  1627. {
  1628. if(txProfile.ChargingProfileId == -1)
  1629. DEBUG_INFO("TxProfile found.\n");
  1630. else
  1631. DEBUG_INFO("TxProfile updated.\n");
  1632. // Required item
  1633. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1634. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1635. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1636. if(isUnitA)
  1637. {
  1638. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1639. 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++)
  1640. {
  1641. 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"));
  1642. 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?
  1643. 3:
  1644. 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")));
  1645. 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")));
  1646. }
  1647. }
  1648. else
  1649. {
  1650. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1651. 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++)
  1652. {
  1653. 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"));
  1654. 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?
  1655. 3:
  1656. 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")));
  1657. 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));
  1658. }
  1659. }
  1660. // Optional item
  1661. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1662. {
  1663. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1664. }
  1665. else
  1666. {
  1667. sprintf((char*)txProfile.ValidFrom, " ");
  1668. }
  1669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1670. {
  1671. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1672. }
  1673. else
  1674. {
  1675. sprintf((char*)txProfile.ValidTo, " ");
  1676. }
  1677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1678. {
  1679. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1680. }
  1681. else
  1682. {
  1683. sprintf((char*)txProfile.RecurrencyKind, " ");
  1684. }
  1685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1686. {
  1687. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1688. }
  1689. else
  1690. {
  1691. txProfile.TransactionId = -1;
  1692. }
  1693. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1694. {
  1695. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1696. }
  1697. else
  1698. {
  1699. txProfile.ChargingSchedule.Duration = 86400;
  1700. }
  1701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1702. {
  1703. 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")));
  1704. }
  1705. else
  1706. {
  1707. 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));
  1708. }
  1709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1710. {
  1711. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1712. }
  1713. else
  1714. {
  1715. txProfile.ChargingSchedule.MinChargingRate = -1;
  1716. }
  1717. }
  1718. }
  1719. }
  1720. json_object_put(obj);
  1721. }
  1722. fclose(fp);
  1723. /*
  1724. if(txProfile.ChargingProfileId != -1)
  1725. {
  1726. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1727. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1728. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1729. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1730. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1731. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1732. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1733. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1734. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1735. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1736. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1737. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1738. {
  1739. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1740. {
  1741. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1742. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1743. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1744. }
  1745. }
  1746. }
  1747. else
  1748. DEBUG_INFO("TxProfile not found.\n");*/
  1749. }
  1750. // Search default tx profile
  1751. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1752. if((access(profileFileName, F_OK))==-1)
  1753. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1754. if((access(profileFileName, F_OK))!=-1)
  1755. {
  1756. fp = fopen(profileFileName, "r");
  1757. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1758. {
  1759. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1760. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1761. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1762. }
  1763. defaultTxProfile.ChargingProfileId = -1;
  1764. defaultTxProfile.StackLevel = -1;
  1765. while(getline(&line, &len, fp) != -1)
  1766. {
  1767. json_object *obj = NULL;
  1768. obj = json_tokener_parse(line);
  1769. if(is_error(obj))
  1770. {
  1771. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1772. }
  1773. else
  1774. {
  1775. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1776. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1777. )
  1778. {
  1779. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1780. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1781. )
  1782. {
  1783. struct tm tmFrom, tmTo;
  1784. struct timeb tbFrom, tbTo;
  1785. 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) &&
  1786. (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))
  1787. {
  1788. tmFrom.tm_year -= 1900;
  1789. tmFrom.tm_mon -= 1;
  1790. tbFrom.time = mktime(&tmFrom);
  1791. tmTo.tm_year -= 1900;
  1792. tmTo.tm_mon -= 1;
  1793. tbTo.time = mktime(&tmTo);
  1794. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1795. {
  1796. if(defaultTxProfile.ChargingProfileId == -1)
  1797. DEBUG_INFO("TxDefaultProfile found.\n");
  1798. else
  1799. DEBUG_INFO("TxDefaultProfile updated.\n");
  1800. // Required item
  1801. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1802. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1803. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1804. if(isUnitA)
  1805. {
  1806. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1807. 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++)
  1808. {
  1809. 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"));
  1810. 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?
  1811. 3:
  1812. 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")));
  1813. 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")));
  1814. }
  1815. }
  1816. else
  1817. {
  1818. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1819. 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++)
  1820. {
  1821. 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"));
  1822. 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?
  1823. 3:
  1824. 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")));
  1825. 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));
  1826. }
  1827. }
  1828. // Optional item
  1829. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1830. {
  1831. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1832. }
  1833. else
  1834. {
  1835. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1836. }
  1837. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1838. {
  1839. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1840. }
  1841. else
  1842. {
  1843. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1844. }
  1845. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1846. {
  1847. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1848. }
  1849. else
  1850. {
  1851. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1852. }
  1853. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1854. {
  1855. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1856. }
  1857. else
  1858. {
  1859. defaultTxProfile.TransactionId = -1;
  1860. }
  1861. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1862. {
  1863. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1864. }
  1865. else
  1866. {
  1867. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1868. }
  1869. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1870. {
  1871. 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")));
  1872. }
  1873. else
  1874. {
  1875. 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));
  1876. }
  1877. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1878. {
  1879. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1880. }
  1881. else
  1882. {
  1883. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1884. }
  1885. }
  1886. }
  1887. }
  1888. else
  1889. {
  1890. if(defaultTxProfile.ChargingProfileId == -1)
  1891. DEBUG_INFO("TxDefaultProfile found.\n");
  1892. else
  1893. DEBUG_INFO("TxDefaultProfile updated.\n");
  1894. // Required item
  1895. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1896. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1897. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1898. if(isUnitA)
  1899. {
  1900. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1901. 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++)
  1902. {
  1903. 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"));
  1904. 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?
  1905. 3:
  1906. 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")));
  1907. 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")));
  1908. }
  1909. }
  1910. else
  1911. {
  1912. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1913. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1914. {
  1915. 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"));
  1916. 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?
  1917. 3:
  1918. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1919. 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));
  1920. }
  1921. }
  1922. // Optional item
  1923. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1924. {
  1925. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1926. }
  1927. else
  1928. {
  1929. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1930. }
  1931. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1932. {
  1933. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1934. }
  1935. else
  1936. {
  1937. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1938. }
  1939. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1940. {
  1941. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1942. }
  1943. else
  1944. {
  1945. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1946. }
  1947. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1948. {
  1949. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1950. }
  1951. else
  1952. {
  1953. defaultTxProfile.TransactionId = -1;
  1954. }
  1955. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1956. {
  1957. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1958. }
  1959. else
  1960. {
  1961. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1962. }
  1963. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1964. {
  1965. 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")));
  1966. }
  1967. else
  1968. {
  1969. 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));
  1970. }
  1971. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1972. {
  1973. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1974. }
  1975. else
  1976. {
  1977. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1978. }
  1979. }
  1980. }
  1981. }
  1982. json_object_put(obj);
  1983. }
  1984. fclose(fp);
  1985. /*
  1986. if(defaultTxProfile.ChargingProfileId != -1)
  1987. {
  1988. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1989. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1990. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1991. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1992. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1993. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1994. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1995. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1996. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1997. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1998. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1999. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2000. {
  2001. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2002. {
  2003. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2004. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2005. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2006. }
  2007. }
  2008. }
  2009. else
  2010. DEBUG_INFO("TxDefaultProfile not found.\n");
  2011. DEBUG_INFO("------------------------------------\n");*/
  2012. }
  2013. // Search max profile
  2014. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2015. if((access(profileFileName, F_OK))!=-1)
  2016. {
  2017. fp = fopen(profileFileName, "r");
  2018. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2019. {
  2020. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  2021. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  2022. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  2023. }
  2024. maxProfile.ChargingProfileId = -1;
  2025. maxProfile.StackLevel = -1;
  2026. while(getline(&line, &len, fp) != -1)
  2027. {
  2028. json_object *obj = NULL;
  2029. obj = json_tokener_parse(line);
  2030. if(is_error(obj))
  2031. {
  2032. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2033. }
  2034. else
  2035. {
  2036. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  2037. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  2038. )
  2039. {
  2040. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2041. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2042. )
  2043. {
  2044. struct tm tmFrom, tmTo;
  2045. struct timeb tbFrom, tbTo;
  2046. 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) &&
  2047. (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))
  2048. {
  2049. tmFrom.tm_year -= 1900;
  2050. tmFrom.tm_mon -= 1;
  2051. tbFrom.time = mktime(&tmFrom);
  2052. tmTo.tm_year -= 1900;
  2053. tmTo.tm_mon -= 1;
  2054. tbTo.time = mktime(&tmTo);
  2055. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2056. {
  2057. if(maxProfile.ChargingProfileId == -1)
  2058. DEBUG_INFO("MaxProfile found.\n");
  2059. else
  2060. DEBUG_INFO("MaxProfile updated.\n");
  2061. // Required item
  2062. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2063. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2064. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2065. if(isUnitA)
  2066. {
  2067. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2068. 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++)
  2069. {
  2070. 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"));
  2071. 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?
  2072. 3:
  2073. 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")));
  2074. 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")));
  2075. }
  2076. }
  2077. else
  2078. {
  2079. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2080. 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++)
  2081. {
  2082. 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"));
  2083. 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?
  2084. 3:
  2085. 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")));
  2086. 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));
  2087. }
  2088. }
  2089. // Optional item
  2090. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2091. {
  2092. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2093. }
  2094. else
  2095. {
  2096. sprintf((char*)maxProfile.ValidFrom, " ");
  2097. }
  2098. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2099. {
  2100. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2101. }
  2102. else
  2103. {
  2104. sprintf((char*)maxProfile.ValidTo, " ");
  2105. }
  2106. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2107. {
  2108. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2109. }
  2110. else
  2111. {
  2112. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2113. }
  2114. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2115. {
  2116. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2117. }
  2118. else
  2119. {
  2120. maxProfile.TransactionId = -1;
  2121. }
  2122. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2123. {
  2124. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2125. }
  2126. else
  2127. {
  2128. maxProfile.ChargingSchedule.Duration = 86400;
  2129. }
  2130. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2131. {
  2132. 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")));
  2133. }
  2134. else
  2135. {
  2136. 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));
  2137. }
  2138. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2139. {
  2140. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2141. }
  2142. else
  2143. {
  2144. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2145. }
  2146. }
  2147. }
  2148. }
  2149. else
  2150. {
  2151. if(maxProfile.ChargingProfileId == -1)
  2152. DEBUG_INFO("MaxProfile found.\n");
  2153. else
  2154. DEBUG_INFO("MaxProfile updated.\n");
  2155. // Required item
  2156. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2157. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2158. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2159. if(isUnitA)
  2160. {
  2161. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  2162. 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++)
  2163. {
  2164. 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"));
  2165. 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?
  2166. 3:
  2167. 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")));
  2168. 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")));
  2169. }
  2170. }
  2171. else
  2172. {
  2173. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  2174. 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++)
  2175. {
  2176. 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"));
  2177. 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?
  2178. 3:
  2179. 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")));
  2180. 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));
  2181. }
  2182. }
  2183. // Optional item
  2184. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2185. {
  2186. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2187. }
  2188. else
  2189. {
  2190. sprintf((char*)maxProfile.ValidFrom, " ");
  2191. }
  2192. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2193. {
  2194. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2195. }
  2196. else
  2197. {
  2198. sprintf((char*)maxProfile.ValidTo, " ");
  2199. }
  2200. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2201. {
  2202. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2203. }
  2204. else
  2205. {
  2206. sprintf((char*)maxProfile.RecurrencyKind, " ");
  2207. }
  2208. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2209. {
  2210. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  2211. }
  2212. else
  2213. {
  2214. maxProfile.TransactionId = -1;
  2215. }
  2216. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2217. {
  2218. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2219. }
  2220. else
  2221. {
  2222. maxProfile.ChargingSchedule.Duration = 86400;
  2223. }
  2224. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2225. {
  2226. 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")));
  2227. }
  2228. else
  2229. {
  2230. 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));
  2231. }
  2232. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2233. {
  2234. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2235. }
  2236. else
  2237. {
  2238. maxProfile.ChargingSchedule.MinChargingRate = -1;
  2239. }
  2240. }
  2241. }
  2242. }
  2243. json_object_put(obj);
  2244. }
  2245. fclose(fp);
  2246. /*
  2247. if(maxProfile.ChargingProfileId !=-1)
  2248. {
  2249. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2250. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2251. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2252. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2253. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2254. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2255. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2256. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  2257. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2258. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2259. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2260. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2261. {
  2262. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2263. {
  2264. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2265. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2266. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2267. }
  2268. }
  2269. }
  2270. else
  2271. DEBUG_INFO("MaxProfile not found.\n");
  2272. DEBUG_INFO("------------------------------------\n");*/
  2273. }
  2274. /*
  2275. * Align found profile start schedule & periods
  2276. */
  2277. //DEBUG_INFO("====================================\n");
  2278. /*
  2279. // For local test usage, force modify found profile start schedule info
  2280. 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);
  2281. 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);
  2282. 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);
  2283. */
  2284. if(txProfile.ChargingProfileId != -1)
  2285. {
  2286. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  2287. {
  2288. if(txProfile.ChargingSchedule.Duration != -1)
  2289. {
  2290. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2291. 0:
  2292. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2293. }
  2294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2295. {
  2296. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2297. {
  2298. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2299. 0:
  2300. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2301. if(idxPeriod > 0)
  2302. {
  2303. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2304. {
  2305. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  2312. {
  2313. if(txProfile.ChargingSchedule.Duration != -1)
  2314. {
  2315. 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?
  2316. 0:
  2317. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2318. }
  2319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2320. {
  2321. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2322. {
  2323. 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?
  2324. 0:
  2325. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2326. if(idxPeriod > 0)
  2327. {
  2328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2329. {
  2330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2331. }
  2332. }
  2333. }
  2334. }
  2335. }
  2336. else
  2337. {
  2338. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  2339. {
  2340. if(txProfile.ChargingSchedule.Duration != -1)
  2341. {
  2342. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2343. 0:
  2344. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2345. }
  2346. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2347. {
  2348. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2349. {
  2350. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2351. 0:
  2352. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2353. if(idxPeriod > 0)
  2354. {
  2355. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2356. {
  2357. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. else
  2364. {
  2365. if(txProfile.ChargingSchedule.Duration != -1)
  2366. {
  2367. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2368. 0:
  2369. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2370. }
  2371. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2372. {
  2373. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2374. {
  2375. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2376. 0:
  2377. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2378. if(idxPeriod > 0)
  2379. {
  2380. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2381. {
  2382. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2383. }
  2384. }
  2385. }
  2386. }
  2387. }
  2388. }
  2389. /*
  2390. DEBUG_INFO("txProfile after align.\n");
  2391. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  2392. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  2393. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  2394. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  2395. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  2396. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  2397. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  2398. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2399. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  2400. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  2401. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  2402. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2403. {
  2404. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2405. {
  2406. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2407. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2408. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2409. }
  2410. }*/
  2411. }
  2412. if(defaultTxProfile.ChargingProfileId != -1)
  2413. {
  2414. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  2415. {
  2416. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2417. {
  2418. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2419. 0:
  2420. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2421. }
  2422. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2423. {
  2424. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2425. {
  2426. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2427. 0:
  2428. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2429. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2430. {
  2431. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2432. }
  2433. if(idxPeriod > 0)
  2434. {
  2435. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2436. {
  2437. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  2444. {
  2445. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2446. {
  2447. 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?
  2448. 0:
  2449. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2450. }
  2451. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2452. {
  2453. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2454. {
  2455. 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?
  2456. 0:
  2457. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2458. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2459. {
  2460. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2461. }
  2462. if(idxPeriod > 0)
  2463. {
  2464. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2465. {
  2466. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2467. }
  2468. }
  2469. }
  2470. }
  2471. }
  2472. else
  2473. {
  2474. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  2475. {
  2476. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2477. {
  2478. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2479. 0:
  2480. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2481. }
  2482. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2483. {
  2484. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2485. {
  2486. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2487. 0:
  2488. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2489. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2490. {
  2491. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2492. }
  2493. if(idxPeriod > 0)
  2494. {
  2495. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2496. {
  2497. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2498. }
  2499. }
  2500. }
  2501. }
  2502. }
  2503. else
  2504. {
  2505. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  2506. {
  2507. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2508. 0:
  2509. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2510. }
  2511. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2512. {
  2513. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2514. {
  2515. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2516. 0:
  2517. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2518. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  2519. {
  2520. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2521. }
  2522. if(idxPeriod > 0)
  2523. {
  2524. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2525. {
  2526. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2527. }
  2528. }
  2529. }
  2530. }
  2531. }
  2532. }
  2533. /*
  2534. DEBUG_INFO("defaultTxProfile after align.\n");
  2535. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  2536. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  2537. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  2538. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  2539. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  2540. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  2541. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  2542. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2543. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2544. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2545. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2547. {
  2548. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2549. {
  2550. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2551. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2552. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2553. }
  2554. }
  2555. DEBUG_INFO("------------------------------------\n");*/
  2556. }
  2557. if(maxProfile.ChargingProfileId != -1)
  2558. {
  2559. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2560. {
  2561. if(maxProfile.ChargingSchedule.Duration != -1)
  2562. {
  2563. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2564. 0:
  2565. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2566. }
  2567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2568. {
  2569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2570. {
  2571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2572. 0:
  2573. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2574. if(idxPeriod > 0)
  2575. {
  2576. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2577. {
  2578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2585. {
  2586. if(maxProfile.ChargingSchedule.Duration != -1)
  2587. {
  2588. 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?
  2589. 0:
  2590. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2591. }
  2592. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2593. {
  2594. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2595. {
  2596. 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?
  2597. 0:
  2598. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2599. if(idxPeriod > 0)
  2600. {
  2601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2602. {
  2603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2604. }
  2605. }
  2606. }
  2607. }
  2608. }
  2609. else
  2610. {
  2611. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2612. {
  2613. if(maxProfile.ChargingSchedule.Duration != -1)
  2614. {
  2615. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2616. 0:
  2617. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2618. }
  2619. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2620. {
  2621. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2622. {
  2623. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2624. 0:
  2625. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2626. if(idxPeriod > 0)
  2627. {
  2628. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2629. {
  2630. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2631. }
  2632. }
  2633. }
  2634. }
  2635. }
  2636. else
  2637. {
  2638. if(maxProfile.ChargingSchedule.Duration != -1)
  2639. {
  2640. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2641. 0:
  2642. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2643. }
  2644. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2645. {
  2646. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2647. {
  2648. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2649. 0:
  2650. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2651. if(idxPeriod > 0)
  2652. {
  2653. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2654. {
  2655. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. /*
  2663. DEBUG_INFO("MaxProfile after align.\n");
  2664. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2665. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2666. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2667. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2668. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2669. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2670. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2671. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2672. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2673. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2674. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2675. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2676. {
  2677. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2678. {
  2679. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2680. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2681. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2682. }
  2683. }
  2684. DEBUG_INFO("------------------------------------\n");*/
  2685. }
  2686. /*
  2687. * Merge to conposite schedule
  2688. */
  2689. //DEBUG_INFO("====================================\n");
  2690. // Find each profile period quantity
  2691. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2692. {
  2693. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2694. limitMax = idx+1;
  2695. }
  2696. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2697. {
  2698. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2699. limitDef = idx+1;
  2700. }
  2701. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2702. {
  2703. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2704. limitTx = idx+1;
  2705. }
  2706. // TxProfile found, composite schedule based on it
  2707. if(txProfile.ChargingProfileId != -1)
  2708. {
  2709. compositeProfile->ChargingSchedule.Duration = txProfile.ChargingSchedule.Duration;
  2710. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2711. {
  2712. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2713. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2714. (txProfile.ChargingSchedule.Duration > 0))
  2715. {
  2716. if(maxProfile.ChargingProfileId != -1)
  2717. {
  2718. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2719. {
  2720. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2721. {
  2722. if((maxProfile.ChargingSchedule.Duration > 0))
  2723. {
  2724. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2725. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2726. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2727. }
  2728. else
  2729. {
  2730. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2731. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2732. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2733. }
  2734. }
  2735. if(idxMaxPeriod == (limitMax-1))
  2736. {
  2737. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2738. {
  2739. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2740. {
  2741. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2742. compositePeriodIdx++;
  2743. }
  2744. else
  2745. {
  2746. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2747. }
  2748. }
  2749. }
  2750. }
  2751. }
  2752. else
  2753. {
  2754. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2755. {
  2756. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2757. compositePeriodIdx++;
  2758. }
  2759. else
  2760. {
  2761. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2762. }
  2763. }
  2764. }
  2765. if(idxTxPeriod == (limitTx-1))
  2766. {
  2767. if(defaultTxProfile.ChargingProfileId != -1)
  2768. {
  2769. compositeProfile->ChargingSchedule.Duration = (defaultTxProfile.ChargingSchedule.Duration>compositeProfile->ChargingSchedule.Duration)?defaultTxProfile.ChargingSchedule.Duration:compositeProfile->ChargingSchedule.Duration;
  2770. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2771. {
  2772. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2773. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2774. (defaultTxProfile.ChargingSchedule.Duration>0))
  2775. {
  2776. if(maxProfile.ChargingProfileId != -1)
  2777. {
  2778. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2779. {
  2780. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2781. {
  2782. if((maxProfile.ChargingSchedule.Duration > 0))
  2783. {
  2784. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2785. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2786. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2787. }
  2788. else
  2789. {
  2790. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2791. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2792. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2793. }
  2794. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2795. {
  2796. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2797. {
  2798. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2799. compositePeriodIdx++;
  2800. }
  2801. else
  2802. {
  2803. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2804. }
  2805. }
  2806. // Delete duplicate period
  2807. if(compositePeriodIdx > 1)
  2808. {
  2809. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2810. {
  2811. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2812. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2813. compositePeriodIdx -= 1;
  2814. }
  2815. }
  2816. }
  2817. else
  2818. {
  2819. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2820. {
  2821. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2822. compositePeriodIdx++;
  2823. }
  2824. else
  2825. {
  2826. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2827. }
  2828. break;
  2829. }
  2830. }
  2831. }
  2832. else
  2833. {
  2834. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2835. {
  2836. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2837. compositePeriodIdx++;
  2838. }
  2839. else
  2840. {
  2841. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2842. }
  2843. }
  2844. }
  2845. }
  2846. }
  2847. }
  2848. }
  2849. }
  2850. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2851. else if(defaultTxProfile.ChargingProfileId != -1)
  2852. {
  2853. compositeProfile->ChargingSchedule.Duration = defaultTxProfile.ChargingSchedule.Duration;
  2854. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2855. {
  2856. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2857. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2858. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2859. {
  2860. if(maxProfile.ChargingProfileId != -1)
  2861. {
  2862. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2863. {
  2864. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2865. {
  2866. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2867. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2868. if((maxProfile.ChargingSchedule.Duration > 0))
  2869. {
  2870. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2871. }
  2872. else
  2873. {
  2874. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2875. }
  2876. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2877. {
  2878. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2879. {
  2880. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2881. compositePeriodIdx++;
  2882. }
  2883. else
  2884. {
  2885. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2886. }
  2887. }
  2888. // Delete duplicate period
  2889. if(compositePeriodIdx > 1)
  2890. {
  2891. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2892. {
  2893. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2894. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2895. compositePeriodIdx -= 1;
  2896. }
  2897. }
  2898. }
  2899. else
  2900. {
  2901. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2902. {
  2903. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2904. compositePeriodIdx++;
  2905. }
  2906. else
  2907. {
  2908. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2909. }
  2910. break;
  2911. }
  2912. }
  2913. }
  2914. else
  2915. {
  2916. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2917. {
  2918. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2919. compositePeriodIdx++;
  2920. }
  2921. else
  2922. {
  2923. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2924. }
  2925. }
  2926. }
  2927. }
  2928. }
  2929. // Fill other period by MaxProfile
  2930. if(maxProfile.ChargingProfileId != -1)
  2931. {
  2932. if(compositePeriodIdx==0)
  2933. {
  2934. compositeProfile->ChargingSchedule.Duration = maxProfile.ChargingSchedule.Duration;
  2935. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  2936. {
  2937. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2938. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2939. (maxProfile.ChargingSchedule.Duration > 0))
  2940. {
  2941. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2942. {
  2943. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2944. compositePeriodIdx++;
  2945. }
  2946. else
  2947. {
  2948. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2949. }
  2950. }
  2951. }
  2952. }
  2953. else
  2954. {
  2955. int lastCompositePeriodIdx = compositePeriodIdx;
  2956. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2957. {
  2958. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2959. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2960. (maxProfile.ChargingSchedule.Duration > 0))
  2961. {
  2962. if((maxProfile.ChargingSchedule.Duration >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod))
  2963. {
  2964. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit)
  2965. {
  2966. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  2967. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2968. tmpPeriod.Limit = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[lastCompositePeriodIdx-1].Limit;
  2969. }
  2970. else
  2971. {
  2972. tmpPeriod.StartPeriod = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod;
  2973. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2974. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2975. }
  2976. }
  2977. if(tmpPeriod.Limit != -1)
  2978. {
  2979. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit)
  2980. {
  2981. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)
  2982. {
  2983. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2984. compositePeriodIdx++;
  2985. }
  2986. else
  2987. {
  2988. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2989. }
  2990. }
  2991. // Delete duplicate period
  2992. if(compositePeriodIdx > 1)
  2993. {
  2994. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2995. {
  2996. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2997. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2998. compositePeriodIdx -= 1;
  2999. }
  3000. }
  3001. }
  3002. }
  3003. }
  3004. }
  3005. }
  3006. compositeProfile->ChargingSchedule.Duration = durationReq;
  3007. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  3008. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3009. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  3010. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  3011. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  3012. {
  3013. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3014. {
  3015. compositeProfile->ChargingProfileId = 1;
  3016. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3017. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  3018. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3019. }
  3020. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  3021. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  3022. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  3023. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  3024. }
  3025. if(line)
  3026. free(line);
  3027. checkChargePointMaxProfile(durationReq, &ShmOCPP16DataPH->MaxChargingProfile, isUnitA);
  3028. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  3029. }
  3030. //==========================================
  3031. // Init all share memory
  3032. //==========================================
  3033. int InitShareMemory()
  3034. {
  3035. int result = PASS;
  3036. int MeterSMId;
  3037. //creat ShmSysConfigAndInfo
  3038. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  3039. {
  3040. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  3041. result = FAIL;
  3042. }
  3043. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3044. {
  3045. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  3046. result = FAIL;
  3047. }
  3048. else
  3049. {}
  3050. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  3051. {
  3052. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  3053. result = FAIL;
  3054. }
  3055. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3056. {
  3057. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  3058. result = FAIL;
  3059. }
  3060. else
  3061. {}
  3062. //creat ShmPsuData
  3063. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  3064. {
  3065. DEBUG_ERROR("shmget ShmPsuData NG\n");
  3066. result = FAIL;
  3067. }
  3068. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3069. {
  3070. DEBUG_ERROR("shmat ShmPsuData NG\n");
  3071. result = FAIL;
  3072. }
  3073. else
  3074. {}
  3075. //link ShmOCPP16Data
  3076. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  3077. {
  3078. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  3079. result = FAIL;
  3080. }
  3081. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3082. {
  3083. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  3084. result = FAIL;
  3085. }
  3086. else
  3087. {}
  3088. //creat ShmOCPP16DataPH
  3089. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  3090. {
  3091. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  3092. result = FAIL;
  3093. }
  3094. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  3095. {
  3096. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  3097. result = FAIL;
  3098. }
  3099. else
  3100. {}
  3101. /****************************** For Initial Settings************************************************/
  3102. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  3103. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  3104. // allocate Configuration memory address
  3105. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  3106. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  3107. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  3108. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  3109. //offline MeterValue Interval
  3110. TempMeterValueInterval = 0;
  3111. return result;
  3112. }
  3113. int ProcessShareMemory()
  3114. {
  3115. if(InitShareMemory() == FAIL)
  3116. {
  3117. DEBUG_ERROR("InitShareMemory NG\n");
  3118. if(ShmStatusCodeData!=NULL)
  3119. {
  3120. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3121. }
  3122. sleep(5);
  3123. return FAIL;
  3124. }
  3125. return PASS;
  3126. }
  3127. void CheckSystemValue(void)
  3128. {
  3129. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  3130. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  3131. char filenmae[100]={0};
  3132. char str[100]={0};
  3133. int tempIndex = 0;
  3134. //===============================
  3135. // send Heartbeat
  3136. //===============================
  3137. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3138. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  3139. {
  3140. clientTime.Heartbeat=time((time_t*)NULL);
  3141. if(server_sign == TRUE)
  3142. {
  3143. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  3144. }
  3145. else
  3146. {
  3147. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  3148. }
  3149. }
  3150. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  3151. {
  3152. //parameter for test
  3153. sendHeartbeatRequest(0);
  3154. //==============================================
  3155. // Reset Waiting Time
  3156. //==============================================
  3157. HeartBeatWithNOResponse += 2;
  3158. }
  3159. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  3160. {
  3161. //==========================================
  3162. // csu trigger DataTransferReq
  3163. //==========================================
  3164. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  3165. {
  3166. sendDataTransferRequest(gun_index);
  3167. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  3168. }
  3169. //===============================
  3170. // CSU Trigger Authorize Request
  3171. //===============================
  3172. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  3173. {
  3174. sendAuthorizeRequest(0);
  3175. authorizeRetryTimes = authorizeRetryTimes + 1;
  3176. if(authorizeRetryTimes < 3)
  3177. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3178. }
  3179. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  3180. {
  3181. authorizeRetryTimes = 0;
  3182. SetOcppConnStatus(FALSE);
  3183. server_sign = FALSE;
  3184. }
  3185. 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))
  3186. {
  3187. sendAuthorizeRequest(0);
  3188. }
  3189. //==============================================
  3190. // Charger start transaction
  3191. //==============================================
  3192. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  3193. {
  3194. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  3195. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  3196. sendStartTransactionRequest(gun_index);
  3197. clientTime.StartTransaction = time((time_t*)NULL);
  3198. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3199. storeTempStopTransaction(gun_index);
  3200. }
  3201. //==============================================
  3202. // Charger stop transaction
  3203. //==============================================
  3204. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  3205. {
  3206. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3207. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  3208. sendStopTransactionRequest(gun_index);
  3209. clientTime.StopTransaction = time((time_t*)NULL);
  3210. }
  3211. //==============================================
  3212. // Charger status report
  3213. //==============================================
  3214. //--- Check Mode Change ---//
  3215. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3216. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3217. {
  3218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3219. {
  3220. tempIndex = ((gun_index==2) ? 1: 0);
  3221. }
  3222. else
  3223. {
  3224. tempIndex = gun_index;
  3225. }
  3226. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3227. {
  3228. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3229. {
  3230. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  3231. {
  3232. // Sent unplug message for California pricing logic
  3233. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  3234. {
  3235. uint8_t ts[20];
  3236. getNowDatetime(ts);
  3237. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3238. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3239. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3240. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3241. }
  3242. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  3243. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  3244. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3245. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3246. {
  3247. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3248. if((access(filenmae,F_OK))!=-1)
  3249. {
  3250. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3251. sprintf(str,"rm -f %s",filenmae);
  3252. system(str);
  3253. }
  3254. }
  3255. }
  3256. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3257. #if 1 // for TempStopTransaction
  3258. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3259. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3260. {
  3261. checkTempStopTransaction(gun_index);
  3262. }
  3263. #endif
  3264. }
  3265. }
  3266. }
  3267. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3268. {
  3269. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3270. {
  3271. tempIndex = ((gun_index==2) ? 1: 0);
  3272. }
  3273. else
  3274. {
  3275. tempIndex = gun_index;
  3276. }
  3277. for (int index = 0; index < CCS_QUANTITY; index++)
  3278. {
  3279. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3280. {
  3281. 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]*/ )
  3282. {
  3283. // Sent unplug message for California pricing logic
  3284. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  3285. {
  3286. uint8_t ts[20];
  3287. getNowDatetime(ts);
  3288. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3289. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3290. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3291. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3292. }
  3293. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  3294. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  3295. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3296. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3297. {
  3298. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3299. if((access(filenmae,F_OK))!=-1)
  3300. {
  3301. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3302. sprintf(str,"rm -f %s",filenmae);
  3303. system(str);
  3304. }
  3305. }
  3306. }
  3307. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3308. #if 1 // for TempStopTransaction
  3309. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3310. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3311. {
  3312. checkTempStopTransaction(gun_index);
  3313. }
  3314. #endif
  3315. }
  3316. }
  3317. }
  3318. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3319. {
  3320. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3321. {
  3322. tempIndex = ((gun_index==2) ? 1: 0);
  3323. }
  3324. else
  3325. {
  3326. tempIndex = gun_index;
  3327. }
  3328. for (int index = 0; index < GB_QUANTITY; index++)
  3329. {
  3330. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3331. {
  3332. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  3333. {
  3334. // Sent unplug message for California pricing logic
  3335. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  3336. {
  3337. uint8_t ts[20];
  3338. getNowDatetime(ts);
  3339. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3340. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3341. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3342. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3343. }
  3344. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  3345. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  3346. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3347. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3348. {
  3349. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3350. if((access(filenmae,F_OK))!=-1)
  3351. {
  3352. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3353. sprintf(str,"rm -f %s",filenmae);
  3354. system(str);
  3355. }
  3356. }
  3357. }
  3358. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3359. #if 1 // for TempStopTransaction
  3360. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3361. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3362. {
  3363. checkTempStopTransaction(gun_index);
  3364. }
  3365. #endif
  3366. }
  3367. }
  3368. }
  3369. else if(gunType[gun_index] == GUN_TYPE_DO)
  3370. {
  3371. tempIndex = gun_index;
  3372. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3373. {
  3374. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3375. {
  3376. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  3377. {
  3378. // Sent unplug message for California pricing logic
  3379. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  3380. {
  3381. uint8_t ts[20];
  3382. getNowDatetime(ts);
  3383. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3384. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3385. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3386. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3387. }
  3388. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  3389. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  3390. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3391. 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
  3392. {
  3393. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3394. if((access(filenmae,F_OK))!=-1)
  3395. {
  3396. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3397. sprintf(str,"rm -f %s",filenmae);
  3398. system(str);
  3399. }
  3400. }
  3401. }
  3402. 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);
  3403. #if 1 // for TempStopTransaction
  3404. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  3405. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3406. {
  3407. checkTempStopTransaction(gun_index);
  3408. }
  3409. #endif
  3410. }
  3411. }
  3412. }
  3413. else
  3414. {
  3415. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3416. {
  3417. tempIndex = 2;
  3418. }
  3419. else
  3420. {
  3421. tempIndex = gun_index;
  3422. }
  3423. for (int index = 0; index < AC_QUANTITY; index++)
  3424. {
  3425. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3426. {
  3427. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  3428. {
  3429. // Sent unplug message for California pricing logic
  3430. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  3431. {
  3432. uint8_t ts[20];
  3433. getNowDatetime(ts);
  3434. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3435. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  3436. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  3437. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  3438. }
  3439. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  3440. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  3441. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  3442. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  3443. {
  3444. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  3445. if((access(filenmae,F_OK))!=-1)
  3446. {
  3447. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  3448. sprintf(str,"rm -f %s",filenmae);
  3449. system(str);
  3450. }
  3451. }
  3452. }
  3453. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  3454. #if 1 // for TempStopTransaction
  3455. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  3456. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  3457. {
  3458. checkTempStopTransaction(gun_index);
  3459. }
  3460. #endif
  3461. }
  3462. }// END
  3463. }
  3464. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  3465. (
  3466. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  3467. )
  3468. )
  3469. {
  3470. if(SystemInitial > 0)
  3471. SystemInitial -= 1;
  3472. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  3473. sendStatusNotificationRequest(gun_index);
  3474. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  3475. }
  3476. //==============================================
  3477. // CSU Trigger Smart Charging Profilw
  3478. //==============================================
  3479. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  3480. {
  3481. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  3482. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  3483. }
  3484. //==============================================
  3485. // Meter report
  3486. //==============================================
  3487. // Trigger MeterValue
  3488. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  3489. {
  3490. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  3491. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  3492. }
  3493. // ClockAlign MeterValue
  3494. 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))
  3495. {
  3496. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3497. {
  3498. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3499. {
  3500. tempIndex = ((gun_index==2) ? 1: 0);
  3501. }
  3502. else
  3503. {
  3504. tempIndex = gun_index;
  3505. }
  3506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3507. {
  3508. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3509. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3510. {
  3511. reqClockAlignMeter[gun_index] = 1;
  3512. }
  3513. }// End for CHAdeMO
  3514. }
  3515. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3516. {
  3517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3518. {
  3519. tempIndex = ((gun_index==2) ? 1: 0);
  3520. }
  3521. else
  3522. {
  3523. tempIndex = gun_index;
  3524. }
  3525. for (int index = 0; index < CCS_QUANTITY; index++)
  3526. {
  3527. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3528. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3529. {
  3530. reqClockAlignMeter[gun_index] = 1;
  3531. }
  3532. } // End for CCS
  3533. }
  3534. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3535. {
  3536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3537. {
  3538. tempIndex = ((gun_index==2) ? 1: 0);
  3539. }
  3540. else
  3541. {
  3542. tempIndex = gun_index;
  3543. }
  3544. for (int index = 0; index < GB_QUANTITY; index++)
  3545. {
  3546. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3547. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3548. {
  3549. reqClockAlignMeter[gun_index] = 1;
  3550. }
  3551. }// End for GB
  3552. }
  3553. else if(gunType[gun_index] == GUN_TYPE_DO)
  3554. {
  3555. tempIndex = gun_index;
  3556. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3557. {
  3558. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3559. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3560. {
  3561. reqClockAlignMeter[gun_index] = 1;
  3562. }
  3563. }
  3564. }
  3565. else
  3566. {
  3567. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3568. {
  3569. tempIndex = 2;
  3570. }
  3571. else
  3572. {
  3573. tempIndex = gun_index;
  3574. }
  3575. for (int index = 0; index < AC_QUANTITY; index++)
  3576. {
  3577. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3578. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3579. {
  3580. reqClockAlignMeter[gun_index] = 1;
  3581. }
  3582. }//End for AC
  3583. }
  3584. if(reqClockAlignMeter[gun_index] == 1)
  3585. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  3586. }
  3587. // Sample period MeterValue
  3588. 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))))
  3589. {
  3590. //check Transaction active
  3591. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3592. {
  3593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3594. {
  3595. tempIndex = ((gun_index==2) ? 1: 0);
  3596. }
  3597. else
  3598. {
  3599. tempIndex = gun_index;
  3600. }
  3601. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3602. {
  3603. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3604. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3605. {
  3606. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3607. {
  3608. reqSampleMeter[gun_index] = 1;
  3609. }
  3610. }
  3611. }// End for CHAdeMO
  3612. }
  3613. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3614. {
  3615. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3616. {
  3617. tempIndex = ((gun_index==2) ? 1: 0);
  3618. }
  3619. else
  3620. {
  3621. tempIndex = gun_index;
  3622. }
  3623. for (int index = 0; index < CCS_QUANTITY; index++)
  3624. {
  3625. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3626. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3627. {
  3628. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3629. {
  3630. reqSampleMeter[gun_index] = 1;
  3631. }
  3632. }
  3633. } // End for CCS
  3634. }
  3635. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3636. {
  3637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3638. {
  3639. tempIndex = ((gun_index==2) ? 1: 0);
  3640. }
  3641. else
  3642. {
  3643. tempIndex = gun_index;
  3644. }
  3645. for (int index = 0; index < GB_QUANTITY; index++)
  3646. {
  3647. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3648. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3649. {
  3650. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3651. {
  3652. reqSampleMeter[gun_index] = 1;
  3653. }
  3654. }
  3655. }// End for GB
  3656. }
  3657. else if(gunType[gun_index] == GUN_TYPE_DO)
  3658. {
  3659. tempIndex = gun_index;
  3660. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3661. {
  3662. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3663. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3664. {
  3665. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3666. {
  3667. reqSampleMeter[gun_index] = 1;
  3668. }
  3669. }
  3670. }
  3671. }
  3672. else
  3673. {
  3674. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3675. {
  3676. tempIndex = 2;
  3677. }
  3678. else
  3679. {
  3680. tempIndex = gun_index;
  3681. }
  3682. for (int index = 0; index < AC_QUANTITY; index++)
  3683. {
  3684. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3685. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3686. {
  3687. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3688. {
  3689. reqSampleMeter[gun_index] = 1;
  3690. }
  3691. }
  3692. }//End for AC
  3693. }
  3694. if(reqSampleMeter[gun_index] == 1)
  3695. {
  3696. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3697. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3698. storeTempStopTransaction(gun_index);
  3699. }
  3700. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3701. }
  3702. //==============================================
  3703. // Check Connector reserved
  3704. //==============================================
  3705. //===============================
  3706. // Check if Reserve is expired
  3707. //===============================
  3708. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3709. {
  3710. double diff_t;
  3711. struct tm tp;
  3712. // current time
  3713. time_t t = time(NULL);
  3714. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3715. tp.tm_isdst = -1;
  3716. time_t utc = mktime(&tp);
  3717. diff_t = difftime(utc, t);
  3718. if(diff_t <= 0)
  3719. {
  3720. DEBUG_INFO("reserve expired.\n");
  3721. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3722. }
  3723. }//END OF Check if Reserve is expired
  3724. //==========================================
  3725. // csu trigger FirmwareStatusNotificationReq
  3726. //==========================================
  3727. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3728. {
  3729. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3730. }
  3731. //==========================================
  3732. // csu trigger DiagnosticsStatusNotificationReq
  3733. //==========================================
  3734. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3735. {
  3736. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3737. }
  3738. //==========================================
  3739. // csu trigger CancelReservationConf
  3740. //==========================================
  3741. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3742. {
  3743. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3744. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3745. }
  3746. //==========================================
  3747. // csu trigger ChangeAvailabilityConf
  3748. //==========================================
  3749. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3750. {
  3751. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3752. }
  3753. //==========================================
  3754. // csu trigger UnlockConnectorConf
  3755. //==========================================
  3756. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3757. {
  3758. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3759. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3760. }
  3761. //==========================================
  3762. // csu trigger ReserveNowConf
  3763. //==========================================
  3764. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3765. {
  3766. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3767. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3768. }
  3769. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3770. {
  3771. sendSignCertificateRequest();
  3772. }
  3773. }
  3774. }
  3775. //==========================================
  3776. // send request routine
  3777. //==========================================
  3778. int sendAuthorizeRequest(int gun_index)
  3779. {
  3780. mtrace();
  3781. int result = FAIL;
  3782. char message[100]={0};
  3783. char guid[37];
  3784. char tempdata[65]={0};
  3785. DEBUG_INFO("sendAuthorizeRequest...\n");
  3786. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3787. //Local Authorize
  3788. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3789. {
  3790. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3791. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3792. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3793. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3794. result = PASS;
  3795. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3796. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3797. authorizeRetryTimes = 0;
  3798. return result;
  3799. }
  3800. 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))||
  3801. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3802. {
  3803. // Query from cache
  3804. DEBUG_INFO("Authorize from cache.\n");
  3805. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3806. // Query from list
  3807. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3808. {
  3809. DEBUG_INFO("Authorize from list.\n");
  3810. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3811. }
  3812. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3813. {
  3814. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3815. {
  3816. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3817. }
  3818. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3819. {
  3820. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3821. }
  3822. if(!GetOcppConnStatus())
  3823. {
  3824. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3825. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3826. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3827. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3828. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3829. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3830. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3831. authorizeRetryTimes = 0;
  3832. return result;
  3833. }
  3834. }
  3835. else
  3836. {
  3837. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3838. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3839. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3840. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3841. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3842. else
  3843. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3844. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3845. result = PASS;
  3846. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3847. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3848. authorizeRetryTimes = 0;
  3849. return result;
  3850. }
  3851. }
  3852. //initialize struct Authorize
  3853. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3854. //get data from shared memory
  3855. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3856. random_uuid(guid);
  3857. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3858. LWS_Send(message);
  3859. sprintf(tempdata, "Authorize,%d", gun_index);
  3860. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3861. {
  3862. result = PASS;
  3863. DEBUG_INFO("Authorize mapItem pass\n");
  3864. }
  3865. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3866. return result;
  3867. }
  3868. int sendBootNotificationRequest(void)
  3869. {
  3870. mtrace();
  3871. int result = FAIL;
  3872. char message[500]={0}, payload[700]={0};
  3873. char guid[37]={0};
  3874. char tempdata[65]={0};
  3875. // Fill BootNotification fields
  3876. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3877. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3878. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3879. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3880. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3881. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3882. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3883. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3884. ShmOCPP16DataPH->ChargeBoxId
  3885. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3886. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3887. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3888. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3889. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3890. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3891. random_uuid(guid);
  3892. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3893. LWS_Send(message);
  3894. sprintf(tempdata, "BootNotification,0");
  3895. 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*/)
  3896. {
  3897. result = PASS;
  3898. }
  3899. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3900. strcpy(queuedata,message);
  3901. return result;
  3902. }
  3903. int sendDataTransferRequest(int gun_index)
  3904. {
  3905. mtrace();
  3906. char message[1000]={0};
  3907. char guid[37]={0};
  3908. char tempdata[65]={0};
  3909. int result = FAIL;
  3910. random_uuid(guid);
  3911. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3912. MESSAGE_TYPE_CALL,
  3913. guid,
  3914. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  3915. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  3916. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  3917. LWS_Send(message);
  3918. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3919. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3920. {
  3921. result = PASS;
  3922. DEBUG_INFO("DataTransfer mapItem pass\n");
  3923. }
  3924. return result;
  3925. }
  3926. int sendDiagnosticsStatusNotificationRequest(char *status)
  3927. {
  3928. mtrace();
  3929. int result = FAIL;
  3930. char message[110]={0};
  3931. char guid[37]={0};
  3932. char tempdata[65]={0};
  3933. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3934. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3935. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3936. random_uuid(guid);
  3937. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3938. LWS_SendNow(message);
  3939. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3940. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3941. {
  3942. result = PASS;
  3943. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3944. }
  3945. //#ifdef SystemLogMessage
  3946. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3947. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3948. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3949. //#endif
  3950. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3951. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3952. //record status
  3953. if(strcmp(status,"Idle")==0)
  3954. {
  3955. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3956. }
  3957. else if(strcmp(status,"Uploaded")==0)
  3958. {
  3959. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3960. }
  3961. else if(strcmp(status,"UploadFailed")==0)
  3962. {
  3963. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3964. }
  3965. else if(strcmp(status,"Uploading")==0)
  3966. {
  3967. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3968. }
  3969. return result;
  3970. }
  3971. int sendFirmwareStatusNotificationRequest(char *status)
  3972. {
  3973. mtrace();
  3974. int result = FAIL;
  3975. char message[110]={0};
  3976. char guid[37]={0};
  3977. char tempdata[65]={0};
  3978. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3979. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3980. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3981. random_uuid(guid);
  3982. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3983. LWS_SendNow(message);
  3984. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3985. 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*/)
  3986. {
  3987. result = PASS;
  3988. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3989. }
  3990. //#ifdef SystemLogMessage
  3991. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3992. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3993. //#endif
  3994. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3995. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3996. //record status
  3997. if(strcmp(status,"Downloaded")==0)
  3998. {
  3999. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  4000. }
  4001. else if(strcmp(status,"DownloadFailed")==0)
  4002. {
  4003. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  4004. }
  4005. else if(strcmp(status,"Downloading")==0)
  4006. {
  4007. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  4008. }
  4009. else if(strcmp(status,"Idle")==0)
  4010. {
  4011. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  4012. }
  4013. else if(strcmp(status,"InstallationFailed")==0)
  4014. {
  4015. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  4016. }
  4017. else if(strcmp(status,"Installing")==0)
  4018. {
  4019. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  4020. }
  4021. else if(strcmp(status,"Installed")==0)
  4022. {
  4023. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  4024. }
  4025. return result;
  4026. }
  4027. int sendHeartbeatRequest(int gun_index)
  4028. {
  4029. mtrace();
  4030. int result = FAIL;
  4031. char message[80]={0};
  4032. char guid[37]={0};
  4033. char tempdata[65]={0};
  4034. random_uuid(guid);
  4035. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  4036. , MESSAGE_TYPE_CALL
  4037. , guid );
  4038. LWS_Send(message);
  4039. sprintf(tempdata, "Heartbeat,%d", 0);
  4040. 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*/)
  4041. {
  4042. result = PASS;
  4043. }
  4044. return result;
  4045. }
  4046. int sendStartTransactionRequest(int gun_index)
  4047. {
  4048. mtrace();
  4049. int result = FAIL;
  4050. char message[250]={0};
  4051. char guid[37]={0};
  4052. struct timeval tmnow;
  4053. struct tm *tm;
  4054. char buf[28];//, usec_buf[6];
  4055. char tempdata[65]={0};
  4056. int tempIndex = 0;
  4057. DEBUG_INFO("sendStartTransactionRequest...\n");
  4058. gettimeofday(&tmnow, NULL);
  4059. time_t t;
  4060. t = time(NULL);
  4061. /*UTC time and date*/
  4062. tm = gmtime(&t);
  4063. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4064. #if 0 // remove temporally
  4065. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4066. strcat(buf,".");
  4067. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4068. strcat(buf,usec_buf);
  4069. #endif
  4070. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  4071. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  4072. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  4073. // clear StartTransaction Response
  4074. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  4075. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  4076. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  4077. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  4078. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4079. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4080. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4081. {
  4082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4083. {
  4084. tempIndex = ((gun_index==2) ? 1: 0);
  4085. }
  4086. else
  4087. {
  4088. tempIndex = gun_index;
  4089. }
  4090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4091. {
  4092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4093. {
  4094. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4095. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  4096. }
  4097. }
  4098. }
  4099. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4100. {
  4101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4102. {
  4103. tempIndex = ((gun_index==2) ? 1: 0);
  4104. }
  4105. else
  4106. {
  4107. tempIndex = gun_index;
  4108. }
  4109. for (int index = 0; index < CCS_QUANTITY; index++)
  4110. {
  4111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4112. {
  4113. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4114. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  4115. }
  4116. }
  4117. }
  4118. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4119. {
  4120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4121. {
  4122. tempIndex = ((gun_index==2) ? 1: 0);
  4123. }
  4124. else
  4125. {
  4126. tempIndex = gun_index;
  4127. }
  4128. for (int index = 0; index < GB_QUANTITY; index++)
  4129. {
  4130. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4131. {
  4132. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4133. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  4134. }
  4135. }
  4136. }
  4137. else if(gunType[gun_index] == GUN_TYPE_DO)
  4138. {
  4139. tempIndex = gun_index;
  4140. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4141. {
  4142. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4143. {
  4144. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4145. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  4146. }
  4147. }
  4148. }
  4149. else
  4150. {
  4151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4152. {
  4153. tempIndex = 2;
  4154. }
  4155. else
  4156. {
  4157. tempIndex = gun_index;
  4158. }
  4159. for (int index = 0; index < AC_QUANTITY; index++)
  4160. {
  4161. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4162. {
  4163. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4164. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  4165. }
  4166. }
  4167. }
  4168. random_uuid(guid);
  4169. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  4170. {
  4171. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  4172. , gun_index +1
  4173. , MESSAGE_TYPE_CALL
  4174. , guid
  4175. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4176. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4177. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4178. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4179. }
  4180. else
  4181. {
  4182. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  4183. , gun_index +1
  4184. , MESSAGE_TYPE_CALL
  4185. , guid
  4186. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  4187. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  4188. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  4189. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  4190. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  4191. }
  4192. #if 1
  4193. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  4194. 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*/)
  4195. {
  4196. result = PASS;
  4197. }
  4198. #endif
  4199. strcpy(queuedata, message);
  4200. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4201. OCPP_insert_transaction_msg(YES, queuedata);
  4202. return result;
  4203. }
  4204. int sendStatusNotificationRequest(int gun_index)
  4205. {
  4206. mtrace();
  4207. int result = FAIL;
  4208. char message[600]={0};
  4209. char guid[37];
  4210. int currentStatus = 0;
  4211. struct timeval tmnow;
  4212. struct tm *tm;
  4213. char buf[28];//, usec_buf[6];
  4214. char tempdata[65]={0};
  4215. int tempIndex = 0;
  4216. uint8_t isStateChanged = TRUE;
  4217. DEBUG_INFO("sendStatusNotificationRequest...\n");
  4218. gettimeofday(&tmnow, NULL);
  4219. time_t t;
  4220. t = time(NULL);
  4221. /*UTC time and date*/
  4222. tm = gmtime(&t);
  4223. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4224. #if 0 // remove temporally
  4225. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  4226. strcat(buf,".");
  4227. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  4228. strcat(buf,usec_buf);
  4229. #endif
  4230. //printf("%s",buf);
  4231. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  4232. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  4233. // it's option
  4234. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  4235. /*
  4236. enum _SYSTEM_STATUS
  4237. {
  4238. S_BOOTING = 0,
  4239. S_IDLE, = 1
  4240. S_AUTHORIZING, =2
  4241. S_REASSIGN_CHECK, =3
  4242. S_REASSIGN, =4
  4243. S_PRECHARGE, =5
  4244. S_PREPARING_FOR_EV, =6
  4245. S_PREPARING_FOR_EVSE, =7
  4246. S_CHARGING, =8
  4247. S_TERMINATING, =9
  4248. S_COMPLETE, =10
  4249. S_ALARM, =11
  4250. S_FAULT =12
  4251. }
  4252. */
  4253. //check Transaction active
  4254. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4255. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4256. {
  4257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4258. {
  4259. tempIndex = ((gun_index==2) ? 1: 0);
  4260. }
  4261. else
  4262. {
  4263. tempIndex = gun_index;
  4264. }
  4265. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4266. {
  4267. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  4268. {
  4269. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  4270. {
  4271. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4272. {
  4273. currentStatus = Preparing; //OCPP Status: Preparing
  4274. }
  4275. else
  4276. {
  4277. currentStatus = Available; //OCPP Status: Available
  4278. }
  4279. }
  4280. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4281. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4282. ) //S_PRECHARGE
  4283. {
  4284. currentStatus = Preparing; //OCPP Status: Preparing
  4285. }
  4286. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4287. {
  4288. currentStatus = Charging; //OCPP Status: Charging
  4289. }
  4290. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4291. {
  4292. currentStatus = Finishing; //OCPP Status: Finishing
  4293. }
  4294. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4295. {
  4296. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4297. }
  4298. 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
  4299. {
  4300. currentStatus = Unavailable; //OCPP Status: Unavailable
  4301. }
  4302. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4303. {
  4304. currentStatus = Faulted; //OCPP Status: Faulted
  4305. }
  4306. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4307. {
  4308. currentStatus = Reserved; //OCPP Status: Reserved
  4309. }
  4310. } //end of the same index
  4311. }//end of for CHAdeMO_QUANTITY
  4312. }
  4313. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4314. {
  4315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4316. {
  4317. tempIndex = ((gun_index==2) ? 1: 0);
  4318. }
  4319. else
  4320. {
  4321. tempIndex = gun_index;
  4322. }
  4323. for (int index = 0; index < CCS_QUANTITY; index++)
  4324. {
  4325. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4326. {
  4327. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4328. {
  4329. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  4330. {
  4331. currentStatus = Preparing; //OCPP Status: Preparing
  4332. }
  4333. else
  4334. {
  4335. currentStatus = Available; //OCPP Status: Available
  4336. }
  4337. }
  4338. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4339. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4340. ) //S_PRECHARGE
  4341. {
  4342. currentStatus = Preparing; //OCPP Status: Preparing
  4343. }
  4344. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4345. {
  4346. currentStatus = Charging; //OCPP Status: Charging
  4347. }
  4348. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4349. {
  4350. currentStatus = Finishing; //OCPP Status: Finishing
  4351. }
  4352. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  4353. {
  4354. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4355. }
  4356. 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
  4357. {
  4358. currentStatus = Unavailable; //OCPP Status : Unavailable
  4359. }
  4360. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4361. {
  4362. currentStatus = Faulted; //OCPP Status: Faulted
  4363. }
  4364. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4365. {
  4366. currentStatus = Reserved; //OCPP Status: Reserved
  4367. }
  4368. } //end of the same index
  4369. } // end of for CCS_QUANTITY
  4370. }
  4371. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4372. {
  4373. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4374. {
  4375. tempIndex = ((gun_index==2) ? 1: 0);
  4376. }
  4377. else
  4378. {
  4379. tempIndex = gun_index;
  4380. }
  4381. for (int index = 0; index < GB_QUANTITY; index++)
  4382. {
  4383. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4384. {
  4385. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4386. {
  4387. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4388. {
  4389. currentStatus = Preparing; //OCPP Status: Preparing
  4390. }
  4391. else
  4392. {
  4393. currentStatus = Available; //OCPP Status: Available
  4394. }
  4395. }
  4396. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4397. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4398. ) //S_PRECHARGE
  4399. {
  4400. currentStatus = Preparing; //OCPP Status: Preparing
  4401. }
  4402. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4403. {
  4404. currentStatus = Charging; //OCPP Status: Charging
  4405. }
  4406. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4407. {
  4408. currentStatus = Finishing; //OCPP Status: Finishing
  4409. }
  4410. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4411. {
  4412. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4413. }
  4414. 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
  4415. {
  4416. currentStatus = Unavailable; //OCPP Status: Unavailable
  4417. }
  4418. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  4419. {
  4420. currentStatus = Faulted; //OCPP Status: Faulted
  4421. }
  4422. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4423. {
  4424. currentStatus = Reserved; //OCPP Status: Reserved
  4425. }
  4426. } //end of the same index
  4427. } // end of for GB_QUANTITY
  4428. }
  4429. else if(gunType[gun_index] == GUN_TYPE_DO)
  4430. {
  4431. tempIndex = gun_index;
  4432. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4433. {
  4434. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4435. {
  4436. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  4437. {
  4438. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  4439. {
  4440. currentStatus = Preparing; //OCPP Status: Preparing
  4441. }
  4442. else
  4443. {
  4444. currentStatus = Available; //OCPP Status: Available
  4445. }
  4446. }
  4447. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  4448. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  4449. ) //S_PRECHARGE
  4450. {
  4451. currentStatus = Preparing; //OCPP Status: Preparing
  4452. }
  4453. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  4454. {
  4455. currentStatus = Charging; //OCPP Status: Charging
  4456. }
  4457. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  4458. {
  4459. currentStatus = Finishing; //OCPP Status: Finishing
  4460. }
  4461. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4462. {
  4463. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4464. }
  4465. 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
  4466. {
  4467. currentStatus = Unavailable; //OCPP Status: Unavailable
  4468. }
  4469. 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
  4470. {
  4471. currentStatus = Faulted; //OCPP Status: Faulted
  4472. }
  4473. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4474. {
  4475. currentStatus = Reserved; //OCPP Status: Reserved
  4476. }
  4477. } //end of the same index
  4478. }
  4479. }
  4480. else
  4481. {
  4482. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4483. {
  4484. tempIndex = 2;
  4485. }
  4486. else
  4487. {
  4488. tempIndex = gun_index;
  4489. }
  4490. for (int index = 0; index < AC_QUANTITY; index++)
  4491. {
  4492. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4493. {
  4494. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  4495. {
  4496. 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))
  4497. {
  4498. currentStatus = Preparing; //OCPP Status: Preparing
  4499. }
  4500. else
  4501. {
  4502. currentStatus = Available; //OCPP Status: Available
  4503. }
  4504. }
  4505. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  4506. {
  4507. currentStatus = Preparing; //OCPP Status: Preparing
  4508. }
  4509. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  4510. {
  4511. currentStatus = Charging; //OCPP Status: Charging
  4512. }
  4513. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  4514. {
  4515. currentStatus = Finishing; //OCPP Status: Finishing
  4516. }
  4517. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  4518. {
  4519. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  4520. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  4521. else
  4522. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  4523. }
  4524. 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
  4525. {
  4526. currentStatus = Unavailable; //OCPP Status: Unavailable
  4527. }
  4528. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  4529. {
  4530. currentStatus = Faulted; //OCPP Status: Faulted
  4531. }
  4532. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  4533. {
  4534. currentStatus = Reserved; //OCPP Status: Reserved
  4535. }
  4536. }//end of the same index
  4537. }//end of for AC_QUANTITY
  4538. }
  4539. //it's option
  4540. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  4541. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  4542. {
  4543. isStateChanged = FALSE;
  4544. }
  4545. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4546. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  4547. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  4548. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  4549. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  4550. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  4551. random_uuid(guid);
  4552. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  4553. , MESSAGE_TYPE_CALL
  4554. , guid
  4555. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  4556. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  4557. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  4558. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  4559. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  4560. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  4561. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  4562. if((server_sign == TRUE) && isStateChanged)
  4563. {
  4564. LWS_Send(message);
  4565. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  4566. 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*/)
  4567. {
  4568. //DEBUG_ERROR("statusNotification mapitem pass");
  4569. result = PASS;
  4570. }
  4571. }
  4572. else
  4573. {
  4574. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  4575. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  4576. result = PASS;
  4577. }
  4578. return result;
  4579. }
  4580. int sendStopTransactionRequest(int gun_index)
  4581. {
  4582. mtrace();
  4583. int result = FAIL;
  4584. //char message[1500]={0};
  4585. char guid[37]={0};
  4586. char tempdata[65]={0};
  4587. int tempIndex = 0;
  4588. char TempStopTransaction[256];
  4589. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  4590. //int idx_sample=0;
  4591. DEBUG_INFO("sendStopTransactionRequest \n");
  4592. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4593. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  4594. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4595. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4596. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4597. {
  4598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4599. {
  4600. tempIndex = ((gun_index==2) ? 1: 0);
  4601. }
  4602. else
  4603. {
  4604. tempIndex = gun_index;
  4605. }
  4606. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4607. {
  4608. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4609. {
  4610. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4611. }
  4612. }// END OF CHAdeMO_QUANTITY
  4613. }
  4614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4615. {
  4616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4617. {
  4618. tempIndex = ((gun_index==2) ? 1: 0);
  4619. }
  4620. else
  4621. {
  4622. tempIndex = gun_index;
  4623. }
  4624. for (int index = 0; index < CCS_QUANTITY; index++)
  4625. {
  4626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4627. {
  4628. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4629. }
  4630. }// END OF CCS_QUANTITY
  4631. }
  4632. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4633. {
  4634. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4635. {
  4636. tempIndex = ((gun_index==2) ? 1: 0);
  4637. }
  4638. else
  4639. {
  4640. tempIndex = gun_index;
  4641. }
  4642. for (int index = 0; index < GB_QUANTITY; index++)
  4643. {
  4644. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4645. {
  4646. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4647. }
  4648. }// END OF GB_QUANTITY
  4649. }
  4650. else if(gunType[gun_index] == GUN_TYPE_DO)
  4651. {
  4652. tempIndex = gun_index;
  4653. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4654. {
  4655. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4656. {
  4657. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4658. }
  4659. }// END OF GB_QUANTITY
  4660. }
  4661. else
  4662. {
  4663. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4664. {
  4665. tempIndex = 2;
  4666. }
  4667. else
  4668. {
  4669. tempIndex = gun_index;
  4670. }
  4671. for (int index = 0; index < AC_QUANTITY; index++)
  4672. {
  4673. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4674. {
  4675. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4676. }
  4677. }// END OF AC_QUANTITY
  4678. }
  4679. //====================================== Stop Transaction Time =====================================================
  4680. struct timeval tmnow;
  4681. struct tm *tm;
  4682. char buf[28];//, usec_buf[6];
  4683. gettimeofday(&tmnow, NULL);
  4684. time_t t;
  4685. t = time(NULL);
  4686. /*UTC time and date*/
  4687. tm = gmtime(&t);
  4688. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4689. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4690. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4691. random_uuid(guid);
  4692. /***********************************transactionData******************************************************/
  4693. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4694. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4695. //=================================
  4696. // Transaction_Begin
  4697. //=================================
  4698. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4699. {
  4700. //============================================ Energy.Active.Import.Interval ================================
  4701. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4702. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4703. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4704. 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*/]);
  4705. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4706. 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))
  4707. {
  4708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4709. }
  4710. else
  4711. {
  4712. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4713. }
  4714. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4715. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4716. }
  4717. //=================================
  4718. // Transaction_End
  4719. //=================================
  4720. // ================================= Current.Import L1 ===============================================
  4721. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4722. {
  4723. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4724. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4725. {
  4726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4727. {
  4728. tempIndex = ((gun_index==2) ? 1: 0);
  4729. }
  4730. else
  4731. {
  4732. tempIndex = gun_index;
  4733. }
  4734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4735. {
  4736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4737. {
  4738. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4739. }
  4740. }// End of for CHAdeMO_QUANTITY
  4741. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4742. }
  4743. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4744. {
  4745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4746. {
  4747. tempIndex = ((gun_index==2) ? 1: 0);
  4748. }
  4749. else
  4750. {
  4751. tempIndex = gun_index;
  4752. }
  4753. for (int index = 0; index < CCS_QUANTITY; index++)
  4754. {
  4755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4756. {
  4757. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4758. }
  4759. }// End of for CCS_QUANTITY
  4760. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4761. }
  4762. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4763. {
  4764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4765. {
  4766. tempIndex = ((gun_index==2) ? 1: 0);
  4767. }
  4768. else
  4769. {
  4770. tempIndex = gun_index;
  4771. }
  4772. for (int index = 0; index < GB_QUANTITY; index++)
  4773. {
  4774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4775. {
  4776. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4777. }
  4778. }// End of for GB_QUANTITY
  4779. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4780. }
  4781. else if(gunType[gun_index] == GUN_TYPE_DO)
  4782. {
  4783. tempIndex = gun_index;
  4784. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4785. {
  4786. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4787. {
  4788. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4789. }
  4790. }
  4791. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4792. }
  4793. else
  4794. {
  4795. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4796. {
  4797. tempIndex = 2;
  4798. }
  4799. else
  4800. {
  4801. tempIndex = gun_index;
  4802. }
  4803. for (int index = 0; index < AC_QUANTITY; index++)
  4804. {
  4805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4806. {
  4807. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4808. }
  4809. }// End of for AC_QUANTITY
  4810. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4811. }
  4812. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4813. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4814. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4815. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4816. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4817. }
  4818. // ================================= Energy.Active.Import.Interval ==============================================
  4819. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4820. {
  4821. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4822. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4823. {
  4824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4825. {
  4826. tempIndex = ((gun_index==2) ? 1: 0);
  4827. }
  4828. else
  4829. {
  4830. tempIndex = gun_index;
  4831. }
  4832. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4833. {
  4834. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4835. {
  4836. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4837. }
  4838. }// END OF CHAdeMO_QUANTITY
  4839. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4840. }
  4841. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4842. {
  4843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4844. {
  4845. tempIndex = ((gun_index==2) ? 1: 0);
  4846. }
  4847. else
  4848. {
  4849. tempIndex = gun_index;
  4850. }
  4851. for (int index = 0; index < CCS_QUANTITY; index++)
  4852. {
  4853. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4854. {
  4855. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4856. }
  4857. }// END OF CCS_QUANTITY
  4858. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4859. }
  4860. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4861. {
  4862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4863. {
  4864. tempIndex = ((gun_index==2) ? 1: 0);
  4865. }
  4866. else
  4867. {
  4868. tempIndex = gun_index;
  4869. }
  4870. for (int index = 0; index < GB_QUANTITY; index++)
  4871. {
  4872. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4873. {
  4874. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4875. }
  4876. }// END OF GB_QUANTITY
  4877. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4878. }
  4879. else if(gunType[gun_index] == GUN_TYPE_DO)
  4880. {
  4881. tempIndex = gun_index;
  4882. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4883. {
  4884. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4885. {
  4886. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4887. }
  4888. }
  4889. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4890. }
  4891. else
  4892. {
  4893. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4894. {
  4895. tempIndex = 2;
  4896. }
  4897. else
  4898. {
  4899. tempIndex = gun_index;
  4900. }
  4901. for (int index = 0; index < AC_QUANTITY; index++)
  4902. {
  4903. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4904. {
  4905. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4906. }
  4907. }// END OF AC_QUANTITY
  4908. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4909. }
  4910. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4911. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4912. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4913. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4914. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4915. }
  4916. //=================================== Power.Active.Import ==================================================
  4917. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4918. {
  4919. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4920. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4921. {
  4922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4923. {
  4924. tempIndex = ((gun_index==2) ? 1: 0);
  4925. }
  4926. else
  4927. {
  4928. tempIndex = gun_index;
  4929. }
  4930. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4931. {
  4932. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4933. {
  4934. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4935. }
  4936. } // End for CHAdeMO_QUANTITY
  4937. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4938. }
  4939. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4940. {
  4941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4942. {
  4943. tempIndex = ((gun_index==2) ? 1: 0);
  4944. }
  4945. else
  4946. {
  4947. tempIndex = gun_index;
  4948. }
  4949. for (int index = 0; index < CCS_QUANTITY; index++)
  4950. {
  4951. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4952. {
  4953. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4954. }
  4955. } // END for CCS_QUANTITY
  4956. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4957. }
  4958. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4959. {
  4960. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4961. {
  4962. tempIndex = ((gun_index==2) ? 1: 0);
  4963. }
  4964. else
  4965. {
  4966. tempIndex = gun_index;
  4967. }
  4968. for (int index = 0; index < GB_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4973. }
  4974. }// END for GB_QUANTITY
  4975. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4976. }
  4977. else if(gunType[gun_index] == GUN_TYPE_DO)
  4978. {
  4979. tempIndex = gun_index;
  4980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4981. {
  4982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4983. {
  4984. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4985. }
  4986. }
  4987. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4988. }
  4989. else
  4990. {
  4991. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4992. {
  4993. tempIndex = 2;
  4994. }
  4995. else
  4996. {
  4997. tempIndex = gun_index;
  4998. }
  4999. for (int index = 0; index < AC_QUANTITY; index++)
  5000. {
  5001. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5002. {
  5003. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  5004. }
  5005. } // END for AC_QUANTITY
  5006. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  5007. }
  5008. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5009. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  5010. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  5011. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  5012. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  5013. }
  5014. //============================ Voltage L1 ====================================
  5015. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5016. {
  5017. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5018. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5019. {
  5020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5021. {
  5022. tempIndex = ((gun_index==2) ? 1: 0);
  5023. }
  5024. else
  5025. {
  5026. tempIndex = gun_index;
  5027. }
  5028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5029. {
  5030. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5031. {
  5032. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5033. }
  5034. } // END OF FOR CHAdeMO_QUANTITY
  5035. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5036. }
  5037. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5038. {
  5039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5040. {
  5041. tempIndex = ((gun_index==2) ? 1: 0);
  5042. }
  5043. else
  5044. {
  5045. tempIndex = gun_index;
  5046. }
  5047. for (int index = 0; index < CCS_QUANTITY; index++)
  5048. {
  5049. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5050. {
  5051. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5052. }
  5053. } // END OF FOR CCS_QUANTITY
  5054. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5055. }
  5056. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5057. {
  5058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5059. {
  5060. tempIndex = ((gun_index==2) ? 1: 0);
  5061. }
  5062. else
  5063. {
  5064. tempIndex = gun_index;
  5065. }
  5066. for (int index = 0; index < GB_QUANTITY; index++)
  5067. {
  5068. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5069. {
  5070. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5071. }
  5072. } // END OF FOR GB_QUANTITY
  5073. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5074. }
  5075. else if(gunType[gun_index] == GUN_TYPE_DO)
  5076. {
  5077. tempIndex = gun_index;
  5078. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5079. {
  5080. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5081. {
  5082. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  5083. }
  5084. }
  5085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  5086. }
  5087. else
  5088. {
  5089. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5090. {
  5091. tempIndex = 2;
  5092. }
  5093. else
  5094. {
  5095. tempIndex = gun_index;
  5096. }
  5097. for (int index = 0; index < AC_QUANTITY; index++)
  5098. {
  5099. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5100. {
  5101. 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
  5102. }
  5103. } // END OF FOR AC_QUANTITY
  5104. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  5105. }
  5106. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  5108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  5109. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  5110. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5111. }
  5112. //====================== End SoC ================================
  5113. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5114. {
  5115. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5116. 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))
  5117. {
  5118. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5119. {
  5120. tempIndex = ((gun_index==2) ? 1: 0);
  5121. }
  5122. else
  5123. {
  5124. tempIndex = gun_index;
  5125. }
  5126. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5127. {
  5128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5129. {
  5130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5131. {
  5132. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  5133. }
  5134. }
  5135. }
  5136. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5137. {
  5138. for (int index = 0; index < CCS_QUANTITY; index++)
  5139. {
  5140. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5141. {
  5142. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  5143. }
  5144. }
  5145. }
  5146. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5147. {
  5148. for (int index = 0; index < GB_QUANTITY; index++)
  5149. {
  5150. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5151. {
  5152. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  5153. }
  5154. }
  5155. }
  5156. else if(gunType[gun_index] == GUN_TYPE_DO)
  5157. {
  5158. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5159. {
  5160. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5161. {
  5162. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  5163. }
  5164. }
  5165. }
  5166. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5167. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  5168. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5169. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  5170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  5171. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5172. } // END FOR DC CASE
  5173. }
  5174. // ================================= Current.Import L2 ===============================================
  5175. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5176. {
  5177. // AC 3 phse L2 current
  5178. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5179. {
  5180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5181. {
  5182. tempIndex = 2;
  5183. }
  5184. else
  5185. {
  5186. tempIndex = gun_index;
  5187. }
  5188. for (int index = 0; index < AC_QUANTITY; index++)
  5189. {
  5190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5191. {
  5192. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  5193. }
  5194. }// End of for AC_QUANTITY
  5195. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  5196. }
  5197. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5198. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  5199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  5200. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  5201. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5202. }
  5203. // ================================= Current.Import L3 ===============================================
  5204. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  5205. {
  5206. // AC 3 phse L3 current
  5207. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5208. {
  5209. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5210. {
  5211. tempIndex = 2;
  5212. }
  5213. else
  5214. {
  5215. tempIndex = gun_index;
  5216. }
  5217. for (int index = 0; index < AC_QUANTITY; index++)
  5218. {
  5219. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5220. {
  5221. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  5222. }
  5223. }// End of for AC_QUANTITY
  5224. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  5225. }
  5226. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5227. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  5228. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  5229. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  5230. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5231. }
  5232. //============================ Voltage L2 ====================================
  5233. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5234. {
  5235. // AC 3 phse L2 voltage
  5236. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5237. {
  5238. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5239. {
  5240. tempIndex = 2;
  5241. }
  5242. else
  5243. {
  5244. tempIndex = gun_index;
  5245. }
  5246. for (int index = 0; index < AC_QUANTITY; index++)
  5247. {
  5248. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5249. {
  5250. 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
  5251. }
  5252. } // END OF FOR AC_QUANTITY
  5253. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  5254. }
  5255. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5256. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  5257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  5258. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  5259. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5260. }
  5261. //============================ Voltage L3 ====================================
  5262. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  5263. {
  5264. // AC 3 phse L3 voltage
  5265. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5266. {
  5267. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5268. {
  5269. tempIndex = 2;
  5270. }
  5271. else
  5272. {
  5273. tempIndex = gun_index;
  5274. }
  5275. for (int index = 0; index < AC_QUANTITY; index++)
  5276. {
  5277. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5278. {
  5279. 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
  5280. }
  5281. } // END OF FOR AC_QUANTITY
  5282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  5283. }
  5284. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  5285. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  5286. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  5287. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  5288. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5289. }
  5290. //====================== Start SoC ================================
  5291. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  5292. {
  5293. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5294. 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))
  5295. {
  5296. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5297. {
  5298. tempIndex = ((gun_index==2) ? 1: 0);
  5299. }
  5300. else
  5301. {
  5302. tempIndex = gun_index;
  5303. }
  5304. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5305. {
  5306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5307. {
  5308. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5309. {
  5310. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  5311. }
  5312. }
  5313. }
  5314. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5315. {
  5316. for (int index = 0; index < CCS_QUANTITY; index++)
  5317. {
  5318. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5319. {
  5320. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  5321. }
  5322. }
  5323. }
  5324. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5325. {
  5326. for (int index = 0; index < GB_QUANTITY; index++)
  5327. {
  5328. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5329. {
  5330. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  5331. }
  5332. }
  5333. }
  5334. else if(gunType[gun_index] == GUN_TYPE_DO)
  5335. {
  5336. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5337. {
  5338. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5339. {
  5340. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  5341. }
  5342. }
  5343. }
  5344. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  5345. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  5346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  5347. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  5348. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  5349. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  5350. } // END FOR DC CASE
  5351. }
  5352. //================================================ Message create ====================================================
  5353. json_object *StopTransaction = json_object_new_object();
  5354. json_object *transactionDatas = json_object_new_array();
  5355. json_object *sampledValues = json_object_new_array();
  5356. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  5357. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  5358. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  5359. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  5360. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  5361. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  5362. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  5363. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  5364. {
  5365. json_object *transactionData = json_object_new_object();
  5366. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  5367. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  5368. {
  5369. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  5370. {
  5371. json_object *sampledValue = json_object_new_object();
  5372. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  5373. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  5374. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  5375. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  5376. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  5377. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  5378. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  5379. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  5380. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  5381. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  5382. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  5383. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  5384. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  5385. json_object_array_add(sampledValues, sampledValue);
  5386. }
  5387. }
  5388. json_object_object_add(transactionData, "sampledValue", sampledValues);
  5389. json_object_array_add(transactionDatas, transactionData);
  5390. }
  5391. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  5392. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  5393. ,MESSAGE_TYPE_CALL
  5394. ,guid
  5395. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  5396. json_object_put(StopTransaction);
  5397. #if 1 // for TempStopTransaction
  5398. //Delete TempStopTransaction
  5399. if((access(TempStopTransaction,F_OK))!=-1)
  5400. {
  5401. remove(TempStopTransaction); // remove file "TempStopTransaction"
  5402. }
  5403. #endif
  5404. #if 1
  5405. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  5406. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  5407. {
  5408. result = PASS;
  5409. //DEBUG_INFO("StopTransaction mapitem pass\n");
  5410. }
  5411. #endif
  5412. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  5413. OCPP_insert_transaction_msg(NO, queuedata);
  5414. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  5415. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  5416. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  5417. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  5418. {
  5419. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  5420. }
  5421. //for test
  5422. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  5423. return result;
  5424. }
  5425. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  5426. {
  5427. mtrace();
  5428. int result = FAIL;
  5429. char guid[37]={0};
  5430. char tempdata[65]={0};
  5431. int tempIndex = 0;
  5432. DEBUG_INFO("sendMeterValuesRequest ...\n");
  5433. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5434. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  5435. //set value
  5436. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  5437. 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) )?
  5438. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  5439. -1);
  5440. random_uuid(guid);
  5441. //UTC Date time
  5442. struct timeval tmnow;
  5443. struct tm *tm;
  5444. char buf[28];//, usec_buf[6];
  5445. gettimeofday(&tmnow, NULL);
  5446. time_t t;
  5447. t = time(NULL);
  5448. /*UTC time and date*/
  5449. tm = gmtime(&t);
  5450. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  5452. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5453. //********************************(1)Current.Import L1************************************************/
  5454. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5455. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  5456. (dataType == ReadingContext_Trigger))
  5457. {
  5458. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5459. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5460. {
  5461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5462. {
  5463. tempIndex = ((gun_index==2) ? 1: 0);
  5464. }
  5465. else
  5466. {
  5467. tempIndex = gun_index;
  5468. }
  5469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5470. {
  5471. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5472. {
  5473. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  5474. }
  5475. }
  5476. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5477. }
  5478. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5479. {
  5480. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5481. {
  5482. tempIndex = ((gun_index==2) ? 1: 0);
  5483. }
  5484. else
  5485. {
  5486. tempIndex = gun_index;
  5487. }
  5488. for (int index = 0; index < CCS_QUANTITY; index++)
  5489. {
  5490. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5491. {
  5492. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  5493. }
  5494. }
  5495. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5496. }
  5497. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5498. {
  5499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5500. {
  5501. tempIndex = ((gun_index==2) ? 1: 0);
  5502. }
  5503. else
  5504. {
  5505. tempIndex = gun_index;
  5506. }
  5507. for (int index = 0; index < GB_QUANTITY; index++)
  5508. {
  5509. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5510. {
  5511. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  5512. }
  5513. }
  5514. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5515. }
  5516. else if(gunType[gun_index] == GUN_TYPE_DO)
  5517. {
  5518. tempIndex = gun_index;
  5519. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5520. {
  5521. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5522. {
  5523. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  5524. }
  5525. }
  5526. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  5527. }
  5528. else
  5529. {
  5530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5531. {
  5532. tempIndex = 2;
  5533. }
  5534. else
  5535. {
  5536. tempIndex = gun_index;
  5537. }
  5538. for (int index = 0; index < AC_QUANTITY; index++)
  5539. {
  5540. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5541. {
  5542. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  5543. }
  5544. }
  5545. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  5546. }
  5547. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  5548. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  5549. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  5550. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  5551. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5552. }
  5553. //********************************(2)Energy.Active.Import.Register ************************************************/
  5554. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5555. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Register]) != NULL)) ||
  5556. (dataType == ReadingContext_Trigger))
  5557. {
  5558. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5559. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5560. {
  5561. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5562. {
  5563. tempIndex = ((gun_index==2) ? 1: 0);
  5564. }
  5565. else
  5566. {
  5567. tempIndex = gun_index;
  5568. }
  5569. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5570. {
  5571. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5572. {
  5573. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  5574. }
  5575. }
  5576. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5577. }
  5578. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5579. {
  5580. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5581. {
  5582. tempIndex = ((gun_index==2) ? 1: 0);
  5583. }
  5584. else
  5585. {
  5586. tempIndex = gun_index;
  5587. }
  5588. for (int index = 0; index < CCS_QUANTITY; index++)
  5589. {
  5590. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5591. {
  5592. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  5593. }
  5594. }
  5595. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5596. }
  5597. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5598. {
  5599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5600. {
  5601. tempIndex = ((gun_index==2) ? 1: 0);
  5602. }
  5603. else
  5604. {
  5605. tempIndex = gun_index;
  5606. }
  5607. for (int index = 0; index < GB_QUANTITY; index++)
  5608. {
  5609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5610. {
  5611. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5612. }
  5613. }
  5614. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5615. }
  5616. else if(gunType[gun_index] == GUN_TYPE_DO)
  5617. {
  5618. tempIndex = gun_index;
  5619. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5620. {
  5621. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5622. {
  5623. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5624. }
  5625. }
  5626. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5627. }
  5628. else
  5629. {
  5630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5631. {
  5632. tempIndex = 2;
  5633. }
  5634. else
  5635. {
  5636. tempIndex = gun_index;
  5637. }
  5638. for (int index = 0; index < AC_QUANTITY; index++)
  5639. {
  5640. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5641. {
  5642. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5643. }
  5644. }
  5645. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5646. }
  5647. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5648. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5649. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5650. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5651. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5652. }
  5653. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5654. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5655. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Energy_Active_Import_Interval]) != NULL)) ||
  5656. (dataType == ReadingContext_Trigger))
  5657. {
  5658. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5659. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5660. {
  5661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5662. {
  5663. tempIndex = ((gun_index==2) ? 1: 0);
  5664. }
  5665. else
  5666. {
  5667. tempIndex = gun_index;
  5668. }
  5669. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5670. {
  5671. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5672. {
  5673. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5674. }
  5675. } // END OF FOR CHAdeMO_QUANTITY
  5676. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5677. }
  5678. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5679. {
  5680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5681. {
  5682. tempIndex = ((gun_index==2) ? 1: 0);
  5683. }
  5684. else
  5685. {
  5686. tempIndex = gun_index;
  5687. }
  5688. for (int index = 0; index < CCS_QUANTITY; index++)
  5689. {
  5690. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5691. {
  5692. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5693. }
  5694. } // END OF CCS_QUANTITY
  5695. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5696. }
  5697. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5698. {
  5699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5700. {
  5701. tempIndex = ((gun_index==2) ? 1: 0);
  5702. }
  5703. else
  5704. {
  5705. tempIndex = gun_index;
  5706. }
  5707. for (int index = 0; index < GB_QUANTITY; index++)
  5708. {
  5709. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5710. {
  5711. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5712. }
  5713. } // END OF GB_QUANTITY
  5714. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5715. }
  5716. else if(gunType[gun_index] == GUN_TYPE_DO)
  5717. {
  5718. tempIndex = gun_index;
  5719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5720. {
  5721. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5722. {
  5723. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5724. }
  5725. }
  5726. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5727. }
  5728. else
  5729. {
  5730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5731. {
  5732. tempIndex = 2;
  5733. }
  5734. else
  5735. {
  5736. tempIndex = gun_index;
  5737. }
  5738. for (int index = 0; index < AC_QUANTITY; index++)
  5739. {
  5740. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5741. {
  5742. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5743. }
  5744. }
  5745. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5746. }
  5747. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5748. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5749. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5750. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5751. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5752. }
  5753. //********************************(4)Power.Active.Import************************************************/
  5754. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5755. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Active_Import]) != NULL)) ||
  5756. (dataType == ReadingContext_Trigger))
  5757. {
  5758. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5759. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5760. {
  5761. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5762. {
  5763. tempIndex = ((gun_index==2) ? 1: 0);
  5764. }
  5765. else
  5766. {
  5767. tempIndex = gun_index;
  5768. }
  5769. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5770. {
  5771. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5772. {
  5773. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5774. }
  5775. } // END OF FOR
  5776. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5777. }
  5778. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5779. {
  5780. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5781. {
  5782. tempIndex = ((gun_index==2) ? 1: 0);
  5783. }
  5784. else
  5785. {
  5786. tempIndex = gun_index;
  5787. }
  5788. for (int index = 0; index < CCS_QUANTITY; index++)
  5789. {
  5790. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5791. {
  5792. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5793. }
  5794. }
  5795. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5796. }
  5797. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5798. {
  5799. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5800. {
  5801. tempIndex = ((gun_index==2) ? 1: 0);
  5802. }
  5803. else
  5804. {
  5805. tempIndex = gun_index;
  5806. }
  5807. for (int index = 0; index < GB_QUANTITY; index++)
  5808. {
  5809. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5810. {
  5811. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5812. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5813. }
  5814. }
  5815. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5816. }
  5817. else if(gunType[gun_index] == GUN_TYPE_DO)
  5818. {
  5819. tempIndex = gun_index;
  5820. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5821. {
  5822. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5823. {
  5824. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5825. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5826. }
  5827. }
  5828. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5829. }
  5830. else
  5831. {
  5832. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5833. {
  5834. tempIndex = 2;
  5835. }
  5836. else
  5837. {
  5838. tempIndex = gun_index;
  5839. }
  5840. for (int index = 0; index < AC_QUANTITY; index++)
  5841. {
  5842. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5843. {
  5844. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5845. }
  5846. }
  5847. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5848. }
  5849. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5850. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5851. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5852. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5853. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5854. }
  5855. //***********************************************(5)VOLTAGE L1******************************************************/
  5856. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5857. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  5858. (dataType == ReadingContext_Trigger))
  5859. {
  5860. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5861. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5862. {
  5863. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5864. {
  5865. tempIndex = ((gun_index==2) ? 1: 0);
  5866. }
  5867. else
  5868. {
  5869. tempIndex = gun_index;
  5870. }
  5871. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5872. {
  5873. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5874. {
  5875. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5876. }
  5877. }
  5878. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5879. }
  5880. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5881. {
  5882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5883. {
  5884. tempIndex = ((gun_index==2) ? 1: 0);
  5885. }
  5886. else
  5887. {
  5888. tempIndex = gun_index;
  5889. }
  5890. for (int index = 0; index < CCS_QUANTITY; index++)
  5891. {
  5892. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5893. {
  5894. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5895. }
  5896. }
  5897. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5898. }
  5899. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5900. {
  5901. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5902. {
  5903. tempIndex = ((gun_index==2) ? 1: 0);
  5904. }
  5905. else
  5906. {
  5907. tempIndex = gun_index;
  5908. }
  5909. for (int index = 0; index < GB_QUANTITY; index++)
  5910. {
  5911. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5912. {
  5913. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5914. }
  5915. }
  5916. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5917. }
  5918. else if(gunType[gun_index] == GUN_TYPE_DO)
  5919. {
  5920. tempIndex = gun_index;
  5921. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5922. {
  5923. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5924. {
  5925. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5926. }
  5927. }
  5928. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5929. }
  5930. else
  5931. {
  5932. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5933. {
  5934. tempIndex = 2;
  5935. }
  5936. else
  5937. {
  5938. tempIndex = gun_index;
  5939. }
  5940. for (int index = 0; index < AC_QUANTITY; index++)
  5941. {
  5942. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5943. {
  5944. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5945. }
  5946. }
  5947. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5948. }
  5949. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5950. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5951. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5952. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5953. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5954. }
  5955. //***********************************************(6)SOC******************************************************/
  5956. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  5957. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[SoC]) != NULL)) ||
  5958. (dataType == ReadingContext_Trigger))
  5959. {
  5960. 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))
  5961. {
  5962. //idx_sample=5;
  5963. //sampledValue = NULL;
  5964. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5965. {
  5966. tempIndex = ((gun_index==2) ? 1: 0);
  5967. }
  5968. else
  5969. {
  5970. tempIndex = gun_index;
  5971. }
  5972. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5973. {
  5974. //tempIndex = ((gun_index==2) ? 1: 0);
  5975. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5976. {
  5977. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5978. {
  5979. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5980. }
  5981. }
  5982. }
  5983. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5984. {
  5985. //tempIndex = ((gun_index==2) ? 1: 0);
  5986. for (int index = 0; index < CCS_QUANTITY; index++)
  5987. {
  5988. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5989. {
  5990. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5991. }
  5992. }
  5993. }
  5994. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5995. {
  5996. //tempIndex = ((gun_index==2) ? 1: 0);
  5997. for (int index = 0; index < GB_QUANTITY; index++)
  5998. {
  5999. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6000. {
  6001. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  6002. }
  6003. }
  6004. }
  6005. else if(gunType[gun_index] == GUN_TYPE_DO)
  6006. {
  6007. //tempIndex = ((gun_index==2) ? 1: 0);
  6008. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6009. {
  6010. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6011. {
  6012. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  6013. }
  6014. }
  6015. }
  6016. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  6017. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  6018. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  6019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  6020. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  6021. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  6022. }
  6023. }
  6024. //********************************(7)Current.Import L2************************************************/
  6025. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6026. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6027. (dataType == ReadingContext_Trigger))
  6028. {
  6029. // Only for AC 3 phase
  6030. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6031. {
  6032. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6033. {
  6034. tempIndex = 2;
  6035. }
  6036. else
  6037. {
  6038. tempIndex = gun_index;
  6039. }
  6040. for (int index = 0; index < AC_QUANTITY; index++)
  6041. {
  6042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6043. {
  6044. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  6045. }
  6046. }
  6047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  6048. }
  6049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  6050. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  6051. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  6052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  6053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6054. }
  6055. //********************************(8)Current.Import L3************************************************/
  6056. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6057. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Import]) != NULL)) ||
  6058. (dataType == ReadingContext_Trigger))
  6059. {
  6060. // Only for AC 3 phase
  6061. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6062. {
  6063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6064. {
  6065. tempIndex = 2;
  6066. }
  6067. else
  6068. {
  6069. tempIndex = gun_index;
  6070. }
  6071. for (int index = 0; index < AC_QUANTITY; index++)
  6072. {
  6073. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6074. {
  6075. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  6076. }
  6077. }
  6078. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  6079. }
  6080. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  6081. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  6082. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  6083. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  6084. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6085. }
  6086. //***********************************************(9)VOLTAGE L2******************************************************/
  6087. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6088. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6089. (dataType == ReadingContext_Trigger))
  6090. {
  6091. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6092. {
  6093. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6094. {
  6095. tempIndex = 2;
  6096. }
  6097. else
  6098. {
  6099. tempIndex = gun_index;
  6100. }
  6101. for (int index = 0; index < AC_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6104. {
  6105. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  6106. }
  6107. }
  6108. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  6109. }
  6110. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  6111. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  6112. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  6113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  6114. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6115. }
  6116. //***********************************************(10)VOLTAGE L3******************************************************/
  6117. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6118. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Voltage]) != NULL)) ||
  6119. (dataType == ReadingContext_Trigger))
  6120. {
  6121. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  6122. {
  6123. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6124. {
  6125. tempIndex = 2;
  6126. }
  6127. else
  6128. {
  6129. tempIndex = gun_index;
  6130. }
  6131. for (int index = 0; index < AC_QUANTITY; index++)
  6132. {
  6133. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6134. {
  6135. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  6136. }
  6137. }
  6138. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  6139. }
  6140. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  6141. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  6142. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  6143. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  6144. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  6145. }
  6146. //***********************************************(11)Current.Offered******************************************************/
  6147. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6148. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Current_Offered]) != NULL)) ||
  6149. (dataType == ReadingContext_Trigger))
  6150. {
  6151. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6152. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6153. {
  6154. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6155. {
  6156. tempIndex = ((gun_index==2) ? 1: 0);
  6157. }
  6158. else
  6159. {
  6160. tempIndex = gun_index;
  6161. }
  6162. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6163. {
  6164. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6165. {
  6166. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10));
  6167. }
  6168. } // END OF FOR CHAdeMO_QUANTITY
  6169. }
  6170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6171. {
  6172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6173. {
  6174. tempIndex = ((gun_index==2) ? 1: 0);
  6175. }
  6176. else
  6177. {
  6178. tempIndex = gun_index;
  6179. }
  6180. for (int index = 0; index < CCS_QUANTITY; index++)
  6181. {
  6182. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6183. {
  6184. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10));
  6185. }
  6186. } // END OF CCS_QUANTITY
  6187. }
  6188. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6189. {
  6190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6191. {
  6192. tempIndex = ((gun_index==2) ? 1: 0);
  6193. }
  6194. else
  6195. {
  6196. tempIndex = gun_index;
  6197. }
  6198. for (int index = 0; index < GB_QUANTITY; index++)
  6199. {
  6200. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6201. {
  6202. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10));
  6203. }
  6204. } // END OF GB_QUANTITY
  6205. }
  6206. else if(gunType[gun_index] == GUN_TYPE_DO)
  6207. {
  6208. tempIndex = gun_index;
  6209. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6210. {
  6211. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6212. {
  6213. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10));
  6214. }
  6215. }
  6216. }
  6217. else
  6218. {
  6219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6220. {
  6221. tempIndex = 2;
  6222. }
  6223. else
  6224. {
  6225. tempIndex = gun_index;
  6226. }
  6227. for (int index = 0; index < AC_QUANTITY; index++)
  6228. {
  6229. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6230. {
  6231. uint16_t currentOffer;
  6232. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  6233. {
  6234. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  6235. }
  6236. else
  6237. {
  6238. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  6239. }
  6240. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Value, "%d", currentOffer);
  6241. }
  6242. }
  6243. }
  6244. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Context, ReadingContextStr[dataType]);
  6245. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Format, ValueFormatStr[Raw]);
  6246. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Measurand, MeasurandStr[Current_Offered]);
  6247. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Location, LocationStr[Location_Outlet]);
  6248. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  6249. }
  6250. //***********************************************(12)Power.Offered******************************************************/
  6251. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6252. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, MeasurandStr[Power_Offered]) != NULL) && (gunType[gun_index] != GUN_TYPE_AC)) ||
  6253. ((dataType == ReadingContext_Trigger) && (gunType[gun_index] != GUN_TYPE_AC)))
  6254. {
  6255. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6256. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6257. {
  6258. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6259. {
  6260. tempIndex = ((gun_index==2) ? 1: 0);
  6261. }
  6262. else
  6263. {
  6264. tempIndex = gun_index;
  6265. }
  6266. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6267. {
  6268. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6269. {
  6270. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100));
  6271. }
  6272. } // END OF FOR CHAdeMO_QUANTITY
  6273. }
  6274. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6275. {
  6276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6277. {
  6278. tempIndex = ((gun_index==2) ? 1: 0);
  6279. }
  6280. else
  6281. {
  6282. tempIndex = gun_index;
  6283. }
  6284. for (int index = 0; index < CCS_QUANTITY; index++)
  6285. {
  6286. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6287. {
  6288. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100));
  6289. }
  6290. } // END OF CCS_QUANTITY
  6291. }
  6292. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6293. {
  6294. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6295. {
  6296. tempIndex = ((gun_index==2) ? 1: 0);
  6297. }
  6298. else
  6299. {
  6300. tempIndex = gun_index;
  6301. }
  6302. for (int index = 0; index < GB_QUANTITY; index++)
  6303. {
  6304. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6305. {
  6306. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100));
  6307. }
  6308. } // END OF GB_QUANTITY
  6309. }
  6310. else if(gunType[gun_index] == GUN_TYPE_DO)
  6311. {
  6312. tempIndex = gun_index;
  6313. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6314. {
  6315. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6316. {
  6317. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Value, "%d", (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100));
  6318. }
  6319. }
  6320. }
  6321. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Context, ReadingContextStr[dataType]);
  6322. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Format, ValueFormatStr[Raw]);
  6323. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Measurand, MeasurandStr[Power_Offered]);
  6324. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Location, LocationStr[Location_Outlet]);
  6325. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[11].Unit,UnitOfMeasureStr[UnitOfMeasure_W]);
  6326. }
  6327. // Message create ====================================================================================================
  6328. if(TRUE)
  6329. {
  6330. json_object *MeterValueReq = json_object_new_object();
  6331. json_object *MeterValues = json_object_new_array();
  6332. json_object *sampledValues = json_object_new_array();
  6333. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  6334. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  6335. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  6336. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  6337. {
  6338. json_object *MeterValue = json_object_new_object();
  6339. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  6340. {
  6341. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  6342. {
  6343. json_object *sampledValue = json_object_new_object();
  6344. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  6345. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  6346. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  6347. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  6348. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  6349. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  6350. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  6351. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  6352. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  6353. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  6354. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  6355. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  6356. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  6357. json_object_array_add(sampledValues, sampledValue);
  6358. }
  6359. }
  6360. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  6361. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  6362. json_object_array_add(MeterValues, MeterValue);
  6363. }
  6364. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  6365. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6366. ,gun_index + 1
  6367. ,MESSAGE_TYPE_CALL
  6368. ,guid
  6369. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6370. json_object_put(MeterValueReq);
  6371. }
  6372. // Put request guid to hash map
  6373. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6374. 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*/)
  6375. {
  6376. result = PASS;
  6377. //DEBUG_INFO("MeterValues mapitem pass\n");
  6378. }
  6379. if((dataType != ReadingContext_Trigger) &&
  6380. (dataType != ReadingContext_Sample_Clock) &&
  6381. ((ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1) || (strstr((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE"))))
  6382. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  6383. else
  6384. {
  6385. if(FirstHeartBeat)
  6386. LWS_Send(queuedata +2);
  6387. }
  6388. return result;
  6389. }
  6390. int sendLogStatusNotificationRequest(char *status)
  6391. {
  6392. mtrace();
  6393. int result = PASS;
  6394. char message[4096]={0};
  6395. char guid[37]={0};
  6396. char tempdata[128]={0};
  6397. json_object *LogStatusNotification = json_object_new_object();
  6398. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6399. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  6400. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  6401. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  6402. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  6403. random_uuid(guid);
  6404. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6405. json_object_put(LogStatusNotification);
  6406. LWS_Send(message);
  6407. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6408. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6409. {
  6410. result = PASS;
  6411. }
  6412. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  6413. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  6414. return result;
  6415. }
  6416. int sendSecurityEventNotificationRequest()
  6417. {
  6418. mtrace();
  6419. int result = PASS;
  6420. char message[4096]={0};
  6421. char guid[37]={0};
  6422. char tempdata[128]={0};
  6423. json_object *SecurityEventNotification = json_object_new_object();
  6424. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6425. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  6426. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  6427. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  6428. random_uuid(guid);
  6429. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6430. json_object_put(SecurityEventNotification);
  6431. LWS_Send(message);
  6432. sprintf(tempdata, "SecurityEventNotification,0");
  6433. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6434. {
  6435. result = PASS;
  6436. }
  6437. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  6438. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  6439. return result;
  6440. }
  6441. int sendSignCertificateRequest()
  6442. {
  6443. mtrace();
  6444. int result = PASS;
  6445. char message[4096]={0};
  6446. char guid[37]={0};
  6447. char tempdata[128]={0};
  6448. json_object *SignCertificate = json_object_new_object();
  6449. DEBUG_INFO("sendSignCertificateRequest...\n");
  6450. // Read csr file content
  6451. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  6452. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  6453. char *line = NULL;
  6454. size_t len = 0;
  6455. while(getline(&line, &len, fp) != -1)
  6456. {
  6457. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  6458. {
  6459. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  6460. }
  6461. }
  6462. fclose(fp);
  6463. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  6464. random_uuid(guid);
  6465. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  6466. json_object_put(SignCertificate);
  6467. LWS_Send(message);
  6468. sprintf(tempdata, "SignCertificate,0");
  6469. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6470. {
  6471. result = PASS;
  6472. }
  6473. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  6474. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  6475. return result;
  6476. }
  6477. int sendSignedFirmwareStatusNotificationRequest(char *status)
  6478. {
  6479. mtrace();
  6480. int result = PASS;
  6481. char message[110]={0};
  6482. char guid[37]={0};
  6483. char tempdata[65]={0};
  6484. json_object *FirmwareStatusNotification = json_object_new_object();
  6485. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  6486. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  6487. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  6488. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  6489. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  6490. random_uuid(guid);
  6491. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6492. json_object_put(FirmwareStatusNotification);
  6493. LWS_Send(message);
  6494. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6495. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6496. {
  6497. result = PASS;
  6498. }
  6499. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  6500. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  6501. return result;
  6502. }
  6503. //==========================================
  6504. // send confirm routine
  6505. //==========================================
  6506. int sendCancelReservationConfirmation(char *uuid,char *payload)
  6507. {
  6508. mtrace();
  6509. int result = FAIL;
  6510. char message[100]={0};
  6511. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  6512. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6513. LWS_Send(message);
  6514. result = TRUE;
  6515. return result;
  6516. }
  6517. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  6518. {
  6519. mtrace();
  6520. int result = FAIL;
  6521. char message[100]={0};
  6522. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  6523. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6524. LWS_Send(message);
  6525. result = TRUE;
  6526. return result;
  6527. }
  6528. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  6529. {
  6530. mtrace();
  6531. int result = FAIL;
  6532. char message[100]={0};
  6533. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  6534. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  6535. LWS_Send(message);
  6536. result = TRUE;
  6537. return result;
  6538. }
  6539. int sendClearCacheConfirmation(char *uuid,char *payload)
  6540. {
  6541. mtrace();
  6542. int result = FAIL;
  6543. char message[500]={0};
  6544. DEBUG_INFO("sendClearCacheConfirmation...\n");
  6545. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6546. LWS_Send(message);
  6547. return result;
  6548. }
  6549. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  6550. {
  6551. mtrace();
  6552. int result = FAIL;
  6553. char message[500]={0};
  6554. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  6555. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6556. LWS_Send(message);
  6557. return result;
  6558. }
  6559. int sendDataTransferConfirmation(char *uuid,char *payload)
  6560. {
  6561. mtrace();
  6562. char statusStr[20]={0};
  6563. char dataStr[10]={0};
  6564. char sstr[20]={0};
  6565. int c = 0;
  6566. char *loc;
  6567. int result = FAIL;
  6568. DEBUG_INFO("sendDataTransferConfirmation...\n");
  6569. /**********************status**************************/
  6570. loc = strstr(payload, "status");
  6571. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6572. c = 0;
  6573. while (loc[3+strlen("status")+c] != '\"')
  6574. {
  6575. sstr[c] = loc[3+strlen("status")+c];
  6576. c++;
  6577. }
  6578. sstr[c] = '\0';
  6579. strcpy(statusStr, sstr);
  6580. /**********************data**************************/
  6581. loc = strstr(payload, "data");
  6582. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6583. c = 0;
  6584. while (loc[3+strlen("data")+c] != '\"')
  6585. {
  6586. sstr[c] = loc[3+strlen("data")+c];
  6587. c++;
  6588. }
  6589. sstr[c] = '\0';
  6590. strcpy(dataStr, sstr);
  6591. return result;
  6592. }
  6593. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  6594. {
  6595. mtrace();
  6596. int result = FAIL;
  6597. char message[1000]={0};
  6598. int CompositeScheduleIndex = 0;
  6599. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  6600. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  6601. if(nPeriod == 0)
  6602. {
  6603. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  6604. {
  6605. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  6606. ,MESSAGE_TYPE_CALLRESULT
  6607. ,uuid
  6608. ,payload
  6609. ,connectorIdInt);
  6610. }
  6611. else
  6612. {
  6613. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  6614. ,MESSAGE_TYPE_CALLRESULT
  6615. ,uuid
  6616. ,payload
  6617. ,connectorIdInt
  6618. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6619. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6620. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6621. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  6622. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  6623. }
  6624. }
  6625. else
  6626. {
  6627. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  6628. ,MESSAGE_TYPE_CALLRESULT
  6629. ,uuid
  6630. ,payload
  6631. ,connectorIdInt
  6632. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6633. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  6634. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  6635. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  6636. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  6637. {
  6638. if (idx_sample == 0)
  6639. {
  6640. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6641. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6642. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6643. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6644. }
  6645. else
  6646. {
  6647. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  6648. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  6649. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  6650. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  6651. }
  6652. }
  6653. sprintf(message + strlen(message), "]}}]");
  6654. }
  6655. LWS_Send(message);
  6656. result = TRUE;
  6657. return result;
  6658. }
  6659. int sendGetConfigurationConfirmation(char *uuid)
  6660. {
  6661. mtrace();
  6662. int result = FAIL;
  6663. int MaxKeySupported = 0;
  6664. int sentConfigurationNumber= 0;
  6665. int sentunConfigurationNumber= 0;
  6666. char message[1024*10]={0};
  6667. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  6668. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  6669. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  6670. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  6671. ,MESSAGE_TYPE_CALLRESULT
  6672. ,uuid );
  6673. //configuration key
  6674. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  6675. {
  6676. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  6677. {
  6678. if (sentConfigurationNumber == 0)
  6679. {
  6680. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6681. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6682. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6683. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6684. }
  6685. else
  6686. {
  6687. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  6688. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  6689. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  6690. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  6691. }
  6692. sentConfigurationNumber = sentConfigurationNumber + 1;
  6693. }
  6694. }
  6695. sprintf(message + strlen(message), "]");
  6696. if(UnknownKeynum != 0)
  6697. {
  6698. sprintf(message + strlen(message), ",\"unknownKey\":[");
  6699. //unkown key
  6700. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  6701. {
  6702. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  6703. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  6704. if(sentunConfigurationNumber == 0)
  6705. {
  6706. sprintf(message + strlen(message), "\"%s\""
  6707. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6708. }
  6709. else
  6710. {
  6711. sprintf(message + strlen(message), ",\"%s\""
  6712. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  6713. }
  6714. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  6715. }
  6716. sprintf(message + strlen(message), "]");
  6717. }
  6718. sprintf(message + strlen(message), "}]");
  6719. LWS_Send(message);
  6720. return result;
  6721. }
  6722. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  6723. {
  6724. mtrace();
  6725. int result = FAIL;
  6726. char message[400]={0};
  6727. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  6728. if(strcmp(payload,"")==0)
  6729. {
  6730. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6731. }
  6732. else
  6733. {
  6734. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6735. }
  6736. LWS_Send(message);
  6737. result = TRUE;
  6738. return result;
  6739. }
  6740. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  6741. {
  6742. mtrace();
  6743. int result = FAIL;
  6744. char message[80]={0};
  6745. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  6746. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  6747. LWS_Send(message);
  6748. result = TRUE;
  6749. return result;
  6750. }
  6751. int sendRemoteStartConfirmation(char *uuid,char *payload)
  6752. {
  6753. mtrace();
  6754. int result = FAIL;
  6755. char message[80]={0};
  6756. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  6757. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6758. LWS_Send(message);
  6759. result = TRUE;
  6760. return result;
  6761. }
  6762. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  6763. {
  6764. mtrace();
  6765. int result = FAIL;
  6766. char message[80]={0};
  6767. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  6768. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6769. LWS_Send(message);
  6770. result = TRUE;
  6771. return result;
  6772. }
  6773. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  6774. {
  6775. mtrace();
  6776. int result = FAIL;
  6777. char message[80]={0};
  6778. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6779. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6780. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6781. LWS_Send(message);
  6782. result = TRUE;
  6783. return result;
  6784. }
  6785. int sendResetConfirmation(char *uuid,char *payload)
  6786. {
  6787. mtrace();
  6788. int result = FAIL;
  6789. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6790. char message[80]={0};
  6791. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6792. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6793. LWS_Send(message);
  6794. result = TRUE;
  6795. return result;
  6796. }
  6797. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6798. {
  6799. mtrace();
  6800. int result = FAIL;
  6801. char message[500]={0};
  6802. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6803. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6804. LWS_Send(message);
  6805. result = TRUE;
  6806. return result;
  6807. }
  6808. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6809. {
  6810. mtrace();
  6811. int result = FAIL;
  6812. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6813. char message[80]={0};
  6814. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6815. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6816. LWS_Send(message);
  6817. result = TRUE;
  6818. return result;
  6819. }
  6820. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6821. {
  6822. mtrace();
  6823. int result = FAIL;
  6824. char message[80]={0};
  6825. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6826. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6827. LWS_Send(message);
  6828. result = TRUE;
  6829. return result;
  6830. }
  6831. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6832. {
  6833. mtrace();
  6834. int result = FAIL;
  6835. char message[80]={0};
  6836. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6837. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6838. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6839. LWS_Send(message);
  6840. result = TRUE;
  6841. return result;
  6842. }
  6843. int sendUpdateFirmwareConfirmation(char *uuid)
  6844. {
  6845. mtrace();
  6846. int result = FAIL;
  6847. char message[60]={0};
  6848. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6849. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6850. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6851. LWS_Send(message);
  6852. result = TRUE;
  6853. return result;
  6854. }
  6855. int sendCertificateSignedConfirmation(char *uuid)
  6856. {
  6857. mtrace();
  6858. int result = PASS;
  6859. char message[4096]={0};
  6860. json_object *CertificateSigned = json_object_new_object();
  6861. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6862. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6863. sprintf(message,"[%d,\"%s\",%s]"
  6864. ,MESSAGE_TYPE_CALLRESULT
  6865. ,uuid
  6866. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6867. json_object_put(CertificateSigned);
  6868. LWS_Send(message);
  6869. return result;
  6870. }
  6871. int sendDeleteCertificateConfirmation(char *uuid)
  6872. {
  6873. mtrace();
  6874. int result = PASS;
  6875. char message[4096]={0};
  6876. json_object *DeleteCertificate = json_object_new_object();
  6877. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6878. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6879. sprintf(message,"[%d,\"%s\",%s]"
  6880. ,MESSAGE_TYPE_CALLRESULT
  6881. ,uuid
  6882. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6883. json_object_put(DeleteCertificate);
  6884. LWS_Send(message);
  6885. return result;
  6886. }
  6887. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6888. {
  6889. mtrace();
  6890. int result = PASS;
  6891. char message[4096]={0};
  6892. json_object *ExtendedTriggerMessage = json_object_new_object();
  6893. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6894. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6895. sprintf(message,"[%d,\"%s\",%s]"
  6896. ,MESSAGE_TYPE_CALLRESULT
  6897. ,uuid
  6898. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6899. json_object_put(ExtendedTriggerMessage);
  6900. LWS_Send(message);
  6901. return result;
  6902. }
  6903. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6904. {
  6905. mtrace();
  6906. int result = PASS;
  6907. char message[4096]={0};
  6908. json_object *GetInstalledCertificateIds = json_object_new_object();
  6909. json_object *certificateHashDataDatas = json_object_new_array();
  6910. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6911. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6912. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6913. {
  6914. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6915. {
  6916. json_object *certificateHashData = json_object_new_object();
  6917. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6918. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6919. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6920. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6921. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6922. }
  6923. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6924. }
  6925. else
  6926. {
  6927. json_object_put(certificateHashDataDatas);
  6928. }
  6929. sprintf(message,"[%d,\"%s\",%s]"
  6930. ,MESSAGE_TYPE_CALLRESULT
  6931. ,uuid
  6932. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6933. json_object_put(GetInstalledCertificateIds);
  6934. LWS_Send(message);
  6935. return result;
  6936. }
  6937. int sendGetLogConfirmation(char *uuid)
  6938. {
  6939. mtrace();
  6940. int result = PASS;
  6941. char message[4096]={0};
  6942. json_object *GetLog = json_object_new_object();
  6943. DEBUG_INFO("sendGetLogConfirmation...\n");
  6944. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6945. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6946. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6947. sprintf(message,"[%d,\"%s\",%s]"
  6948. ,MESSAGE_TYPE_CALLRESULT
  6949. ,uuid
  6950. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6951. json_object_put(GetLog);
  6952. LWS_Send(message);
  6953. return result;
  6954. }
  6955. int sendInstallCertificateConfirmation(char *uuid)
  6956. {
  6957. mtrace();
  6958. int result = PASS;
  6959. char message[4096]={0};
  6960. json_object *InstallCertificate = json_object_new_object();
  6961. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6962. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6963. sprintf(message,"[%d,\"%s\",%s]"
  6964. ,MESSAGE_TYPE_CALLRESULT
  6965. ,uuid
  6966. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6967. json_object_put(InstallCertificate);
  6968. LWS_Send(message);
  6969. return result;
  6970. }
  6971. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6972. {
  6973. mtrace();
  6974. int result = PASS;
  6975. char message[4096]={0};
  6976. json_object *SignedUpdateFirmware = json_object_new_object();
  6977. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6978. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  6979. sprintf(message,"[%d,\"%s\",%s]"
  6980. ,MESSAGE_TYPE_CALLRESULT
  6981. ,uuid
  6982. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6983. json_object_put(SignedUpdateFirmware);
  6984. LWS_Send(message);
  6985. return result;
  6986. }
  6987. int sendUnknownConfirmation(char *uuid)
  6988. {
  6989. mtrace();
  6990. int result = PASS;
  6991. char message[256]={0};
  6992. DEBUG_INFO("sendUnknownConfirmation...\n");
  6993. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6994. LWS_Send(message);
  6995. return result;
  6996. }
  6997. //==========================================
  6998. // Handle server request routine Start
  6999. //==========================================
  7000. int handleCancelReservationRequest(char *uuid, char *payload)
  7001. {
  7002. mtrace();
  7003. int result = FAIL;
  7004. int gunNO = 0;
  7005. int reservationIdInt = -1;
  7006. char comfirmstr[20];
  7007. DEBUG_INFO("handleCancelReservationRequest...\n");
  7008. json_object *CancelReservation;
  7009. CancelReservation = json_tokener_parse(payload);
  7010. if(!is_error(CancelReservation))
  7011. {
  7012. // Required data
  7013. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  7014. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  7015. }
  7016. json_object_put(CancelReservation);
  7017. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  7018. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7019. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  7020. if(reservationIdInt != -1)
  7021. {
  7022. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7023. //check Transaction active
  7024. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7025. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7026. {
  7027. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  7028. {
  7029. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7030. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7031. if(gunType[2] == GUN_TYPE_CHAdeMO)
  7032. {
  7033. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  7034. }
  7035. else
  7036. {
  7037. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  7038. }
  7039. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7040. goto end;
  7041. }
  7042. }
  7043. for (int index = 0; index < CCS_QUANTITY; index++)
  7044. {
  7045. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  7046. {
  7047. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7048. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7049. if(gunType[2] == GUN_TYPE_CCS)
  7050. {
  7051. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  7052. }
  7053. else
  7054. {
  7055. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  7056. }
  7057. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7058. goto end;
  7059. }
  7060. }
  7061. for (int index = 0; index < GB_QUANTITY; index++)
  7062. {
  7063. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  7064. {
  7065. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7066. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7067. if(gunType[2] == GUN_TYPE_GBT)
  7068. {
  7069. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  7070. }
  7071. else
  7072. {
  7073. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  7074. }
  7075. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7076. goto end;
  7077. }
  7078. }
  7079. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7080. {
  7081. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  7082. {
  7083. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7084. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7085. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  7086. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7087. goto end;
  7088. }
  7089. }
  7090. for (int index = 0; index < AC_QUANTITY; index++)
  7091. {
  7092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  7093. {
  7094. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  7095. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  7096. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7097. {
  7098. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  7099. }
  7100. else
  7101. {
  7102. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  7103. }
  7104. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  7105. goto end;
  7106. }
  7107. }
  7108. }
  7109. //The reservationId does NOT match the reservationId
  7110. sendCancelReservationConfirmation(uuid, comfirmstr);
  7111. end:
  7112. // Fill in ocpp packet uuid
  7113. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  7114. return result;
  7115. }
  7116. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  7117. {
  7118. mtrace();
  7119. int result = FAIL;
  7120. int gunIndex = 0;
  7121. char typeStr[16]={0};
  7122. char comfirmstr[20];
  7123. int specificId = FALSE;
  7124. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  7125. json_object *ChangeAvailability;
  7126. ChangeAvailability = json_tokener_parse(payload);
  7127. if(!is_error(ChangeAvailability))
  7128. {
  7129. // Required data
  7130. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  7131. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  7132. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  7133. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  7134. }
  7135. json_object_put(ChangeAvailability);
  7136. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7137. {
  7138. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  7139. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  7140. }
  7141. else if(gunIndex == 0)
  7142. {
  7143. for(int i=0; i < gunTotalNumber; i++)
  7144. {
  7145. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  7146. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  7147. }
  7148. }
  7149. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  7150. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7151. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  7152. {
  7153. specificId = TRUE;
  7154. }
  7155. if(specificId == FALSE)
  7156. goto end;
  7157. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  7158. {
  7159. //----------------------gunIndex is 0 ------------------------------------------------//
  7160. if(gunIndex == 0)
  7161. {
  7162. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7163. {
  7164. for(int i=0; i < gunTotalNumber; i++)
  7165. {
  7166. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7167. {
  7168. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  7169. {
  7170. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7171. {
  7172. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7173. goto end;
  7174. }
  7175. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7176. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7177. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7178. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7179. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7180. {
  7181. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7182. goto end;
  7183. }
  7184. }
  7185. }//END FOR CHAdeMO_QUANTITY
  7186. for (int index = 0; index < CCS_QUANTITY; index++)
  7187. {
  7188. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  7189. {
  7190. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  7191. {
  7192. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7193. goto end;
  7194. }
  7195. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7196. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7197. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7198. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7199. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7200. {
  7201. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7202. goto end;
  7203. }
  7204. }
  7205. }//END FOR CCS_QUANTITY
  7206. for (int index = 0; index < GB_QUANTITY; index++)
  7207. {
  7208. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  7209. {
  7210. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7211. {
  7212. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7213. goto end;
  7214. }
  7215. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7216. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7217. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7218. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7219. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7220. {
  7221. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7222. goto end;
  7223. }
  7224. }
  7225. }// END FOR GB_QUANTITY
  7226. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7227. {
  7228. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  7229. {
  7230. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7231. {
  7232. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7233. goto end;
  7234. }
  7235. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7236. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7237. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7238. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7239. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7240. {
  7241. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7242. goto end;
  7243. }
  7244. }
  7245. }// END FOR GENERAL_GUN_QUANTITY
  7246. for (int index = 0; index < AC_QUANTITY; index++)
  7247. {
  7248. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  7249. {
  7250. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7251. {
  7252. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7253. goto end;
  7254. }
  7255. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7256. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7257. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7258. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7259. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7260. {
  7261. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7262. goto end;
  7263. }
  7264. }
  7265. }//END FOR AC_QUANTITY
  7266. }// END FOR gunTotalNumber
  7267. }
  7268. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7269. {
  7270. for(int i=0; i < gunTotalNumber; i++)
  7271. {
  7272. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  7273. {
  7274. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7275. goto end;
  7276. }
  7277. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7278. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  7279. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  7280. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  7281. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7282. {
  7283. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7284. goto end;
  7285. }
  7286. }
  7287. }
  7288. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7289. goto end;
  7290. }
  7291. //----------------------gunIndex is not 0 ------------------------------------------------//
  7292. //check Transaction active
  7293. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7294. {
  7295. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  7296. {
  7297. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  7298. {
  7299. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7300. goto end;
  7301. }
  7302. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7303. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7304. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7305. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7306. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7307. {
  7308. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7309. goto end;
  7310. }
  7311. else
  7312. {
  7313. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  7314. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7315. goto end;
  7316. }
  7317. }
  7318. }//END FOR CHAdeMO_QUANTITY
  7319. for (int index = 0; index < CCS_QUANTITY; index++)
  7320. {
  7321. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  7322. {
  7323. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  7324. {
  7325. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7326. goto end;
  7327. }
  7328. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7329. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7330. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7331. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7332. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7333. {
  7334. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7335. goto end;
  7336. }
  7337. else
  7338. {
  7339. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  7340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7341. goto end;
  7342. }
  7343. }
  7344. }//END FOR CCS_QUANTITY
  7345. for (int index = 0; index < GB_QUANTITY; index++)
  7346. {
  7347. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  7348. {
  7349. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7350. {
  7351. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7352. goto end;
  7353. }
  7354. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7355. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7356. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7357. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7358. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7359. {
  7360. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7361. goto end;
  7362. }
  7363. else
  7364. {
  7365. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  7366. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7367. goto end;
  7368. }
  7369. }
  7370. }// END FOR GB_QUANTITY
  7371. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7372. {
  7373. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  7374. {
  7375. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7376. {
  7377. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7378. goto end;
  7379. }
  7380. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  7381. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  7382. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  7383. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  7384. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7385. {
  7386. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7387. goto end;
  7388. }
  7389. else
  7390. {
  7391. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  7392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7393. goto end;
  7394. }
  7395. }
  7396. }// END FOR GENERAL_GUN_QUANTITY
  7397. for (int index = 0; index < AC_QUANTITY; index++)
  7398. {
  7399. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  7400. {
  7401. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  7402. {
  7403. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7404. goto end;
  7405. }
  7406. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  7407. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  7408. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  7409. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  7410. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  7411. {
  7412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  7413. goto end;
  7414. }
  7415. else
  7416. {
  7417. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  7418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7419. goto end;
  7420. }
  7421. }
  7422. }//END FOR AC_QUANTITY
  7423. }//END FOR AvailabilityTypeStr[Inoperative]
  7424. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  7425. {
  7426. //----------------------gunIndex is 0 ------------------------------------------------//
  7427. if(gunIndex == 0)
  7428. {
  7429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7430. {
  7431. for(int i=0; i < gunTotalNumber; i++)
  7432. {
  7433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7434. {
  7435. 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
  7436. {
  7437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7438. goto end;
  7439. }
  7440. }//END FOR CHAdeMO_QUANTITY
  7441. for (int index = 0; index < CCS_QUANTITY; index++)
  7442. {
  7443. 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
  7444. {
  7445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7446. goto end;
  7447. }
  7448. }//END FOR CCS_QUANTITY
  7449. for (int index = 0; index < GB_QUANTITY; index++)
  7450. {
  7451. 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
  7452. {
  7453. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7454. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7455. goto end;
  7456. }
  7457. }// END FOR GB_QUANTITY
  7458. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7459. {
  7460. 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
  7461. {
  7462. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7463. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7464. goto end;
  7465. }
  7466. }// END FOR GENERAL_GUN_QUANTITY
  7467. for (int index = 0; index < AC_QUANTITY; index++)
  7468. {
  7469. 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
  7470. {
  7471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7472. goto end;
  7473. }
  7474. }//END FOR CHAdeMO_QUANTITY
  7475. }// END FOR gunTotalNumber
  7476. }
  7477. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  7478. {
  7479. for(int i=0; i < gunTotalNumber; i++)
  7480. {
  7481. for (int index = 0; index < AC_QUANTITY; index++)
  7482. {
  7483. 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
  7484. {
  7485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  7486. goto end;
  7487. }
  7488. }//END FOR CHAdeMO_QUANTITY
  7489. } // END FOR gunTotalNumber
  7490. }
  7491. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7492. goto end;
  7493. }
  7494. //----------------------gunIndex is not 0 ------------------------------------------------//
  7495. //check Transaction active
  7496. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7497. {
  7498. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7499. {
  7500. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7501. goto end;
  7502. }
  7503. }//END FOR CHAdeMO_QUANTITY
  7504. for (int index = 0; index < CCS_QUANTITY; index++)
  7505. {
  7506. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7507. {
  7508. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7509. goto end;
  7510. }
  7511. }//END FOR CCS_QUANTITY
  7512. for (int index = 0; index < GB_QUANTITY; index++)
  7513. {
  7514. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7515. {
  7516. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7517. goto end;
  7518. }
  7519. }// END FOR GB_QUANTITY
  7520. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7521. {
  7522. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7523. {
  7524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7525. goto end;
  7526. }
  7527. }// END FOR GENERAL_GUN_QUANTITY
  7528. for (int index = 0; index < AC_QUANTITY; index++)
  7529. {
  7530. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  7531. {
  7532. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  7533. goto end;
  7534. }
  7535. }//END FOR AC_QUANTITY
  7536. }//END FOR AvailabilityTypeStr[Operative]
  7537. end:
  7538. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7539. {
  7540. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  7541. }
  7542. else
  7543. {
  7544. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  7545. }
  7546. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  7547. {
  7548. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7549. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  7550. }
  7551. else if(gunIndex == 0)
  7552. {
  7553. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  7554. {
  7555. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  7556. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  7557. }
  7558. }
  7559. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  7560. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7561. return result;
  7562. }
  7563. int handleChangeConfigurationRequest(char *uuid, char *payload)
  7564. {
  7565. mtrace();
  7566. int result = FAIL;
  7567. char keystr[40]={0};
  7568. char valuestr[256]={0};
  7569. char comfirmstr[20]={0};
  7570. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  7571. json_object *ChangeConfiguration;
  7572. ChangeConfiguration = json_tokener_parse(payload);
  7573. if(!is_error(ChangeConfiguration))
  7574. {
  7575. // Required data
  7576. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  7577. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  7578. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  7579. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  7580. }
  7581. json_object_put(ChangeConfiguration);
  7582. if((uuid==NULL) || (payload ==NULL) )
  7583. {
  7584. DEBUG_ERROR("Payload is null\n");
  7585. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7586. }
  7587. else
  7588. {
  7589. int status = setKeyValue(keystr, valuestr);
  7590. switch(status)
  7591. {
  7592. case ConfigurationStatus_Accepted:
  7593. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  7594. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  7595. StoreConfigurationTable();
  7596. break;
  7597. case RebootRequired:
  7598. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  7599. StoreConfigurationTable();
  7600. break;
  7601. case NotSupported:
  7602. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  7603. break;
  7604. case ConfigurationStatus_Rejected:
  7605. default:
  7606. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  7607. break;
  7608. }
  7609. }
  7610. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  7611. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  7612. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7613. {
  7614. ChageWebSocketPingInterval(atoi(valuestr));
  7615. }
  7616. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  7617. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  7618. {
  7619. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7620. SetOcppConnStatus(FALSE);
  7621. }
  7622. return result;
  7623. }
  7624. int handleClearCacheRequest(char *uuid, char *payload)
  7625. {
  7626. mtrace();
  7627. int result = FAIL;
  7628. char comfirmstr[20];
  7629. char rmFileCmd[100]={0};
  7630. struct stat stats;
  7631. DEBUG_INFO("handleClearCacheRequest...\n");
  7632. stat("/Storage/OCPP_PH", &stats);
  7633. // Check for directory existence
  7634. if (S_ISDIR(stats.st_mode) == 1)
  7635. {}
  7636. else
  7637. {
  7638. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  7639. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  7640. system(rmFileCmd);
  7641. }
  7642. if(OCPP_cleanLocalCache())
  7643. {
  7644. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  7645. }
  7646. else
  7647. {
  7648. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  7649. }
  7650. sendClearCacheConfirmation(uuid, comfirmstr);
  7651. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7652. return result;
  7653. }
  7654. int handleClearChargingProfileRequest(char *uuid, char *payload)
  7655. {
  7656. mtrace();
  7657. int result = FAIL;
  7658. int resultRename;
  7659. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  7660. char chargingProfilePurposeStr[26]={0};
  7661. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  7662. char tempchargingProfilePurposeStr[26]={0};
  7663. char str[100]={0};
  7664. char fname[200]={0};
  7665. char comfirmstr[20]={0};
  7666. char word[1600]={0};
  7667. int clearflag = FALSE;
  7668. int chargingProfileIdIsNULL = FALSE;
  7669. int connectorIsNULL = FALSE;
  7670. int chargingProfilePurposeIsNULL = FALSE;
  7671. int stackLevelIsNULL = FALSE;
  7672. //int GotoEnd = FALSE;
  7673. FILE *fptr1, *fptr2;
  7674. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  7675. int n_chargingProfile=0;
  7676. int isEmptyFile = FALSE;
  7677. char sLineWord[1600]={0};
  7678. char chargingProfiles[10][100]={0};
  7679. int ChargeProfileCount = 0;
  7680. int ch;
  7681. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  7682. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  7683. json_object *ClearChargingProfile;
  7684. ClearChargingProfile = json_tokener_parse(payload);
  7685. if(!is_error(ClearChargingProfile))
  7686. {
  7687. // Optional data
  7688. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  7689. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  7690. else
  7691. chargingProfileIdIsNULL = TRUE;
  7692. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  7693. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  7694. else
  7695. connectorIsNULL = TRUE;
  7696. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  7697. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  7698. else
  7699. chargingProfilePurposeIsNULL = TRUE;
  7700. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  7701. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  7702. else
  7703. stackLevelIsNULL = TRUE;
  7704. }
  7705. json_object_put(ClearChargingProfile);
  7706. if(connectorIsNULL == FALSE)
  7707. {
  7708. switch(connectorIdInt)
  7709. {
  7710. case 0:
  7711. if(chargingProfilePurposeIsNULL == TRUE)
  7712. {
  7713. int l = 0;
  7714. strcpy(fname, ChargePointMaxProfile_JSON);
  7715. if((access(fname,F_OK))!=-1)
  7716. {
  7717. strcpy(chargingProfiles[l], fname);
  7718. l = l + 1;
  7719. }
  7720. strcpy(fname, TxDefaultProfile_0_JSON);
  7721. if((access(fname,F_OK))!=-1)
  7722. {
  7723. strcpy(chargingProfiles[l], fname);
  7724. l = l + 1;
  7725. }
  7726. ChargeProfileCount = l;
  7727. }
  7728. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  7729. {
  7730. strcpy(fname, ChargePointMaxProfile_JSON);
  7731. if((access(fname,F_OK))!=-1)
  7732. {
  7733. strcpy(chargingProfiles[0], fname);
  7734. ChargeProfileCount = 1;
  7735. }
  7736. }
  7737. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7738. {
  7739. strcpy(fname, TxDefaultProfile_0_JSON);
  7740. if((access(fname,F_OK))!=-1)
  7741. {
  7742. strcpy(chargingProfiles[0], fname);
  7743. ChargeProfileCount = 1;
  7744. }
  7745. }
  7746. break;
  7747. default:
  7748. if(chargingProfilePurposeIsNULL == TRUE)
  7749. {
  7750. int m = 0;
  7751. memset(fname, 0, ARRAY_SIZE(fname));
  7752. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7753. if((access(fname,F_OK))!=-1)
  7754. {
  7755. strcpy(chargingProfiles[m], fname);
  7756. m = m + 1;
  7757. }
  7758. memset(fname, 0, ARRAY_SIZE(fname));
  7759. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7760. if((access(fname,F_OK))!=-1)
  7761. {
  7762. strcpy(chargingProfiles[m], fname);
  7763. m = m + 1;
  7764. }
  7765. ChargeProfileCount = m;
  7766. }
  7767. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  7768. {
  7769. //strcpy(fname, TxDefaultProfile_1_JSON);
  7770. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  7771. if((access(fname,F_OK))!=-1)
  7772. {
  7773. strcpy(chargingProfiles[0], fname);
  7774. ChargeProfileCount = 1;
  7775. }
  7776. }
  7777. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7778. {
  7779. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7780. if((access(fname,F_OK))!=-1)
  7781. {
  7782. strcpy(chargingProfiles[0], fname);
  7783. ChargeProfileCount = 1;
  7784. }
  7785. //strcpy(fname, TxProfile_1_JSON);
  7786. }
  7787. //strcpy(fname, ChargePointMaxProfile_JSON );
  7788. break;
  7789. }
  7790. }
  7791. else // Check all Charging Profiles
  7792. {
  7793. int i = 0;
  7794. char fnametemp[200]={0};
  7795. ChargeProfileCount = 0;
  7796. //Check ChargePointMaxProfile.json exit
  7797. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7798. {
  7799. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7800. i = i + 1;
  7801. }
  7802. //Check TxDefaultProfile_0.json exit
  7803. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7804. {
  7805. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7806. i = i + 1;
  7807. }
  7808. //Check TxDefaultProfile_%d.json
  7809. for(int j=1; j <= gunTotalNumber; j++)
  7810. {
  7811. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7812. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7813. if((access(fnametemp,F_OK))!=-1)
  7814. {
  7815. strcpy(chargingProfiles[i], fnametemp);
  7816. i = i + 1;
  7817. }
  7818. }
  7819. //Check TxProfile_%d.json
  7820. for(int j=1; j <= gunTotalNumber; j++)
  7821. {
  7822. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7823. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7824. if((access(fnametemp,F_OK))!=-1)
  7825. {
  7826. strcpy(chargingProfiles[i], fnametemp);
  7827. i = i + 1;
  7828. }
  7829. }
  7830. ChargeProfileCount = i;
  7831. }// End connectorIsNULL is TRUE
  7832. if(ChargeProfileCount == 0)
  7833. {
  7834. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7835. goto end;
  7836. }
  7837. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7838. {
  7839. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7840. goto end;
  7841. }
  7842. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7843. {
  7844. memset(str, 0, ARRAY_SIZE(str));
  7845. // clear temp file
  7846. sprintf(str,"rm -f %s",temp);
  7847. system(str);
  7848. for(int k=0; k < ChargeProfileCount; k++)
  7849. {
  7850. memset(str, 0, ARRAY_SIZE(str));
  7851. //clear file in C
  7852. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7853. system(str);
  7854. }
  7855. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7856. goto end;
  7857. }
  7858. else if(connectorIsNULL == TRUE)
  7859. {
  7860. for(int k=0; k < ChargeProfileCount; k++)
  7861. {
  7862. fptr1 = fopen(chargingProfiles[k], "r");
  7863. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7864. //Check Charging Profile Count
  7865. while(fscanf(fptr1, "%s", word) != EOF)
  7866. {
  7867. //DEBUG_INFO("word=%s\n",word);
  7868. if(strstr(word, "chargingProfileId")!= NULL)
  7869. {
  7870. //DEBUG_INFO("test chargingProfileId \n");
  7871. n_chargingProfile = n_chargingProfile + 1;
  7872. //DEBUG_INFO("chargingProfileId Found\n");
  7873. }
  7874. }
  7875. rewind(fptr1);
  7876. //search Charging Profile Element
  7877. //int i= 0;
  7878. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7879. {
  7880. json_object *tmpProfilee;
  7881. tmpProfilee = json_tokener_parse(sLineWord);
  7882. if(!is_error(tmpProfilee))
  7883. {
  7884. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7885. {
  7886. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7887. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7888. }
  7889. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7890. {
  7891. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7892. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7893. }
  7894. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7895. {
  7896. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7897. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7898. }
  7899. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7900. {
  7901. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7902. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7903. }
  7904. }
  7905. json_object_put(tmpProfilee);
  7906. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7907. {
  7908. //------- not write to fptr2-------//
  7909. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7910. //clearflag = TRUE;
  7911. }
  7912. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7913. {
  7914. //------- not write to fptr2-------//
  7915. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7916. }
  7917. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7918. {
  7919. //------- not write to fptr2-------//
  7920. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7921. }
  7922. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7923. {
  7924. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7925. }
  7926. else
  7927. {
  7928. fprintf(fptr2, sLineWord);//writing data into file
  7929. }
  7930. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7931. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7932. if(clearflag == TRUE)
  7933. {
  7934. fclose(fptr1);
  7935. fclose(fptr2);
  7936. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7937. system(str);
  7938. // clear temp file
  7939. sprintf(str,"rm -f %s",temp);
  7940. system(str);
  7941. }
  7942. else
  7943. {
  7944. fclose(fptr1);
  7945. fclose(fptr2);
  7946. memset(str, 0, ARRAY_SIZE(str));
  7947. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7948. system(str);
  7949. resultRename = rename(temp, chargingProfiles[k]);
  7950. if(resultRename == 0)
  7951. {
  7952. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7953. }
  7954. else
  7955. {
  7956. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7957. }
  7958. if(comfirmstr[0]== 0)
  7959. {
  7960. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7961. }
  7962. //Check chargingProfile is empty file
  7963. /*------ Read the file ----------------*/
  7964. fptr1=fopen(chargingProfiles[k],"r");
  7965. ch=fgetc(fptr1);
  7966. rewind(fptr1);
  7967. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7968. if(ch!=EOF)
  7969. {
  7970. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7971. {
  7972. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7973. if(sLineWord[0]=='\0')
  7974. {
  7975. isEmptyFile = TRUE;
  7976. break;
  7977. }
  7978. else
  7979. {
  7980. isEmptyFile = FALSE;
  7981. break;
  7982. }
  7983. }
  7984. }
  7985. else
  7986. isEmptyFile = TRUE;
  7987. fclose(fptr1);
  7988. if(isEmptyFile == TRUE)
  7989. {
  7990. memset(str, 0, ARRAY_SIZE(str));
  7991. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7992. system(str);
  7993. }
  7994. }
  7995. }// End of while(int k=0; k < ChargePointCount; k++)
  7996. }
  7997. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7998. {
  7999. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  8000. for(int k=0; k < ChargeProfileCount; k++)
  8001. {
  8002. fptr1 = fopen(chargingProfiles[k], "r");
  8003. fptr2 = fopen(temp, "w+");
  8004. //Check Charging Profile Count
  8005. while(fscanf(fptr1, "%s", word) != EOF)
  8006. {
  8007. //DEBUG_INFO("word=%s\n",word);
  8008. if(strstr(word, "chargingProfileId")!= NULL)
  8009. {
  8010. n_chargingProfile = n_chargingProfile + 1;
  8011. }
  8012. }
  8013. rewind(fptr1);
  8014. //search Charging Profile Element
  8015. //int i= 0;
  8016. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  8017. {
  8018. json_object *tmpProfilee;
  8019. tmpProfilee = json_tokener_parse(sLineWord);
  8020. if(!is_error(tmpProfilee))
  8021. {
  8022. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  8023. {
  8024. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  8025. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  8026. }
  8027. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  8028. {
  8029. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  8030. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  8031. }
  8032. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  8033. {
  8034. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  8035. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  8036. }
  8037. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8038. {
  8039. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  8040. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  8041. }
  8042. }
  8043. json_object_put(tmpProfilee);
  8044. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  8045. {
  8046. //------- not write to fptr2-------//
  8047. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8048. //clearflag = TRUE;
  8049. }
  8050. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  8051. {
  8052. //------- not write to fptr2-------//
  8053. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8054. }
  8055. else if(stackLevelIsNULL == TRUE)
  8056. {
  8057. //Clear Whole File
  8058. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  8059. clearflag = TRUE;
  8060. break;
  8061. }
  8062. else
  8063. {
  8064. fprintf(fptr2, sLineWord);//writing data into file
  8065. }
  8066. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8067. }
  8068. if(clearflag == TRUE)
  8069. {
  8070. fclose(fptr1);
  8071. fclose(fptr2);
  8072. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8073. system(str);
  8074. // clear temp file
  8075. sprintf(str,"rm -f %s",temp);
  8076. system(str);
  8077. }
  8078. else
  8079. {
  8080. fclose(fptr1);
  8081. fclose(fptr2);
  8082. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8083. system(str);
  8084. resultRename = rename(temp, chargingProfiles[k]);
  8085. if(resultRename == 0)
  8086. {
  8087. DEBUG_INFO("File ChargingProfile renamed successfully");
  8088. }
  8089. else
  8090. {
  8091. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  8092. }
  8093. if(comfirmstr[0]== 0)
  8094. {
  8095. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  8096. }
  8097. //Check chargingProfile is empty file
  8098. /*------ Read the file ----------------*/
  8099. fptr1=fopen(chargingProfiles[k],"r");
  8100. ch=fgetc(fptr1);
  8101. rewind(fptr1);
  8102. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  8103. if(ch!=EOF)
  8104. {
  8105. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  8106. {
  8107. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  8108. if(sLineWord[0]=='\0')
  8109. {
  8110. isEmptyFile = TRUE;
  8111. break;
  8112. }
  8113. else
  8114. {
  8115. isEmptyFile = FALSE;
  8116. break;
  8117. }
  8118. }
  8119. }
  8120. else
  8121. isEmptyFile = TRUE;
  8122. fclose(fptr1);
  8123. if(isEmptyFile == TRUE)
  8124. {
  8125. memset(str, 0, ARRAY_SIZE(str));
  8126. sprintf(str,"rm -f %s",chargingProfiles[k]);
  8127. system(str);
  8128. }
  8129. /*------- End of reading ---------------*/
  8130. }
  8131. } // while(int k=0; k < ChargeProfileCount; k++)
  8132. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  8133. end:
  8134. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  8135. {
  8136. if(connectorIdInt == 0)
  8137. {
  8138. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  8139. {
  8140. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  8141. }
  8142. }
  8143. else
  8144. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  8145. }
  8146. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  8147. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  8148. return result;
  8149. }
  8150. void createFirmwareVersionByDataTransfer(void)
  8151. {
  8152. json_object *FirmwareDataTransfer = json_object_new_object();
  8153. // AC & DC model
  8154. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  8155. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  8156. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  8157. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  8158. // DC model
  8159. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  8160. {
  8161. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  8162. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  8163. (gunType[3] != GUN_TYPE_UNKNOWN))
  8164. {
  8165. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  8166. }
  8167. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  8168. {
  8169. // DS DM DW
  8170. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8171. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8172. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  8173. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  8174. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8175. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8176. }
  8177. else
  8178. {
  8179. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  8180. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  8181. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  8182. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  8183. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  8184. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  8185. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  8186. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  8187. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  8188. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  8189. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  8190. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  8191. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  8192. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  8193. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  8194. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  8195. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  8196. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  8197. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  8198. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  8199. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  8200. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  8201. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  8202. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  8203. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  8204. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  8205. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  8206. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  8207. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  8208. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  8209. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  8210. }
  8211. }
  8212. // 4G model
  8213. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  8214. {
  8215. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  8216. }
  8217. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8218. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  8219. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  8220. json_object_put(FirmwareDataTransfer);
  8221. }
  8222. int handleDataTransferRequest(char *uuid, char *payload)
  8223. {
  8224. mtrace();
  8225. json_object *response = json_object_new_object();
  8226. int result = FAIL;
  8227. char tempvendorId[255]={0};
  8228. char tempmessageId[50]={0};
  8229. char tempdata[512]={0};
  8230. char message[2048]={0};
  8231. DEBUG_INFO("handleDataTransferRequest...\n");
  8232. if((uuid != NULL) && (payload != NULL))
  8233. {
  8234. json_object *DataTransfer;
  8235. DataTransfer = json_tokener_parse(payload);
  8236. if(!is_error(DataTransfer))
  8237. {
  8238. // Required data
  8239. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  8240. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  8241. // Optional data
  8242. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  8243. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  8244. if(json_object_object_get(DataTransfer, "data") != NULL)
  8245. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  8246. result = PASS;
  8247. }
  8248. json_object_put(DataTransfer);
  8249. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  8250. {
  8251. // Send all moudle firmware version on EVSE
  8252. createFirmwareVersionByDataTransfer();
  8253. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8254. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  8255. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8256. json_object_put(response);
  8257. }
  8258. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  8259. {
  8260. system("/usr/bin/run_tmate_restart.sh &");
  8261. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8262. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8263. json_object_put(response);
  8264. }
  8265. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  8266. {
  8267. json_object *data;
  8268. data = json_tokener_parse(tempdata);
  8269. if(!is_error(data))
  8270. {
  8271. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  8272. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  8273. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  8274. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  8275. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  8276. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  8277. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  8278. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  8279. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  8280. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  8281. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8282. }
  8283. else
  8284. {
  8285. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8286. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8287. }
  8288. json_object_put(data);
  8289. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8290. json_object_put(response);
  8291. }
  8292. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  8293. {
  8294. json_object *data;
  8295. data = json_tokener_parse(tempdata);
  8296. if(!is_error(data))
  8297. {
  8298. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  8299. if(json_object_object_get(data, "idToken") != NULL)
  8300. {
  8301. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  8302. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  8303. }
  8304. if(json_object_object_get(data, "price") != NULL)
  8305. {
  8306. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  8307. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  8308. }
  8309. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8310. }
  8311. else
  8312. {
  8313. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8314. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8315. }
  8316. json_object_put(data);
  8317. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8318. json_object_put(response);
  8319. }
  8320. else if(strstr(tempmessageId, "RunningCost") != NULL)
  8321. {
  8322. json_object *data;
  8323. data = json_tokener_parse(tempdata);
  8324. if(!is_error(data))
  8325. {
  8326. if(json_object_object_get(data, "txId") != NULL)
  8327. {
  8328. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8329. for(int idx = 0;idx<gunTotalNumber;idx++)
  8330. {
  8331. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8332. {
  8333. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningCost));
  8334. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8335. if(json_object_object_get(data, "description") != NULL)
  8336. {
  8337. // California pricing V1.0
  8338. DEBUG_INFO("California pricing V1.0\n");
  8339. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8340. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8341. }
  8342. else
  8343. {
  8344. // California pricing V1.1
  8345. DEBUG_INFO("California pricing V1.1\n");
  8346. if(json_object_object_get(data, "timestamp") != NULL)
  8347. {
  8348. DEBUG_INFO("timestamp: %s\n", json_object_get_string(json_object_object_get(data, "timestamp")));
  8349. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].timestamp, "%s", json_object_get_string(json_object_object_get(data, "timestamp")));
  8350. }
  8351. if(json_object_object_get(data, "meterValue") != NULL)
  8352. {
  8353. DEBUG_INFO("meterValue: %d\n", json_object_get_int(json_object_object_get(data, "meterValue")));
  8354. ShmOCPP16DataPH->Cost.RunningCost[idx].meterValue = json_object_get_int(json_object_object_get(data, "meterValue"));
  8355. }
  8356. if(json_object_object_get(data, "cost") != NULL)
  8357. {
  8358. DEBUG_INFO("cost: %f\n", json_object_get_double(json_object_object_get(data, "cost")));
  8359. ShmOCPP16DataPH->Cost.RunningCost[idx].cost = json_object_get_double(json_object_object_get(data, "cost"));
  8360. }
  8361. if(json_object_object_get(data, "state") != NULL)
  8362. {
  8363. DEBUG_INFO("state: %s\n", json_object_get_string(json_object_object_get(data, "state")));
  8364. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].state, "%s", json_object_get_string(json_object_object_get(data, "state")));
  8365. }
  8366. if(json_object_object_get(data, "chargingPrice") != NULL)
  8367. {
  8368. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice") != NULL)
  8369. {
  8370. DEBUG_INFO("chargingPrice-kWhPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice")));
  8371. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.kWhPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "kWhPrice"));
  8372. }
  8373. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice") != NULL)
  8374. {
  8375. DEBUG_INFO("chargingPrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice")));
  8376. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "hourPrice"));
  8377. }
  8378. if(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee") != NULL)
  8379. {
  8380. DEBUG_INFO("chargingPrice-flatFee: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee")));
  8381. ShmOCPP16DataPH->Cost.RunningCost[idx].chargingPrice.flatFee = json_object_get_double(json_object_object_get(json_object_object_get(data, "chargingPrice"), "flatFee"));
  8382. }
  8383. }
  8384. if(json_object_object_get(data, "idlePrice") != NULL)
  8385. {
  8386. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes") != NULL)
  8387. {
  8388. DEBUG_INFO("idlePrice-graceMinutes: %d\n", json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes")));
  8389. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.graceMinutes = json_object_get_int(json_object_object_get(json_object_object_get(data, "idlePrice"), "graceMinutes"));
  8390. }
  8391. if(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice") != NULL)
  8392. {
  8393. DEBUG_INFO("idlePrice-hourPrice: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice")));
  8394. ShmOCPP16DataPH->Cost.RunningCost[idx].idlePrice.hourPrice = json_object_get_double(json_object_object_get(json_object_object_get(data, "idlePrice"), "hourPrice"));
  8395. }
  8396. }
  8397. if(json_object_object_get(data, "nextPeriod") != NULL)
  8398. {
  8399. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime") != NULL)
  8400. {
  8401. DEBUG_INFO("nextPeriod-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8402. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].nextPeriod.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "nextPeriod"), "atTime")));
  8403. }
  8404. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice") != NULL)
  8405. {
  8406. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "kWhPrice") != NULL)
  8407. {
  8408. 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")));
  8409. 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"));
  8410. }
  8411. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "hourPrice") != NULL)
  8412. {
  8413. 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")));
  8414. 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"));
  8415. }
  8416. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "chargingPrice"), "flatFee") != NULL)
  8417. {
  8418. 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")));
  8419. 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"));
  8420. }
  8421. }
  8422. if(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice") != NULL)
  8423. {
  8424. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "graceMinutes") != NULL)
  8425. {
  8426. 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")));
  8427. 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"));
  8428. }
  8429. if(json_object_object_get(json_object_object_get(json_object_object_get(data, "nextPeriod"), "idlePrice"), "hourPrice") != NULL)
  8430. {
  8431. 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")));
  8432. 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"));
  8433. }
  8434. }
  8435. }
  8436. if(json_object_object_get(data, "triggerMeterValue") != NULL)
  8437. {
  8438. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime") != NULL)
  8439. {
  8440. DEBUG_INFO("triggerMeterValue-atTime: %s\n", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8441. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atTime")));
  8442. }
  8443. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh") != NULL)
  8444. {
  8445. DEBUG_INFO("triggerMeterValue-atEnergykWh: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh")));
  8446. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atEnergykWh = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atEnergykWh"));
  8447. }
  8448. if(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW") != NULL)
  8449. {
  8450. DEBUG_INFO("triggerMeterValue-atPowerkW: %f\n", json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW")));
  8451. ShmOCPP16DataPH->Cost.RunningCost[idx].triggerMeterValue.atPowerkW = json_object_get_double(json_object_object_get(json_object_object_get(data, "triggerMeterValue"), "atPowerkW"));
  8452. }
  8453. }
  8454. }
  8455. }
  8456. }
  8457. }
  8458. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8459. }
  8460. else
  8461. {
  8462. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8463. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8464. }
  8465. json_object_put(data);
  8466. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8467. json_object_put(response);
  8468. }
  8469. else if(strstr(tempmessageId, "FinalCost") != NULL)
  8470. {
  8471. json_object *data;
  8472. data = json_tokener_parse(tempdata);
  8473. if(!is_error(data))
  8474. {
  8475. if(json_object_object_get(data, "txId") != NULL)
  8476. {
  8477. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  8478. for(int idx = 0;idx<gunTotalNumber;idx++)
  8479. {
  8480. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  8481. {
  8482. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutFinalCost));
  8483. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  8484. if(json_object_object_get(data, "description") != NULL)
  8485. {
  8486. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  8487. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  8488. }
  8489. }
  8490. }
  8491. }
  8492. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8493. }
  8494. else
  8495. {
  8496. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8497. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8498. }
  8499. json_object_put(data);
  8500. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8501. json_object_put(response);
  8502. }
  8503. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  8504. {
  8505. json_object *data;
  8506. data = json_tokener_parse(tempdata);
  8507. if(!is_error(data))
  8508. {
  8509. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8510. if(json_object_object_get(data, "Content_Type") != NULL)
  8511. {
  8512. 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))
  8513. {
  8514. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  8515. if(json_object_object_get(data, "Customization_Conent") != NULL)
  8516. {
  8517. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  8518. }
  8519. }
  8520. else
  8521. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8522. }
  8523. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  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_DsiplayLcdPage") != 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, "Page_Index") != NULL)
  8542. {
  8543. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  8544. }
  8545. if(json_object_object_get(data, "Duration") != NULL)
  8546. {
  8547. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  8548. }
  8549. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  8550. }
  8551. else
  8552. {
  8553. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8554. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8555. }
  8556. json_object_put(data);
  8557. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8558. json_object_put(response);
  8559. }
  8560. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  8561. {
  8562. json_object *data;
  8563. data = json_tokener_parse(tempdata);
  8564. if(!is_error(data))
  8565. {
  8566. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  8567. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  8568. {
  8569. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  8570. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  8571. else
  8572. {
  8573. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8574. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8575. }
  8576. }
  8577. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  8578. {
  8579. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  8580. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  8581. else
  8582. {
  8583. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8584. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8585. }
  8586. }
  8587. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  8588. {
  8589. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  8590. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  8591. else
  8592. {
  8593. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8594. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8595. }
  8596. }
  8597. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  8598. {
  8599. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  8600. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  8601. else
  8602. {
  8603. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8604. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8605. }
  8606. }
  8607. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  8608. {
  8609. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  8610. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  8611. else
  8612. {
  8613. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8614. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8615. }
  8616. }
  8617. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  8618. {
  8619. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  8620. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  8621. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  8622. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  8623. else
  8624. {
  8625. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8626. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8627. }
  8628. }
  8629. if(json_object_object_get(data, "isAuthentication") != NULL)
  8630. {
  8631. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  8632. {
  8633. case 0:
  8634. case 1:
  8635. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  8636. break;
  8637. default:
  8638. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8639. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8640. break;
  8641. }
  8642. }
  8643. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  8644. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  8645. }
  8646. else
  8647. {
  8648. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  8649. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  8650. }
  8651. json_object_put(data);
  8652. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  8653. json_object_put(response);
  8654. }
  8655. else
  8656. {
  8657. // Can not find valid message id
  8658. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  8659. }
  8660. }
  8661. else
  8662. {
  8663. // Payload is null
  8664. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  8665. }
  8666. LWS_Send(message);
  8667. return result;
  8668. }
  8669. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  8670. {
  8671. mtrace();
  8672. int result = FAIL;
  8673. int connectorIdInt, durationInt;
  8674. char chargingRateUnitStr[4]={0};
  8675. char comfirmstr[20];
  8676. int confirmPeriods = 0;
  8677. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  8678. json_object *GetCompositeSchedule;
  8679. GetCompositeSchedule = json_tokener_parse(payload);
  8680. if(!is_error(GetCompositeSchedule))
  8681. {
  8682. // Required data
  8683. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  8684. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  8685. else
  8686. connectorIdInt = -1;
  8687. if(json_object_object_get(GetCompositeSchedule, "duration"))
  8688. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  8689. else
  8690. durationInt = 86400;
  8691. // Optional data
  8692. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  8693. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  8694. }
  8695. json_object_put(GetCompositeSchedule);
  8696. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  8697. if((connectorIdInt == 0) ||
  8698. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  8699. {
  8700. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  8701. struct StructChargingProfile tmpProfile[1];
  8702. if(strstr(chargingRateUnitStr, "W") != NULL)
  8703. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  8704. else
  8705. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  8706. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8707. {
  8708. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8709. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8710. }
  8711. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  8712. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  8713. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  8714. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  8715. {
  8716. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  8717. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  8718. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  8719. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  8720. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  8721. {
  8722. confirmPeriods = idx;
  8723. break;
  8724. }
  8725. }
  8726. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  8727. {
  8728. confirmPeriods += 1;
  8729. }
  8730. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  8731. }
  8732. else
  8733. {
  8734. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  8735. }
  8736. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  8737. return result;
  8738. }
  8739. int handleGetConfigurationRequest(char *uuid, char *payload)
  8740. {
  8741. mtrace();
  8742. int result = FAIL;
  8743. int MaxKeySupported = 0;
  8744. int n_keys = 0;
  8745. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  8746. DEBUG_INFO("handleGetConfigurationRequest...\n");
  8747. json_object *GetConfiguration;
  8748. GetConfiguration = json_tokener_parse(payload);
  8749. if(!is_error(GetConfiguration))
  8750. {
  8751. // Optional data
  8752. if(json_object_object_get(GetConfiguration, "key") != NULL)
  8753. {
  8754. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  8755. {
  8756. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  8757. n_keys = idx + 1;
  8758. }
  8759. }
  8760. }
  8761. json_object_put(GetConfiguration);
  8762. UnknownKeynum = 0;
  8763. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  8764. MaxKeySupported = GetConfigurationMaxKeysNUM;
  8765. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  8766. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  8767. if(n_keys != 0)
  8768. {
  8769. for(int i=0;i<n_keys;i++)
  8770. {
  8771. getKeyValue(requestKey[i]);
  8772. }
  8773. }
  8774. else
  8775. {
  8776. DEBUG_INFO("There is no key in Message, get all configuration\n");
  8777. getKeyValue("");
  8778. }
  8779. processUnkownKey();
  8780. sendGetConfigurationConfirmation(uuid);
  8781. return result;
  8782. }
  8783. static char fnamePlusPath[100]={0};
  8784. static char fnamePWithNoPath[60]={0};
  8785. void checkUploadLog(void)
  8786. {
  8787. FILE *fp;
  8788. /* Open the command for reading. */
  8789. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  8790. if (fp == NULL) {
  8791. DEBUG_WARN("Failed to run command\n" );
  8792. exit(1);
  8793. }
  8794. int ftppathlen = 0;
  8795. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  8796. int i = 0;
  8797. /* Read the output a line at a time - output it. */
  8798. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  8799. if(i==0)
  8800. {
  8801. ftppathlen = strlen(fnamePlusPath);
  8802. DEBUG_INFO("%s\n", fnamePlusPath);
  8803. fnamePlusPath[ftppathlen]='\0';
  8804. break;
  8805. }
  8806. i= i+1;
  8807. }
  8808. /* close */
  8809. pclose(fp);
  8810. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  8811. {
  8812. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  8813. {
  8814. fnamePlusPath[k]='\0';
  8815. }
  8816. }
  8817. i=1;
  8818. //char fname[60]={0};
  8819. while(i < ftppathlen)
  8820. {
  8821. int len=ftppathlen-i;
  8822. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  8823. {
  8824. DEBUG_INFO("compare '/' all right\n");
  8825. break;
  8826. }
  8827. i=i+1;
  8828. }
  8829. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  8830. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  8831. fnamePWithNoPath[i+1] = '\0';
  8832. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  8833. {
  8834. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  8835. {
  8836. fnamePWithNoPath[j]='\0';
  8837. }
  8838. }
  8839. FILE* fp1 = fopen(fnamePlusPath, "r");
  8840. if (fp1)
  8841. {
  8842. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  8843. // file exists
  8844. fclose(fp1);
  8845. }
  8846. else
  8847. {
  8848. // file doesn't exist
  8849. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  8850. }
  8851. }
  8852. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  8853. {
  8854. mtrace();
  8855. int result = FAIL;
  8856. time_t CurrentTime;
  8857. struct tm *tm;
  8858. pthread_t th_Status;
  8859. CurrentTime = time(NULL);
  8860. tm = localtime(&CurrentTime);
  8861. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  8862. 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);
  8863. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8864. if(!interLock.isGetDiagnosticGoing)
  8865. {
  8866. interLock.isGetDiagnosticGoing = 1;
  8867. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  8868. sleep(1);
  8869. }
  8870. else
  8871. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  8872. return result;
  8873. }
  8874. void* GetDiagnosticsProcess(void* data)
  8875. {
  8876. pthread_detach(pthread_self());
  8877. mtrace();
  8878. int retriesInt=0, retryIntervalInt=0;
  8879. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  8880. 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};
  8881. int port=0;
  8882. int isSuccess = FALSE;
  8883. char ftpbuf[200]={0};
  8884. char cmdBuf[2048];
  8885. struct tm *tmNow;
  8886. time_t CurrentTime;
  8887. struct tm tmStart;
  8888. struct tm tmStop;
  8889. CurrentTime = time(NULL);
  8890. tmNow=localtime(&CurrentTime);
  8891. uint16_t targetYear, targetMonth;
  8892. json_object *GetDiagnostics;
  8893. DEBUG_INFO("GetDiagnosticsProcess...\n");
  8894. GetDiagnostics = json_tokener_parse(data);
  8895. if(!is_error(GetDiagnostics))
  8896. {
  8897. // Required data
  8898. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  8899. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  8900. // Optional data
  8901. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  8902. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  8903. else
  8904. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  8905. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  8906. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  8907. else
  8908. retryIntervalInt = 30;
  8909. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  8910. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  8911. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  8912. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  8913. }
  8914. json_object_put(GetDiagnostics);
  8915. // Pack log to compress file
  8916. 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) &&
  8917. (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))
  8918. {
  8919. // Pack system log
  8920. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8921. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8922. targetYear = tmStart.tm_year;
  8923. targetMonth = tmStart.tm_mon;
  8924. do
  8925. {
  8926. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8927. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8928. if(targetMonth+1>=13)
  8929. {
  8930. targetYear += 1;
  8931. targetMonth = 1;
  8932. }
  8933. else
  8934. {
  8935. targetMonth += 1;
  8936. }
  8937. }while((targetYear < (tmNow->tm_year+1900)) ||
  8938. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8939. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8940. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8941. system(cmdBuf);
  8942. // Pack charging & event log
  8943. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8944. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8945. targetYear = tmStart.tm_year;
  8946. targetMonth = tmStart.tm_mon;
  8947. do
  8948. {
  8949. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8950. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8951. if(targetMonth+1>=13)
  8952. {
  8953. targetYear += 1;
  8954. targetMonth = 1;
  8955. }
  8956. else
  8957. {
  8958. targetMonth += 1;
  8959. }
  8960. }while((targetYear < (tmNow->tm_year+1900)) ||
  8961. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8962. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8963. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8964. system(cmdBuf);
  8965. // Combine log file
  8966. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8967. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8968. }
  8969. else
  8970. {
  8971. system("exec /root/logPackTools 'log' 6");
  8972. }
  8973. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8974. system(cmdBuf);
  8975. checkUploadLog();
  8976. //****************location*******************/
  8977. if(strcmp(locationstr,"")==0)
  8978. {
  8979. DEBUG_INFO("location is <Empty>!\n");
  8980. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8981. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8982. goto end;
  8983. }
  8984. memset(protocol, 0, ARRAY_SIZE(protocol));
  8985. memset(user, 0, ARRAY_SIZE(user) );
  8986. memset(password, 0, ARRAY_SIZE(password));
  8987. memset(host, 0, ARRAY_SIZE(host));
  8988. memset(path, 0, ARRAY_SIZE(path));
  8989. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8990. memset(host1, 0, ARRAY_SIZE(host1));
  8991. memset(path1, 0, ARRAY_SIZE(path1));
  8992. /*location: ftp://user:password@host:port/path*/
  8993. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8994. if((access(fnamePlusPath,F_OK))!=-1)
  8995. {
  8996. DEBUG_INFO("fnamePlusPath exist.\n");
  8997. }
  8998. else
  8999. {
  9000. DEBUG_INFO("fnamePlusPath not exist!\n");
  9001. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9002. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9003. goto end;
  9004. }
  9005. if(strchr(locationstr,'@')==NULL)
  9006. {
  9007. sscanf(locationstr,
  9008. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9009. protocol, host, &port, path);
  9010. strcpy(user,"anonymous");
  9011. strcpy(password,"");
  9012. }
  9013. else
  9014. {
  9015. //DEBUG_INFO("pch=%s\n", pch);
  9016. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9017. protocol, user, password, host, &port, path);
  9018. }
  9019. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  9020. {
  9021. DEBUG_INFO("protocol is not ftp/http ! \n");
  9022. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9023. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9024. goto end;
  9025. }
  9026. if(strncmp(locationstr,"http", 4) == 0)
  9027. {
  9028. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9029. sprintf(ftppath,"/%s", path);
  9030. do
  9031. {
  9032. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9033. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9034. sleep(3);
  9035. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  9036. if(!isSuccess)
  9037. {
  9038. DEBUG_INFO("Diagnostics fail.\n");
  9039. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9040. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9041. sleep(retryIntervalInt);
  9042. }
  9043. else
  9044. {
  9045. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9046. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9047. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9048. }
  9049. retriesInt--;
  9050. }while((isSuccess == 0)&&(retriesInt >= 0));
  9051. }
  9052. else
  9053. {
  9054. sscanf(host,"%[^/]%s",host1, path1);
  9055. if(strlen(path) > 0)
  9056. sprintf(ftppath,"/%s", path);
  9057. else
  9058. sprintf(ftppath,"/%s", path1);
  9059. int ftppathlen=strlen(ftppath);
  9060. int i=1;
  9061. char filenametemp[50];
  9062. while(i < ftppathlen)
  9063. {
  9064. int len=ftppathlen-i;
  9065. if(ftppath[len]== 47) // '/' ascll code: 47
  9066. {
  9067. DEBUG_INFO("find '/' all right\n");
  9068. break;
  9069. }
  9070. i=i+1;
  9071. }
  9072. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9073. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9074. filenametemp[i+1] = 0;
  9075. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9076. if(port == 0)
  9077. port = 21;
  9078. do
  9079. {
  9080. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  9081. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9082. sleep(3);
  9083. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  9084. if(!isSuccess)
  9085. {
  9086. DEBUG_INFO("Diagnostics fail.\n");
  9087. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  9088. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9089. sleep(retryIntervalInt);
  9090. }
  9091. else
  9092. {
  9093. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  9094. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  9095. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9096. }
  9097. retriesInt--;
  9098. }while((!isSuccess)&&(retriesInt >= 0));
  9099. }
  9100. end:
  9101. system("rm -f /mnt/*");
  9102. sleep(5);
  9103. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9104. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  9105. interLock.isGetDiagnosticGoing = 0;
  9106. pthread_exit(NULL);
  9107. }
  9108. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  9109. {
  9110. mtrace();
  9111. int result = FAIL;
  9112. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  9113. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  9114. {
  9115. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  9116. locallistVersion = -1;
  9117. }
  9118. else
  9119. {
  9120. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  9121. OCPP_getListVerion();
  9122. }
  9123. //from db.OCPP_getListVerion
  9124. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  9125. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  9126. sendGetLocalListVersionConfirmation(uuid,"");
  9127. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  9128. return result;
  9129. }
  9130. int handleRemoteStartRequest(char *uuid, char *payload)
  9131. {
  9132. mtrace();
  9133. int result = FAIL;
  9134. int connectorIdInt=-1;
  9135. int tempIndex = 0;
  9136. int connectorIdIsNULL, chargingProfileIsNULL;
  9137. char comfirmstr[20]={0};
  9138. char cmdBuf[512];
  9139. json_object *RemoteStartTransaction;
  9140. FILE *fp;
  9141. DEBUG_INFO("handleRemoteStartRequest ...\n");
  9142. if(server_pending == TRUE)
  9143. {
  9144. return 0;
  9145. }
  9146. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  9147. RemoteStartTransaction = json_tokener_parse(payload);
  9148. if(!is_error(RemoteStartTransaction))
  9149. {
  9150. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  9151. {
  9152. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  9153. }
  9154. else
  9155. {
  9156. connectorIdIsNULL = TRUE;
  9157. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  9158. {
  9159. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP16DataPH->StatusNotification[gun_index].Status, "Preparing") != NULL))
  9160. {
  9161. connectorIdIsNULL = FALSE;
  9162. connectorIdInt = (gun_index+1);
  9163. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdInt);
  9164. break;
  9165. }
  9166. }
  9167. }
  9168. if((connectorIdInt <= gunTotalNumber) && (connectorIdInt > 0))
  9169. {
  9170. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  9171. // Required data
  9172. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  9173. // Optional data
  9174. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  9175. {
  9176. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  9177. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  9178. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  9179. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  9180. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  9181. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  9182. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  9183. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  9184. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  9185. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  9186. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  9187. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  9188. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  9189. {
  9190. 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")));
  9191. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  9192. 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"));
  9193. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  9194. 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"));
  9195. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  9196. 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")));
  9197. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9198. {
  9199. 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++)
  9200. {
  9201. 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"));
  9202. 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"));
  9203. 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)
  9204. 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"));
  9205. }
  9206. }
  9207. }
  9208. }
  9209. else
  9210. {
  9211. chargingProfileIsNULL = TRUE;
  9212. }
  9213. }
  9214. }
  9215. else
  9216. {
  9217. connectorIdIsNULL = TRUE;
  9218. }
  9219. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  9220. {
  9221. DEBUG_WARN("Connector id is NULL\n.");
  9222. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9223. goto end;
  9224. }
  9225. /*
  9226. enum _SYSTEM_STATUS
  9227. {
  9228. S_BOOTING = 0,
  9229. S_IDLE, = 1
  9230. S_AUTHORIZING, = 2
  9231. S_REASSIGN_CHECK, = 3
  9232. S_REASSIGN, = 4
  9233. S_PRECHARGE, = 5
  9234. S_PREPARING_FOR_EV, = 6
  9235. S_PREPARING_FOR_EVSE, = 7
  9236. S_CHARGING, = 8
  9237. S_TERMINATING, = 9
  9238. S_COMPLETE, = 10
  9239. S_ALARM, = 11
  9240. S_FAULT = 12
  9241. }
  9242. */
  9243. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  9244. {
  9245. //check Transaction active
  9246. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9247. {
  9248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9249. {
  9250. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9251. }
  9252. else
  9253. {
  9254. tempIndex = connectorIdInt -1;
  9255. }
  9256. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9257. {
  9258. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  9259. {
  9260. 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))
  9261. {
  9262. //Reserved
  9263. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9264. }
  9265. 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))
  9266. {
  9267. //Reserved
  9268. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9269. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9270. goto end;
  9271. }
  9272. else
  9273. {
  9274. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9275. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  9276. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  9277. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  9278. {
  9279. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  9280. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9281. goto end;
  9282. }
  9283. }//END FOR ELSE
  9284. }
  9285. }// END FOR CHAdeMO_QUANTITY
  9286. }
  9287. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9288. {
  9289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9290. {
  9291. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9292. }
  9293. else
  9294. {
  9295. tempIndex = connectorIdInt -1;
  9296. }
  9297. for (int index = 0; index < CCS_QUANTITY; index++)
  9298. {
  9299. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9300. {
  9301. 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))
  9302. {
  9303. //Reserved
  9304. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9305. }
  9306. 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))
  9307. {
  9308. //Reserved
  9309. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9310. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9311. goto end;
  9312. }
  9313. else
  9314. {
  9315. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9316. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9317. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9318. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9319. {
  9320. DEBUG_WARN("CCS connector not allow start\n.");
  9321. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9322. goto end;
  9323. }
  9324. }// END FOR ELSE
  9325. }
  9326. }// END FOR CCS_QUANTITY
  9327. }
  9328. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9329. {
  9330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9331. {
  9332. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  9333. }
  9334. else
  9335. {
  9336. tempIndex = connectorIdInt -1;
  9337. }
  9338. for (int index = 0; index < GB_QUANTITY; index++)
  9339. {
  9340. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  9341. {
  9342. 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))
  9343. {
  9344. //Reserved
  9345. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9346. }
  9347. 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))
  9348. {
  9349. //Reserved
  9350. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9351. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9352. goto end;
  9353. }
  9354. else
  9355. {
  9356. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9357. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9358. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9359. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9360. {
  9361. DEBUG_WARN("GB connector not allow start\n.");
  9362. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9363. goto end;
  9364. }
  9365. }// END FOR ELSE
  9366. }
  9367. } // END FOR GB_QUANTITY
  9368. }
  9369. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9370. {
  9371. tempIndex = connectorIdInt -1;
  9372. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9373. {
  9374. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  9375. {
  9376. 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))
  9377. {
  9378. //Reserved
  9379. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9380. }
  9381. 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))
  9382. {
  9383. //Reserved
  9384. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9385. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9386. goto end;
  9387. }
  9388. else
  9389. {
  9390. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9391. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9392. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9393. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9394. {
  9395. DEBUG_WARN("GB connector not allow start\n.");
  9396. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9397. goto end;
  9398. }
  9399. }// END FOR ELSE
  9400. }
  9401. } // END FOR GB_QUANTITY
  9402. }
  9403. else
  9404. {
  9405. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9406. {
  9407. tempIndex = 2;
  9408. }
  9409. else
  9410. {
  9411. tempIndex = connectorIdInt -1;
  9412. }
  9413. for (int index = 0; index < AC_QUANTITY; index++)
  9414. {
  9415. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  9416. {
  9417. 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))
  9418. {
  9419. //Reserved
  9420. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  9421. }
  9422. 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))
  9423. {
  9424. //Reserved
  9425. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  9426. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9427. goto end;
  9428. }
  9429. else
  9430. {
  9431. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9432. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  9433. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  9434. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  9435. {
  9436. DEBUG_WARN("AC connector not allow start\n.");
  9437. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9438. goto end;
  9439. }
  9440. }//END FOR ELSE
  9441. }
  9442. }// END FOR AC_QUANTITY
  9443. }
  9444. if(chargingProfileIsNULL == FALSE)
  9445. {
  9446. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9447. {
  9448. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9449. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9450. //memset idTag
  9451. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9452. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9453. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9455. // Save profile to file
  9456. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9457. system(cmdBuf);
  9458. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9459. fp = fopen(cmdBuf, "w");
  9460. 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));
  9461. fclose(fp);
  9462. }
  9463. else
  9464. {
  9465. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  9466. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9467. }
  9468. }
  9469. else
  9470. {
  9471. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  9472. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9473. //memset idTag
  9474. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  9475. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9476. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  9477. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  9478. }
  9479. }
  9480. else
  9481. {
  9482. DEBUG_WARN("Connector id over\n.");
  9483. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9484. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9485. }
  9486. end:
  9487. json_object_put(RemoteStartTransaction);
  9488. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  9489. {
  9490. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  9491. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  9492. }
  9493. //OCPP send RemoteStartConfirmation by first.
  9494. sendRemoteStartConfirmation(uuid, comfirmstr);
  9495. return result;
  9496. }
  9497. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  9498. {
  9499. mtrace();
  9500. int result = FAIL;
  9501. int match = FALSE;
  9502. int GunNO = 0;
  9503. int tempIndex = 0;
  9504. int transactionIdInt=0;
  9505. int transactionIdIsNULL= TRUE;
  9506. char comfirmstr[20];
  9507. json_object *RemoteStopTransaction;
  9508. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  9509. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  9510. if(server_pending == TRUE)
  9511. {
  9512. return 0;
  9513. }
  9514. RemoteStopTransaction = json_tokener_parse(payload);
  9515. if(!is_error(RemoteStopTransaction))
  9516. {
  9517. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  9518. {
  9519. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  9520. transactionIdIsNULL = FALSE;
  9521. }
  9522. }
  9523. json_object_put(RemoteStopTransaction);
  9524. if(transactionIdIsNULL == FALSE)
  9525. {
  9526. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  9527. {
  9528. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  9529. {
  9530. //check Transaction active
  9531. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9532. {
  9533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9534. {
  9535. tempIndex = ((gun_index==2) ? 1: 0);
  9536. }
  9537. else
  9538. {
  9539. tempIndex = gun_index;
  9540. }
  9541. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9542. {
  9543. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9544. {
  9545. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9546. {
  9547. match = TRUE;
  9548. GunNO = gun_index;
  9549. }
  9550. }
  9551. }// END FOR CHAdeMO_QUANTITY
  9552. }
  9553. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9554. {
  9555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9556. {
  9557. tempIndex = ((gun_index==2) ? 1: 0);
  9558. }
  9559. else
  9560. {
  9561. tempIndex = gun_index;
  9562. }
  9563. for (int index = 0; index < CCS_QUANTITY; index++)
  9564. {
  9565. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9566. {
  9567. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9568. {
  9569. match = TRUE;
  9570. GunNO = gun_index;
  9571. }
  9572. }
  9573. }// END FOR CCS_QUANTITY
  9574. }
  9575. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9576. {
  9577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9578. {
  9579. tempIndex = ((gun_index==2) ? 1: 0);
  9580. }
  9581. else
  9582. {
  9583. tempIndex = gun_index;
  9584. }
  9585. for (int index = 0; index < GB_QUANTITY; index++)
  9586. {
  9587. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9588. {
  9589. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9590. {
  9591. match = TRUE;
  9592. GunNO = gun_index;
  9593. }
  9594. }
  9595. }// END FOR GB_QUANTITY
  9596. }
  9597. else if(gunType[gun_index] == GUN_TYPE_DO)
  9598. {
  9599. tempIndex = gun_index;
  9600. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9601. {
  9602. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9603. {
  9604. 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
  9605. {
  9606. match = TRUE;
  9607. GunNO = gun_index;
  9608. }
  9609. }
  9610. }// END FOR GB_QUANTITY
  9611. }
  9612. else
  9613. {
  9614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9615. {
  9616. tempIndex = 2;
  9617. }
  9618. else
  9619. {
  9620. tempIndex = gun_index;
  9621. }
  9622. for (int index = 0; index < AC_QUANTITY; index++)
  9623. {
  9624. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9625. {
  9626. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  9627. {
  9628. match = TRUE;
  9629. GunNO = gun_index;
  9630. }
  9631. }
  9632. }// END FOR CHAdeMO_QUANTITY
  9633. } // END FOR AC ELSE
  9634. }// CHECK IF ResponseTransactionId == transactionIdInt
  9635. }//END FOR
  9636. if( match == TRUE)
  9637. {
  9638. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  9639. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  9640. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  9641. }
  9642. else
  9643. {
  9644. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9645. }
  9646. }
  9647. else
  9648. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  9649. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  9650. return result;
  9651. }
  9652. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  9653. {
  9654. mtrace();
  9655. int result = FAIL;
  9656. int connectorIdInt=0, reservationIdInt=0;
  9657. int tempIndex = 0;
  9658. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  9659. char comfirmstr[20]={0};
  9660. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  9661. int c = 0;
  9662. char *loc;
  9663. //char *ptr;
  9664. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  9665. strcpy(sstrtemp, stringtrimspace(payload));
  9666. //***(1)connectorId ****/
  9667. c=0;
  9668. loc = strstr(sstrtemp, "connectorId");
  9669. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9670. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  9671. {
  9672. sstr[c] = loc[strlen("connectorId")+2+c];
  9673. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9674. c++;
  9675. }
  9676. sstr[c] = '\0';
  9677. connectorIdInt = atoi(sstr);
  9678. //***(2)expiryDate ****/
  9679. loc = strstr(sstrtemp, "expiryDate");
  9680. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9681. c = 0;
  9682. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  9683. {
  9684. sstr[c] = loc[3+strlen("expiryDate")+c];
  9685. c++;
  9686. }
  9687. sstr[c] = '\0';
  9688. strcpy(expiryDatestr, sstr);
  9689. //***(3)idTag ****/
  9690. loc = strstr(sstrtemp, "idTag");
  9691. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9692. c = 0;
  9693. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  9694. {
  9695. sstr[c] = loc[3+strlen("idTag")+c];
  9696. c++;
  9697. }
  9698. sstr[c] = '\0';
  9699. strcpy(idTagstr, sstr);
  9700. //***(4)parentIdTag ****/
  9701. loc = strstr(sstrtemp, "parentIdTag");
  9702. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9703. c = 0;
  9704. if(loc == NULL)
  9705. {
  9706. strcpy(parentIdTagstr, "");
  9707. }
  9708. else
  9709. {
  9710. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9711. {
  9712. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9713. c++;
  9714. }
  9715. sstr[c] = '\0';
  9716. strcpy(parentIdTagstr, sstr);
  9717. }
  9718. //***(5)reservationId ****/
  9719. c=0;
  9720. loc = strstr(sstrtemp, "reservationId");
  9721. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9722. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  9723. {
  9724. sstr[c] = loc[strlen("reservationId")+2+c];
  9725. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9726. c++;
  9727. }
  9728. sstr[c] = '\0';
  9729. reservationIdInt = atoi(sstr);
  9730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9731. /*
  9732. enum SYSTEM_STATUS
  9733. {
  9734. SYS_MODE_BOOTING = 0,
  9735. SYS_MODE_IDLE = 1,
  9736. SYS_MODE_AUTHORIZING = 2,
  9737. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  9738. SYS_MODE_REASSIGN = 4,
  9739. SYS_MODE_PREPARING = 5,
  9740. SYS_MODE_PREPARE_FOR_EV = 6,
  9741. SYS_MODE_PREPARE_FOR_EVSE = 7,
  9742. SYS_MODE_CHARGING = 8,
  9743. SYS_MODE_TERMINATING = 9,
  9744. SYS_MODE_COMPLETE = 10,
  9745. SYS_MODE_ALARM = 11,
  9746. SYS_MODE_FAULT = 12,
  9747. SYS_MODE_RESERVATION = 13,
  9748. SYS_MODE_BOOKING = 14,
  9749. SYS_MODE_MAINTAIN = 15,
  9750. SYS_MODE_DEBUG = 16,
  9751. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  9752. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  9753. SYS_MODE_UPDATE = 19
  9754. };
  9755. */
  9756. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  9757. {
  9758. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9759. goto end;
  9760. }
  9761. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  9762. {
  9763. //check Transaction active
  9764. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9765. {
  9766. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9767. {
  9768. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9769. }
  9770. else
  9771. {
  9772. tempIndex = connectorIdInt -1;
  9773. }
  9774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9775. {
  9776. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9777. {
  9778. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9779. {
  9780. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9781. {
  9782. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9783. {
  9784. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9786. }
  9787. 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'))
  9788. {
  9789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9790. }
  9791. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9792. {
  9793. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9794. }
  9795. else
  9796. {
  9797. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9798. }
  9799. }
  9800. 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
  9801. {
  9802. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9803. }
  9804. }
  9805. else
  9806. {
  9807. //replace reservation
  9808. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9810. }
  9811. }
  9812. } // END FOR CHAdeMO_QUANTITY
  9813. }
  9814. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9815. {
  9816. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9817. {
  9818. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9819. }
  9820. else
  9821. {
  9822. tempIndex = connectorIdInt -1;
  9823. }
  9824. for (int index = 0; index < CCS_QUANTITY; index++)
  9825. {
  9826. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9827. {
  9828. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9829. {
  9830. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9831. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  9832. {
  9833. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9834. {
  9835. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9836. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9837. }
  9838. 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'))
  9839. {
  9840. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9841. }
  9842. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  9843. {
  9844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9845. }
  9846. else
  9847. {
  9848. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9849. }
  9850. }
  9851. 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
  9852. {
  9853. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9854. }
  9855. }
  9856. else
  9857. {
  9858. //replace reservation
  9859. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9861. }
  9862. }
  9863. } // END FOR CCS_QUANTITY
  9864. }
  9865. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9866. {
  9867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9868. {
  9869. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9870. }
  9871. else
  9872. {
  9873. tempIndex = connectorIdInt -1;
  9874. }
  9875. for (int index = 0; index < GB_QUANTITY; index++)
  9876. {
  9877. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9878. {
  9879. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9880. {
  9881. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9882. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9883. {
  9884. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9885. {
  9886. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9887. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9888. }
  9889. 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'))
  9890. {
  9891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9892. }
  9893. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9894. {
  9895. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9896. }
  9897. else
  9898. {
  9899. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9900. }
  9901. }
  9902. 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
  9903. {
  9904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9905. }
  9906. }
  9907. else
  9908. {
  9909. //replace reservation
  9910. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9912. }
  9913. }
  9914. }// END FOR GB_QUANTITY
  9915. }
  9916. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9917. {
  9918. tempIndex = connectorIdInt -1;
  9919. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9920. {
  9921. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9922. {
  9923. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  9924. {
  9925. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9926. 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
  9927. {
  9928. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9929. {
  9930. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9932. }
  9933. 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'))
  9934. {
  9935. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9936. }
  9937. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9938. {
  9939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9940. }
  9941. else
  9942. {
  9943. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9944. }
  9945. }
  9946. 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
  9947. {
  9948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9949. }
  9950. }
  9951. else
  9952. {
  9953. //replace reservation
  9954. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9956. }
  9957. }
  9958. }// END FOR GB_QUANTITY
  9959. }
  9960. else
  9961. {
  9962. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9963. {
  9964. tempIndex = 2;
  9965. }
  9966. else
  9967. {
  9968. tempIndex = (connectorIdInt -1);
  9969. }
  9970. for (int index = 0; index < AC_QUANTITY; index++)
  9971. {
  9972. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9973. {
  9974. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9975. {
  9976. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9977. {
  9978. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9979. {
  9980. 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))
  9981. {
  9982. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9983. }
  9984. else
  9985. {
  9986. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9987. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9988. }
  9989. }
  9990. 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'))
  9991. {
  9992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9993. }
  9994. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9995. {
  9996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9997. }
  9998. else
  9999. {
  10000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10001. }
  10002. }
  10003. 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
  10004. {
  10005. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10006. }
  10007. }
  10008. else
  10009. {
  10010. //replace reservation
  10011. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  10012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10013. }
  10014. }
  10015. } // END FOR AC_QUANTITY
  10016. }
  10017. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10018. }
  10019. else if(connectorIdInt == 0)
  10020. {
  10021. //check Transaction active
  10022. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10023. {
  10024. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  10025. {
  10026. 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'))
  10027. {
  10028. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10029. goto end;
  10030. }
  10031. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10032. {
  10033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10034. goto end;
  10035. }
  10036. 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
  10037. {
  10038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10039. goto end;
  10040. }
  10041. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10042. {
  10043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10044. goto end;
  10045. }
  10046. }
  10047. }// END FOR CHAdeMO_QUANTITY
  10048. for (int index = 0; index < CCS_QUANTITY; index++)
  10049. {
  10050. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  10051. {
  10052. 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'))
  10053. {
  10054. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10055. goto end;
  10056. }
  10057. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  10058. {
  10059. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10060. goto end;
  10061. }
  10062. 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
  10063. {
  10064. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10065. goto end;
  10066. }
  10067. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10068. {
  10069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10070. goto end;
  10071. }
  10072. }
  10073. } // END FOR CCS_QUANTITY
  10074. for (int index = 0; index < GB_QUANTITY; index++)
  10075. {
  10076. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  10077. {
  10078. 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'))
  10079. {
  10080. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10081. goto end;
  10082. }
  10083. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10084. {
  10085. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10086. goto end;
  10087. }
  10088. 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
  10089. {
  10090. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10091. goto end;
  10092. }
  10093. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10094. {
  10095. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10096. goto end;
  10097. }
  10098. }
  10099. } // END FOR GB_QUANTITY
  10100. for (int index = 0; index < AC_QUANTITY; index++)
  10101. {
  10102. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  10103. {
  10104. 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'))
  10105. {
  10106. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  10107. goto end;
  10108. }
  10109. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  10110. {
  10111. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10112. goto end;
  10113. }
  10114. 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
  10115. {
  10116. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  10117. goto end;
  10118. }
  10119. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10120. {
  10121. 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))
  10122. {
  10123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  10124. goto end;
  10125. }
  10126. }
  10127. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  10128. {
  10129. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10130. goto end;
  10131. }
  10132. }
  10133. }// END FOR AC_QUANTITY
  10134. //The connectorId is 0
  10135. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  10136. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  10137. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  10138. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  10139. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  10140. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  10141. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  10142. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  10143. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  10144. result = TRUE;
  10145. return result;
  10146. }
  10147. else
  10148. {
  10149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  10150. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  10151. }
  10152. if(strcmp(comfirmstr,"Accepted") == 0)
  10153. {
  10154. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  10155. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  10156. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  10157. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  10158. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  10159. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  10160. result = TRUE;
  10161. return result;
  10162. }
  10163. end:
  10164. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  10165. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  10166. return result;
  10167. }
  10168. int handleResetRequest(char *uuid, char *payload)
  10169. {
  10170. mtrace();
  10171. int result = FAIL;
  10172. char sstr[10]={0},sstrtemp[30]={ 0 };
  10173. char typestr[10]={0};
  10174. char comfirmstr[20]={0};
  10175. int c = 0;
  10176. char *loc;
  10177. DEBUG_INFO("handleResetRequest...\n");
  10178. strcpy(sstrtemp, stringtrimspace(payload));
  10179. loc = strstr(sstrtemp, "type");
  10180. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10181. c = 0;
  10182. while (loc[3+strlen("type")+c] != '\"')
  10183. {
  10184. sstr[c] = loc[3+strlen("type")+c];
  10185. c++;
  10186. }
  10187. sstr[c] = '\0';
  10188. strcpy(typestr,sstr);
  10189. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  10190. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  10191. {
  10192. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  10193. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  10194. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  10195. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10196. }
  10197. else
  10198. {
  10199. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  10200. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  10201. result = PASS;
  10202. }
  10203. sendResetConfirmation(uuid, comfirmstr);
  10204. return result;
  10205. }
  10206. int handleSendLocalListRequest(char *uuid, char *payload)
  10207. {
  10208. mtrace();
  10209. int result = FAIL;
  10210. char comfirmstr[20];
  10211. int checkState_Faulted = FALSE;
  10212. json_object *SendLocalList;
  10213. DEBUG_INFO("handleSendLocalListRequest...\n");
  10214. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  10215. {
  10216. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10217. goto end;
  10218. }
  10219. //check Charge Point state
  10220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10221. {
  10222. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10223. {
  10224. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10225. }
  10226. }
  10227. for (int index = 0; index < CCS_QUANTITY; index++)
  10228. {
  10229. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10230. {
  10231. checkState_Faulted = TRUE; //OCPP Status
  10232. }
  10233. }
  10234. for (int index = 0; index < GB_QUANTITY; index++)
  10235. {
  10236. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10237. {
  10238. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10239. }
  10240. }
  10241. //check Charge Point state
  10242. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10243. {
  10244. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10245. {
  10246. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10247. }
  10248. }
  10249. //check Charge Point state
  10250. for (int index = 0; index < AC_QUANTITY; index++)
  10251. {
  10252. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  10253. {
  10254. checkState_Faulted = TRUE; //OCPP Status: Faulted
  10255. }
  10256. }
  10257. if(checkState_Faulted == TRUE)
  10258. {
  10259. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10260. goto end;
  10261. }
  10262. // Parsing payload
  10263. SendLocalList = json_tokener_parse(payload);
  10264. if(!is_error(SendLocalList))
  10265. {
  10266. // Required data
  10267. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  10268. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  10269. // Optional data
  10270. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  10271. {
  10272. //Check UpdateType
  10273. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10274. {
  10275. //Local list full update
  10276. DEBUG_INFO("Local list full update.\n");
  10277. OCPP_getListVerion();
  10278. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10279. {
  10280. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  10281. goto end;
  10282. }
  10283. OCPP_cleanLocalList();
  10284. }
  10285. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10286. {
  10287. //Local list different update
  10288. DEBUG_INFO("Local list different update.\n");
  10289. OCPP_getListVerion();
  10290. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  10291. {
  10292. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  10293. goto end;
  10294. }
  10295. }
  10296. else
  10297. {
  10298. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  10299. goto end;
  10300. }
  10301. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)*1);
  10302. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  10303. {
  10304. 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")));
  10305. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  10306. {
  10307. 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")));
  10308. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  10309. 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")));
  10310. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  10311. 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")));
  10312. }
  10313. // Add to db
  10314. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10315. {
  10316. //Local list full update
  10317. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  10318. idx,
  10319. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10320. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10321. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10322. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10323. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10324. // update list
  10325. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10326. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10327. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10328. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10329. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10330. }
  10331. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10332. {
  10333. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  10334. idx,
  10335. ShmOCPP16DataPH->SendLocalList.ListVersion,
  10336. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10337. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10338. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10339. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10340. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  10341. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTag,
  10342. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ParentIdTag,
  10343. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.ExpiryDate,
  10344. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[0].IdTagInfo.Status);
  10345. }
  10346. }
  10347. }
  10348. else
  10349. {
  10350. //Check UpdateType
  10351. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  10352. {
  10353. //Local list full update
  10354. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  10355. OCPP_cleanLocalList();
  10356. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10357. goto end;
  10358. }
  10359. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  10360. {
  10361. //Local list different update
  10362. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  10363. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10364. goto end;
  10365. }
  10366. }
  10367. result = PASS;
  10368. }
  10369. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  10370. end:
  10371. json_object_put(SendLocalList);
  10372. sendSendLocalListConfirmation(uuid, comfirmstr);
  10373. return result;
  10374. }
  10375. int handleSetChargingProfileRequest(char *uuid, char *payload)
  10376. {
  10377. mtrace();
  10378. int result = FAIL;
  10379. struct StructSetChargingProfile SetProfileReq = {0};
  10380. int tempchargingProfileIdInt;
  10381. int chargingSchedulePeriodCount = 0;
  10382. char comfirmstr[20]={0};
  10383. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  10384. char rmFileCmd[128]={0};
  10385. int profileQuantity = 0;
  10386. json_object *SetChargingProfile;
  10387. DEBUG_INFO("handleSetChargingProfileRequest\n");
  10388. SetChargingProfile = json_tokener_parse(payload);
  10389. if(!is_error(SetChargingProfile))
  10390. {
  10391. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  10392. {
  10393. SetProfileReq.ConnectorId = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  10394. }
  10395. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  10396. {
  10397. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10398. {
  10399. SetProfileReq.ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10400. }
  10401. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10402. {
  10403. SetProfileReq.ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  10404. }
  10405. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10406. {
  10407. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10408. }
  10409. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  10410. {
  10411. strcpy((char*)SetProfileReq.ChargingProfile.ChargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  10412. }
  10413. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  10414. {
  10415. SetProfileReq.ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  10416. }
  10417. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  10418. {
  10419. strcpy((char*)SetProfileReq.ChargingProfile.RecurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  10420. }
  10421. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  10422. {
  10423. strcpy((char*)SetProfileReq.ChargingProfile.ValidFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  10424. }
  10425. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  10426. {
  10427. strcpy((char*)SetProfileReq.ChargingProfile.ValidTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  10428. }
  10429. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  10430. {
  10431. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  10432. {
  10433. 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")));
  10434. }
  10435. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  10436. {
  10437. SetProfileReq.ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  10438. }
  10439. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  10440. {
  10441. SetProfileReq.ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  10442. }
  10443. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  10444. {
  10445. 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")));
  10446. }
  10447. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  10448. {
  10449. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  10450. if(chargingSchedulePeriodCount <= 10)
  10451. {
  10452. 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++)
  10453. {
  10454. 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)
  10455. {
  10456. 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"));
  10457. }
  10458. 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)
  10459. {
  10460. 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"));
  10461. }
  10462. 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)
  10463. {
  10464. 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"));
  10465. }
  10466. }
  10467. }
  10468. }
  10469. }
  10470. }
  10471. }
  10472. // Profile periods quantity check
  10473. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  10474. {
  10475. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10476. goto end;
  10477. }
  10478. // Profile purpose info check
  10479. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10480. {
  10481. FILE *fp;
  10482. char dataLine[4096]={0};
  10483. DEBUG_INFO("Profile purpose is ChargePointMaxProfile.\n");
  10484. if(SetProfileReq.ConnectorId != 0)
  10485. {
  10486. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10487. goto end;
  10488. }
  10489. fp = fopen(ChargePointMaxProfile_JSON, "r");
  10490. if (!fp)
  10491. {
  10492. DEBUG_INFO("%s does not create.\n", ChargePointMaxProfile_JSON);
  10493. fp = fopen(ChargePointMaxProfile_JSON, "w+");
  10494. }
  10495. else
  10496. {
  10497. while(fscanf(fp, "%s", dataLine) != EOF)
  10498. {
  10499. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10500. {
  10501. profileQuantity += 1;
  10502. }
  10503. }
  10504. }
  10505. fclose(fp);
  10506. }
  10507. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10508. {
  10509. FILE *fp;
  10510. char dataLine[4096]={0};
  10511. char filename[128]={0};
  10512. int tmpProfileQuantity;
  10513. DEBUG_INFO("Profile purpose is TxDefaultProfile.\n");
  10514. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10515. {
  10516. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10517. goto end;
  10518. }
  10519. if(SetProfileReq.ConnectorId == 0)
  10520. {
  10521. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  10522. {
  10523. tmpProfileQuantity = 0;
  10524. memset(filename, 0, ARRAY_SIZE(filename));
  10525. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10526. fp = fopen(filename, "r");
  10527. if (!fp)
  10528. {
  10529. DEBUG_INFO("%s does not create.\n", filename);
  10530. fp = fopen(filename, "w+");
  10531. }
  10532. else
  10533. {
  10534. while(fscanf(fp, "%s", dataLine) != EOF)
  10535. {
  10536. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10537. {
  10538. tmpProfileQuantity += 1;
  10539. }
  10540. }
  10541. }
  10542. fclose(fp);
  10543. profileQuantity = (profileQuantity < tmpProfileQuantity) ? tmpProfileQuantity : profileQuantity;
  10544. }
  10545. }
  10546. else
  10547. {
  10548. memset(filename, 0, ARRAY_SIZE(filename));
  10549. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10550. fp = fopen(filename, "r");
  10551. if (!fp)
  10552. {
  10553. DEBUG_INFO("%s does not create.\n", filename);
  10554. fp = fopen(filename, "w+");
  10555. }
  10556. else
  10557. {
  10558. while(fscanf(fp, "%s", dataLine) != EOF)
  10559. {
  10560. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10561. {
  10562. profileQuantity += 1;
  10563. }
  10564. }
  10565. }
  10566. fclose(fp);
  10567. }
  10568. }
  10569. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  10570. {
  10571. int isMatchTransactiodId= FALSE;
  10572. FILE *fp;
  10573. char dataLine[4096]={0};
  10574. char filename[128]={0};
  10575. DEBUG_INFO("Profile purposeStr is TxProfile.\n");
  10576. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  10577. if(SetProfileReq.ConnectorId == 0)
  10578. {
  10579. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10580. goto end;
  10581. }
  10582. int tempIndex = 0;
  10583. //check Transaction active
  10584. if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CHAdeMO)
  10585. {
  10586. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10587. {
  10588. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10589. }
  10590. else
  10591. {
  10592. tempIndex = SetProfileReq.ConnectorId -1;
  10593. }
  10594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10595. {
  10596. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  10597. {
  10598. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  10599. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10600. {
  10601. if(SetProfileReq.ConnectorId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10602. {
  10603. isMatchTransactiodId = TRUE;
  10604. break;
  10605. }
  10606. }
  10607. }
  10608. }
  10609. }
  10610. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_CCS)
  10611. {
  10612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10613. {
  10614. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10615. }
  10616. else
  10617. {
  10618. tempIndex = SetProfileReq.ConnectorId -1;
  10619. }
  10620. for (int index = 0; index < CCS_QUANTITY; index++)
  10621. {
  10622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  10623. {
  10624. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  10625. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10626. {
  10627. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10628. {
  10629. isMatchTransactiodId = TRUE;
  10630. break;
  10631. }
  10632. }
  10633. }
  10634. }
  10635. }
  10636. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_GBT)
  10637. {
  10638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10639. {
  10640. tempIndex = (((SetProfileReq.ConnectorId -1)==2) ? 1: 0);
  10641. }
  10642. else
  10643. {
  10644. tempIndex = SetProfileReq.ConnectorId -1;
  10645. }
  10646. for (int index = 0; index < GB_QUANTITY; index++)
  10647. {
  10648. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10649. {
  10650. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  10651. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10652. {
  10653. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10654. {
  10655. isMatchTransactiodId = TRUE;
  10656. break;
  10657. }
  10658. }
  10659. }
  10660. }
  10661. }
  10662. else if(gunType[SetProfileReq.ConnectorId -1] == GUN_TYPE_DO)
  10663. {
  10664. tempIndex = SetProfileReq.ConnectorId -1;
  10665. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10666. {
  10667. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10668. {
  10669. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  10670. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  10671. {
  10672. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10673. {
  10674. isMatchTransactiodId = TRUE;
  10675. break;
  10676. }
  10677. }
  10678. }
  10679. }
  10680. }
  10681. else
  10682. {
  10683. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10684. {
  10685. tempIndex = 2;
  10686. }
  10687. else
  10688. {
  10689. tempIndex = (SetProfileReq.ConnectorId -1);
  10690. }
  10691. for (int index = 0; index < AC_QUANTITY; index++)
  10692. {
  10693. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10694. {
  10695. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10696. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  10697. {
  10698. if(SetProfileReq.ChargingProfile.TransactionId == ShmOCPP16DataPH->StartTransaction[SetProfileReq.ConnectorId -1].ResponseTransactionId)
  10699. {
  10700. isMatchTransactiodId = TRUE;
  10701. break;
  10702. }
  10703. }
  10704. }
  10705. }
  10706. }
  10707. //check Transaction active
  10708. if(isMatchTransactiodId == FALSE)
  10709. {
  10710. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10711. goto end;
  10712. }
  10713. if((SetProfileReq.ConnectorId != 0) && (SetProfileReq.ConnectorId > gunTotalNumber))
  10714. {
  10715. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10716. goto end;
  10717. }
  10718. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10719. fp = fopen(filename, "r");
  10720. if (!fp)
  10721. {
  10722. DEBUG_INFO("%s does not create.\n", filename);
  10723. fp = fopen(filename, "w+");
  10724. }
  10725. else
  10726. {
  10727. //Check Charging Profile Count
  10728. while(fscanf(fp, "%s", dataLine) != EOF)
  10729. {
  10730. //DEBUG_INFO("word=%s\n",word);
  10731. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10732. {
  10733. profileQuantity += 1;
  10734. }
  10735. }
  10736. }
  10737. fclose(fp);
  10738. }
  10739. // Check ChargeProfileMaxStackLevel
  10740. DEBUG_INFO("%s profile quantity: %d\n", SetProfileReq.ChargingProfile.ChargingProfilePurpose, profileQuantity);
  10741. if(profileQuantity >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10742. {
  10743. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10744. goto end;
  10745. }
  10746. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10747. {
  10748. FILE *fp;
  10749. char dataLine[4096]={0};
  10750. char fnametemp[128]={0};
  10751. int tmpProfileQuantity;
  10752. //Check ChargePointMaxProfile.json exit
  10753. profileQuantity = 0;
  10754. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10755. {
  10756. fp = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  10757. //Check Charging Profile Count
  10758. tmpProfileQuantity = 0;
  10759. while(fscanf(fp, "%s", dataLine) != EOF)
  10760. {
  10761. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10762. {
  10763. profileQuantity += 1;
  10764. tmpProfileQuantity += 1;
  10765. }
  10766. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10767. }
  10768. fclose(fp);
  10769. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n", tmpProfileQuantity);
  10770. }
  10771. //Check TxDefaultProfile_%d.json
  10772. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  10773. {
  10774. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10775. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10776. if((access(fnametemp,F_OK))!=-1)
  10777. {
  10778. fp = fopen(fnametemp, "r");
  10779. //Check Charging Profile Count
  10780. tmpProfileQuantity = 0;
  10781. while(fscanf(fp, "%s", dataLine) != EOF)
  10782. {
  10783. //DEBUG_INFO("word=%s\n",word);
  10784. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10785. {
  10786. profileQuantity += 1;
  10787. tmpProfileQuantity += 1;
  10788. }
  10789. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10790. }
  10791. fclose(fp);
  10792. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  10793. }
  10794. }
  10795. //Check TxProfile_%d.json
  10796. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  10797. {
  10798. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10799. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", idxCon);
  10800. if((access(fnametemp,F_OK))!=-1)
  10801. {
  10802. fp = fopen(fnametemp, "r");
  10803. //Check Charging Profile Count
  10804. tmpProfileQuantity = 0;
  10805. while(fscanf(fp, "%s", dataLine) != EOF)
  10806. {
  10807. if(strstr(dataLine, "chargingProfileId")!= NULL)
  10808. {
  10809. profileQuantity += 1;
  10810. tmpProfileQuantity += 1;
  10811. }
  10812. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  10813. }
  10814. fclose(fp);
  10815. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  10816. }
  10817. }
  10818. DEBUG_INFO("All purpose profile quantity: %d\n", profileQuantity);
  10819. if(profileQuantity > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10820. {
  10821. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10822. goto end;
  10823. }
  10824. }
  10825. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10826. //**********************************Write to File********************************************************/
  10827. {
  10828. FILE *infile;
  10829. FILE *outfile;
  10830. char dataLine[4096]={0};
  10831. char filename[128]={0};
  10832. int chkChar=0;
  10833. for(int idxCon=1; idxCon <= (SetProfileReq.ConnectorId==0?gunTotalNumber:1); idxCon++)
  10834. {
  10835. if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  10836. {
  10837. sprintf(filename, "%s", ChargePointMaxProfile_JSON);
  10838. }
  10839. else if(strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  10840. {
  10841. if(SetProfileReq.ConnectorId==0)
  10842. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", idxCon);
  10843. else
  10844. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", SetProfileReq.ConnectorId);
  10845. }
  10846. else
  10847. {
  10848. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", SetProfileReq.ConnectorId);
  10849. }
  10850. infile = fopen (filename, "r");
  10851. outfile = fopen (tempfile, "w");
  10852. chkChar = fgetc(infile);
  10853. rewind(infile);
  10854. if(chkChar == EOF)
  10855. {
  10856. // Profile is empty
  10857. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10858. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10859. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10860. fclose(infile);
  10861. fclose(outfile);
  10862. sprintf(rmFileCmd,"rm -f %s",filename);
  10863. system(rmFileCmd);
  10864. rename(tempfile, filename);
  10865. }
  10866. else
  10867. {
  10868. // Profile is not empty
  10869. int ChargingProfileAdded = FALSE;
  10870. while (fgets(dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  10871. {
  10872. dataLine[strlen(dataLine) - 1] = '\0'; // eat the newline fgets() stores
  10873. json_object *tmpChargingProfile;
  10874. tmpChargingProfile = json_tokener_parse(dataLine);
  10875. if(!is_error(SetChargingProfile))
  10876. {
  10877. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10878. {
  10879. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10880. {
  10881. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10882. }
  10883. }
  10884. }
  10885. json_object_put(tmpChargingProfile);
  10886. if((tempchargingProfileIdInt == SetProfileReq.ChargingProfile.ChargingProfileId))
  10887. {
  10888. if(ChargingProfileAdded == FALSE)
  10889. {
  10890. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10891. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10892. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10893. ChargingProfileAdded = TRUE;
  10894. }
  10895. }
  10896. else
  10897. {
  10898. fprintf(outfile,"%s\n",dataLine);
  10899. if(ChargingProfileAdded == FALSE)
  10900. {
  10901. if((strcmp((char*)SetProfileReq.ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0) && (SetProfileReq.ConnectorId==0))
  10902. json_object_object_add(SetChargingProfile, "connectorId", json_object_new_int(idxCon));
  10903. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10904. ChargingProfileAdded = TRUE;
  10905. }
  10906. }
  10907. } // end of while loop
  10908. fclose(infile);
  10909. fclose(outfile);
  10910. sprintf(rmFileCmd,"rm -f %s",filename);
  10911. system(rmFileCmd);
  10912. rename(tempfile, filename);
  10913. }
  10914. }
  10915. sleep(1);
  10916. result = TRUE;
  10917. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10918. }
  10919. end:
  10920. json_object_put(SetChargingProfile);
  10921. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10922. {
  10923. if(SetProfileReq.ConnectorId == 0)
  10924. {
  10925. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10926. {
  10927. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10928. }
  10929. }
  10930. else
  10931. checkCompositeSchedule(SetProfileReq.ConnectorId, 86400, &ShmOCPP16DataPH->SmartChargingProfile[SetProfileReq.ConnectorId-1], TRUE);
  10932. }
  10933. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10934. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10935. return result;
  10936. }
  10937. int handleTriggerMessageRequest(char *uuid, char *payload)
  10938. {
  10939. mtrace();
  10940. int result = FAIL;
  10941. int connectorIdIsNULL = FALSE;
  10942. int connectorIdInt =0;
  10943. char sstr[40]={0},sstrtemp[100]={ 0 };
  10944. char requestedMessagestr[40]={0};
  10945. char comfirmstr[20]={0};
  10946. int c = 0;
  10947. char *loc;
  10948. DEBUG_INFO("handleTriggerMessageRequest\n");
  10949. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10950. strcpy(sstrtemp, stringtrimspace(payload));
  10951. c = 0;
  10952. loc = strstr(sstrtemp, "requestedMessage");
  10953. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10954. {
  10955. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10956. c++;
  10957. }
  10958. sstr[c] = '\0';
  10959. strcpy(requestedMessagestr, sstr);
  10960. c = 0;
  10961. loc = strstr(sstrtemp, "connectorId");
  10962. if(loc == NULL)
  10963. {
  10964. connectorIdIsNULL = TRUE;
  10965. }
  10966. else
  10967. {
  10968. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10969. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10970. {
  10971. sstr[c] = loc[strlen("connectorId")+2+c];
  10972. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10973. c++;
  10974. }
  10975. sstr[c] = '\0';
  10976. connectorIdInt = atoi(sstr);
  10977. }
  10978. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10979. {
  10980. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10981. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10982. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10983. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10984. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10985. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10986. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10987. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10988. {
  10989. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10990. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10991. return TRUE;
  10992. }
  10993. else
  10994. {
  10995. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10996. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10997. }
  10998. }
  10999. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  11000. {
  11001. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  11002. sendTriggerMessageConfirmation(uuid,comfirmstr);
  11003. return TRUE;
  11004. }
  11005. //==========================
  11006. // Trigger message
  11007. //==========================
  11008. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11009. {
  11010. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11011. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11012. {
  11013. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11014. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11015. }
  11016. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11017. }
  11018. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  11019. {
  11020. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  11021. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  11022. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  11023. }
  11024. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  11025. {
  11026. //sendBootNotificationRequest();
  11027. server_sign = FALSE;
  11028. }
  11029. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  11030. {
  11031. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11032. }
  11033. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  11034. {
  11035. if(connectorIdIsNULL == FALSE)
  11036. {
  11037. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11038. {
  11039. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  11040. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  11041. }
  11042. }
  11043. else
  11044. {
  11045. for(int idx=0;idx< gunTotalNumber;idx++)
  11046. {
  11047. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11048. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11049. }
  11050. }
  11051. }
  11052. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  11053. {
  11054. if(connectorIdIsNULL == FALSE)
  11055. {
  11056. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  11057. {
  11058. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  11059. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  11060. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  11061. }
  11062. }
  11063. else
  11064. {
  11065. for(int idx=0;idx< gunTotalNumber;idx++)
  11066. {
  11067. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  11068. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  11069. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  11070. }
  11071. }
  11072. }
  11073. return result;
  11074. }
  11075. int handleUnlockConnectorRequest(char *uuid, char *payload)
  11076. {
  11077. mtrace();
  11078. int result = FAIL;
  11079. int connectorIdInt =0;
  11080. char comfirmstr[20]={0};
  11081. int tempIndex = 0;
  11082. json_object *UnlockConnector;
  11083. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  11084. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  11085. UnlockConnector = json_tokener_parse(payload);
  11086. if(!is_error(UnlockConnector))
  11087. {
  11088. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  11089. {
  11090. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  11091. }
  11092. }
  11093. json_object_put(UnlockConnector);
  11094. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  11095. if(gunTotalNumber == 0)
  11096. {
  11097. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11098. goto end;
  11099. }
  11100. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  11101. {
  11102. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11103. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  11104. goto end;
  11105. }
  11106. else
  11107. {
  11108. //check Transaction active
  11109. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  11110. {
  11111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11112. {
  11113. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11114. }
  11115. else
  11116. {
  11117. tempIndex = connectorIdInt -1;
  11118. }
  11119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11120. {
  11121. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11122. {
  11123. //stop Transaction
  11124. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11125. }
  11126. }
  11127. }
  11128. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  11129. {
  11130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11131. {
  11132. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11133. }
  11134. else
  11135. {
  11136. tempIndex = connectorIdInt -1;
  11137. }
  11138. for (int index = 0; index < CCS_QUANTITY; index++)
  11139. {
  11140. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11141. {
  11142. //stop Transaction
  11143. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11144. }
  11145. }
  11146. }
  11147. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  11148. {
  11149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11150. {
  11151. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11152. }
  11153. else
  11154. {
  11155. tempIndex = connectorIdInt -1;
  11156. }
  11157. for (int index = 0; index < GB_QUANTITY; index++)
  11158. {
  11159. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  11160. {
  11161. //stop Transaction
  11162. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11163. }
  11164. }
  11165. }
  11166. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  11167. {
  11168. tempIndex = connectorIdInt -1;
  11169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11170. {
  11171. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  11172. {
  11173. //stop Transaction
  11174. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11175. }
  11176. }
  11177. }
  11178. else
  11179. {
  11180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11181. {
  11182. tempIndex = 2;
  11183. }
  11184. else
  11185. {
  11186. tempIndex = connectorIdInt-1;
  11187. }
  11188. for (int index = 0; index < AC_QUANTITY; index++)
  11189. {
  11190. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  11191. {
  11192. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  11193. }
  11194. }
  11195. }
  11196. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  11197. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  11198. result = TRUE;
  11199. return result;
  11200. }
  11201. end:
  11202. //json_object_put(obj); --- remove temporally
  11203. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  11204. return result;
  11205. }
  11206. static char UpdateFirmwarepayloadData[300]={0};
  11207. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  11208. {
  11209. mtrace();
  11210. int result = FAIL;
  11211. pthread_t t;
  11212. sendUpdateFirmwareConfirmation(uuid);
  11213. memset(UpdateFirmwarepayloadData, 0, 300);
  11214. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  11215. if(!interLock.isUpdateFirmwareGoing)
  11216. {
  11217. interLock.isUpdateFirmwareGoing = 1;
  11218. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  11219. sleep(1);
  11220. }
  11221. else
  11222. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  11223. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  11224. return result;
  11225. }
  11226. void *UpdateFirmwareProcess(void *data)
  11227. {
  11228. pthread_detach(pthread_self());
  11229. mtrace();
  11230. int retriesInt =0, retryIntervalInt=0;
  11231. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  11232. int port=0;
  11233. char locationstr[512]={0}, retrieveDatestr[36]={0};
  11234. int isSuccess = 0;
  11235. char ftpbuf[512];
  11236. char temp[100];
  11237. char * pch;
  11238. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  11239. json_object *UpdateFirmware;
  11240. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  11241. if(!is_error(UpdateFirmware))
  11242. {
  11243. // Required data
  11244. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  11245. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  11246. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  11247. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  11248. // Optional data
  11249. if(json_object_object_get(UpdateFirmware, "retries"))
  11250. {
  11251. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  11252. }
  11253. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  11254. {
  11255. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  11256. }
  11257. }
  11258. json_object_put(UpdateFirmware);
  11259. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11260. memset(path, 0, ARRAY_SIZE(path));
  11261. // Wait retrieveData
  11262. if(strlen(retrieveDatestr) > 10)
  11263. {
  11264. do
  11265. {
  11266. sleep(1);
  11267. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  11268. }
  11269. // Ready to download
  11270. system("rm -f /mnt/*");
  11271. if(strncmp(locationstr,"http", 4) == 0)
  11272. {
  11273. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11274. sprintf(ftppath,"/%s", path);
  11275. DEBUG_INFO("locationstr: %s\n", locationstr);
  11276. DEBUG_INFO("protocol: %s\n",protocol);
  11277. DEBUG_INFO("host: %s\n",host);
  11278. DEBUG_INFO("path: %s\n",path);
  11279. DEBUG_INFO("ftppath: %s\n",ftppath);
  11280. int ftppathlen=strlen(ftppath);
  11281. int i=1;
  11282. char filenametemp[50];
  11283. while(i < ftppathlen)
  11284. {
  11285. int len=ftppathlen-i;
  11286. if(ftppath[len]== 47) // '/' ascll code: 47
  11287. {
  11288. DEBUG_INFO("compare '/' all right\n");
  11289. break;
  11290. }
  11291. i=i+1;
  11292. }
  11293. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11294. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11295. filenametemp[i+1] = 0;
  11296. do
  11297. {
  11298. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11299. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11300. sleep(1);
  11301. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  11302. if(!isSuccess)
  11303. {
  11304. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11305. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11306. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11307. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11308. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11309. }
  11310. else
  11311. {
  11312. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11313. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11314. }
  11315. retriesInt--;
  11316. }while((isSuccess == 0)&&(retriesInt >= 0));
  11317. }
  11318. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  11319. {
  11320. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11321. memset(temp, 0, ARRAY_SIZE(temp));
  11322. //DEBUG_INFO("locationstr=%s\n",locationstr);
  11323. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  11324. int ftppathlen=strlen(ftpbuf);
  11325. int i=1;
  11326. char filenametemp[50];
  11327. while(i < ftppathlen)
  11328. {
  11329. int len=ftppathlen-i;
  11330. if(ftpbuf[len]== 47) // '/' ascll code: 47
  11331. {
  11332. DEBUG_INFO(" compare '/' all right\n");
  11333. break;
  11334. }
  11335. i=i+1;
  11336. }
  11337. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11338. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  11339. filenametemp[i+1] = 0;
  11340. strncpy(temp, ftpbuf, ftppathlen-i+1);
  11341. pch=strchr(temp,'@');
  11342. if(pch==NULL)
  11343. {
  11344. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11345. protocol, host, &port, path);
  11346. strcpy(user,"anonymous");
  11347. strcpy(password,"");
  11348. }
  11349. else
  11350. {
  11351. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11352. protocol, user, password, host, &port, path);
  11353. }
  11354. sscanf(host,"%[^/]%s",host1, path1);
  11355. sprintf(ftppath,"%s", path1);
  11356. //DEBUG_INFO("protocol =%s\n",protocol);
  11357. //DEBUG_INFO("user =%s\n",user);
  11358. //DEBUG_INFO("password =%s\n",password);
  11359. //DEBUG_INFO("host1 =%s\n",host1);
  11360. //DEBUG_INFO("port =%d\n",port);
  11361. //DEBUG_INFO("path1 =%s\n",path1);
  11362. //DEBUG_INFO("ftppath=%s\n",ftppath);
  11363. //ftpFile(host, user, password, port, ftppath, fname);
  11364. //download firmware pthred
  11365. if(port == 0)
  11366. {
  11367. port = 21;
  11368. }
  11369. do
  11370. {
  11371. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  11372. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11373. sleep(1);
  11374. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  11375. if(!isSuccess)
  11376. {
  11377. //BulldogUtil.sleepMs(interval*1000);
  11378. DEBUG_INFO("Update firmware request and download file fail.\n");
  11379. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11380. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11381. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  11382. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11383. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11384. }
  11385. else
  11386. {
  11387. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  11388. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11389. }
  11390. retriesInt--;
  11391. }while((!isSuccess)&&(retriesInt >= 0));
  11392. }
  11393. else
  11394. {
  11395. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  11396. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11397. sleep(1);
  11398. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  11399. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11400. }
  11401. // OCPPPH only, must announce CSU upgrade firmware
  11402. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  11403. interLock.isUpdateFirmwareGoing = 0;
  11404. pthread_exit(NULL);
  11405. }
  11406. int handleCertificateSignedRequest(char *uuid, char *payload)
  11407. {
  11408. mtrace();
  11409. int result = PASS;
  11410. json_object *CertificateSigned;
  11411. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11412. CertificateSigned = json_tokener_parse(payload);
  11413. if(!is_error(CertificateSigned))
  11414. {
  11415. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  11416. }
  11417. json_object_put(CertificateSigned);
  11418. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  11419. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  11420. fclose(fp);
  11421. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11422. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  11423. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  11424. sendCertificateSignedConfirmation(uuid);
  11425. return result;
  11426. }
  11427. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11428. {
  11429. mtrace();
  11430. int result = PASS;
  11431. json_object *DeleteCertificate;
  11432. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11433. DeleteCertificate = json_tokener_parse(payload);
  11434. if(!is_error(DeleteCertificate))
  11435. {
  11436. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11437. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11438. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11439. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11440. }
  11441. json_object_put(DeleteCertificate);
  11442. /*
  11443. * TODO: Delete certificateSigned process
  11444. */
  11445. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  11446. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  11447. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  11448. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  11449. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  11450. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  11451. sendDeleteCertificateConfirmation(uuid);
  11452. return result;
  11453. }
  11454. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  11455. {
  11456. mtrace();
  11457. int result = PASS;
  11458. json_object *ExtendedTriggerMessage;
  11459. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  11460. ExtendedTriggerMessage = json_tokener_parse(payload);
  11461. if(!is_error(ExtendedTriggerMessage))
  11462. {
  11463. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  11464. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  11465. {
  11466. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  11467. }
  11468. else
  11469. {
  11470. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  11471. }
  11472. }
  11473. json_object_put(ExtendedTriggerMessage);
  11474. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  11475. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  11476. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  11477. {
  11478. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  11479. }
  11480. else
  11481. {
  11482. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  11483. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  11484. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  11485. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  11486. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  11487. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  11488. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  11489. {
  11490. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  11491. }
  11492. else
  11493. {
  11494. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  11495. }
  11496. }
  11497. sendExtendedTriggerMessageConfirmation(uuid);
  11498. //==========================
  11499. // Trigger message
  11500. //==========================
  11501. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  11502. {
  11503. //sendBootNotificationRequest();
  11504. server_sign = FALSE;
  11505. }
  11506. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  11507. {
  11508. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  11509. }
  11510. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  11511. {
  11512. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  11513. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  11514. {
  11515. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  11516. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  11517. }
  11518. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  11519. }
  11520. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  11521. {
  11522. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  11523. }
  11524. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  11525. {
  11526. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11527. {
  11528. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  11529. }
  11530. else
  11531. {
  11532. for(int idx=0;idx< gunTotalNumber;idx++)
  11533. {
  11534. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  11535. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  11536. }
  11537. }
  11538. }
  11539. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  11540. {
  11541. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  11542. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  11543. {
  11544. 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\" &");
  11545. }
  11546. }
  11547. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  11548. {
  11549. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  11550. {
  11551. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  11552. }
  11553. else
  11554. {
  11555. for(int idx=0;idx< gunTotalNumber;idx++)
  11556. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  11557. }
  11558. }
  11559. return result;
  11560. }
  11561. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11562. {
  11563. mtrace();
  11564. int result = PASS;
  11565. json_object *GetInstalledCertificateIds;
  11566. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11567. GetInstalledCertificateIds = json_tokener_parse(payload);
  11568. if(!is_error(GetInstalledCertificateIds))
  11569. {
  11570. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  11571. }
  11572. json_object_put(GetInstalledCertificateIds);
  11573. /*
  11574. * TODO: Return installed certificate process
  11575. */
  11576. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  11577. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  11578. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  11579. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  11580. sendGetInstalledCertificateIdsConfirmation(uuid);
  11581. return result;
  11582. }
  11583. int handleGetLogRequest(char *uuid, char *payload)
  11584. {
  11585. mtrace();
  11586. int result = PASS;
  11587. json_object *GetLog;
  11588. DEBUG_INFO("handleGetLogRequest...\n");
  11589. GetLog = json_tokener_parse(payload);
  11590. if(!is_error(GetLog))
  11591. {
  11592. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11593. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11594. if(json_object_object_get(GetLog, "retries") != NULL)
  11595. {
  11596. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11597. }
  11598. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11599. {
  11600. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11601. }
  11602. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11603. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11604. {
  11605. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11606. }
  11607. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11608. {
  11609. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11610. }
  11611. }
  11612. json_object_put(GetLog);
  11613. /*
  11614. * TODO: Upload log process
  11615. */
  11616. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  11617. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  11618. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  11619. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  11620. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  11621. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  11622. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  11623. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  11624. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  11625. sendGetLogConfirmation(uuid);
  11626. return result;
  11627. }
  11628. int handleInstallCertificateRequest(char *uuid, char *payload)
  11629. {
  11630. mtrace();
  11631. int result = PASS;
  11632. json_object *InstallCertificate;
  11633. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11634. InstallCertificate = json_tokener_parse(payload);
  11635. if(!is_error(InstallCertificate))
  11636. {
  11637. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11638. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11639. /*
  11640. * TODO: Install certificate process
  11641. */
  11642. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11643. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11644. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11645. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11646. sendInstallCertificateConfirmation(uuid);
  11647. }
  11648. json_object_put(InstallCertificate);
  11649. return result;
  11650. }
  11651. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11652. {
  11653. mtrace();
  11654. int result = PASS;
  11655. json_object *SignedUpdateFirmware;
  11656. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11657. SignedUpdateFirmware = json_tokener_parse(payload);
  11658. if(!is_error(SignedUpdateFirmware))
  11659. {
  11660. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11661. {
  11662. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11663. }
  11664. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11665. {
  11666. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11667. }
  11668. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11669. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11670. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11671. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11672. {
  11673. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11674. }
  11675. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11676. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11677. }
  11678. json_object_put(SignedUpdateFirmware);
  11679. /*
  11680. * TODO: Upgrade firmware process
  11681. */
  11682. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11683. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11684. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11685. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11686. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11687. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11688. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11689. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11690. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11691. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11692. sendInstallCertificateConfirmation(uuid);
  11693. return result;
  11694. }
  11695. int handleUnknownRequest(char *uuid, char *payload)
  11696. {
  11697. mtrace();
  11698. int result = PASS;
  11699. DEBUG_INFO("handleUnknownRequest...\n");
  11700. sendUnknownConfirmation(uuid);
  11701. result = PASS;
  11702. return result;
  11703. }
  11704. //==========================================
  11705. // Handle server response routine
  11706. //==========================================
  11707. void handleAuthorizeResponse(char *payload, int gun_index)
  11708. {
  11709. mtrace();
  11710. char expiryDatestr[30]={0};
  11711. char parentIdTagstr[20]={0};
  11712. char statusstr[20]={0};
  11713. int expiryDateISNULL=FALSE;
  11714. int parentIdTagISNULL=FALSE;
  11715. DEBUG_INFO("handleAuthorizeResponse...\n");
  11716. json_object *Authorize;
  11717. Authorize = json_tokener_parse(payload);
  11718. if(!is_error(Authorize))
  11719. {
  11720. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11721. {
  11722. // Required data
  11723. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11724. // Optional data
  11725. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11726. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11727. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11728. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11729. }
  11730. }
  11731. json_object_put(Authorize);
  11732. if(expiryDateISNULL == FALSE)
  11733. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11734. if(parentIdTagISNULL == FALSE)
  11735. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11736. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11737. //Update idTag information to authorization cache if supproted
  11738. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11739. {
  11740. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11741. }
  11742. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11743. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11744. authorizeRetryTimes = 0;
  11745. }
  11746. void handleBootNotificationResponse(char *payload, int gun_index)
  11747. {
  11748. mtrace();
  11749. char statusStr[12]={0};
  11750. char currentTimeStr[30]={0};
  11751. int intervalInt = 0;
  11752. DEBUG_INFO("handleBootNotificationResponse...\n");
  11753. json_object *BootNotification;
  11754. BootNotification = json_tokener_parse(payload);
  11755. if(!is_error(BootNotification))
  11756. {
  11757. // Required data
  11758. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11759. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11760. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11761. }
  11762. json_object_put(BootNotification);
  11763. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11764. BootNotificationInterval = intervalInt;
  11765. HeartBeatWaitTime = intervalInt;
  11766. //write back to ShmOCPP16DataPH->BootNotification
  11767. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11768. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11769. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11770. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11771. {
  11772. server_sign = TRUE;
  11773. server_pending =FALSE;
  11774. }
  11775. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11776. {
  11777. server_pending = TRUE;
  11778. }
  11779. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11780. srand(time(NULL));
  11781. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11782. SetOcppConnStatus(TRUE);
  11783. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11784. }
  11785. void handleDataTransferResponse(char *payload, int gun_index)
  11786. {
  11787. char sstr[160]={0};//sstr[200]={ 0 };
  11788. int c = 0;
  11789. char *loc;
  11790. DEBUG_INFO("handleDataTransferResponse ...\n");
  11791. loc = strstr(payload, "status");
  11792. c = 0;
  11793. while (loc[3+strlen("status")+c] != '\"')
  11794. {
  11795. sstr[c] = loc[3+strlen("status")+c];
  11796. c++;
  11797. }
  11798. sstr[c] = '\0';
  11799. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11800. }
  11801. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11802. {
  11803. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11804. //struct json_object *obj;
  11805. // obj = json_tokener_parse(payload);
  11806. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11807. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11808. //No fields are defined.
  11809. }
  11810. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11811. {
  11812. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11813. //struct json_object *obj;
  11814. // obj = json_tokener_parse(payload);
  11815. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11816. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11817. //No fields are defined.
  11818. }
  11819. void handleHeartbeatResponse(char *payload, int gun_index)
  11820. {
  11821. mtrace();
  11822. DEBUG_INFO("handleHeartbeatResponse...\n");
  11823. json_object *Heartbeat;
  11824. Heartbeat = json_tokener_parse(payload);
  11825. if(!is_error(Heartbeat))
  11826. {
  11827. // Required data
  11828. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11829. }
  11830. json_object_put(Heartbeat);
  11831. if(FirstHeartBeat == 0)
  11832. {
  11833. FirstHeartBeat = 1;
  11834. DEBUG_INFO("FirstHeartBeat \n");
  11835. }
  11836. HeartBeatWithNOResponse = 0;
  11837. clientTime.Heartbeat=time((time_t*)NULL);
  11838. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11839. }
  11840. void handleMeterValuesResponse(char *payload, int gun_index)
  11841. {
  11842. mtrace();
  11843. DEBUG_INFO("handleMeterValuesResponse...\n");
  11844. }
  11845. void handleStartTransactionResponse(char *payload, int gun_index)
  11846. {
  11847. mtrace();
  11848. //int transactionIdInt = 0;
  11849. FILE *outfile;
  11850. char data[100]={0};
  11851. DEBUG_INFO("handleStartTransactionResponse...\n");
  11852. json_object *StartTransaction;
  11853. StartTransaction = json_tokener_parse(payload);
  11854. if(!is_error(StartTransaction))
  11855. {
  11856. // Required data
  11857. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11858. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11859. // Optional data
  11860. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11861. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11862. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11863. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11864. }
  11865. json_object_put(StartTransaction);
  11866. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11867. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11868. //-----------Start : write to the Queue TransactionId file -----------------//
  11869. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11870. {}
  11871. else
  11872. {
  11873. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11874. if(log == NULL)
  11875. {
  11876. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11877. return ;
  11878. }
  11879. else
  11880. {
  11881. fclose(log);
  11882. }
  11883. }
  11884. // open file for writing
  11885. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11886. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11887. {
  11888. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11889. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11890. fputs(data, outfile);
  11891. fclose (outfile);
  11892. }
  11893. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11894. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11895. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11896. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11897. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11898. }
  11899. void handleStatusNotificationResponse(char *payload, int gun_index)
  11900. {
  11901. mtrace();
  11902. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11903. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11904. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11905. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11906. }
  11907. void handleStopTransactionnResponse(char *payload, int gun_index)
  11908. {
  11909. mtrace();
  11910. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11911. json_object *StopTransaction;
  11912. StopTransaction = json_tokener_parse(payload);
  11913. if(!is_error(StopTransaction))
  11914. {
  11915. // Optional data
  11916. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11917. {
  11918. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11919. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11920. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11921. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11922. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11923. }
  11924. }
  11925. json_object_put(StopTransaction);
  11926. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11927. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11928. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11929. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11930. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11931. }
  11932. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11933. {
  11934. mtrace();
  11935. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11936. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11937. }
  11938. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11939. {
  11940. mtrace();
  11941. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11942. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11943. }
  11944. void handleSignCertificateResponse(char *payload, int gun_index)
  11945. {
  11946. mtrace();
  11947. DEBUG_INFO("handleSignCertificateResponse...\n");
  11948. json_object *SignCertificate;
  11949. SignCertificate = json_tokener_parse(payload);
  11950. if(!is_error(SignCertificate))
  11951. {
  11952. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11953. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11954. }
  11955. json_object_put(SignCertificate);
  11956. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11957. }
  11958. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11959. {
  11960. mtrace();
  11961. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11962. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11963. }
  11964. //==========================================
  11965. // Handle Error routine
  11966. //==========================================
  11967. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11968. {
  11969. mtrace();
  11970. #ifdef SystemLogMessage
  11971. DEBUG_INFO("errorCode: %s\n", errorCode);
  11972. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11973. DEBUG_INFO("errorDetails: %s\n", payload);
  11974. #endif
  11975. }
  11976. //===============================================
  11977. // Common routine
  11978. //===============================================
  11979. int initialConfigurationTable(void)
  11980. {
  11981. //clock_t start_t, end_t, total_t;
  11982. FILE *fp;
  11983. FILE *outfile;
  11984. char str[512]={0};
  11985. char sstr[256]={0};
  11986. int c = 0;
  11987. char *loc;
  11988. int confVersion = 8;
  11989. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11990. //start_t = clock();
  11991. //printf("Starting of the program, start_t = %ld\n", start_t);
  11992. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11993. // Check configuration file size is correct
  11994. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  11995. {
  11996. struct stat st;
  11997. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  11998. if(st.st_size < 3100)
  11999. {
  12000. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  12001. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  12002. }
  12003. }
  12004. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  12005. {
  12006. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12007. if(outfile == NULL)
  12008. {
  12009. DEBUG_INFO("Error opening file\n");
  12010. return FALSE;
  12011. }
  12012. /*Core Profile*/
  12013. //AllowOfflineTxForUnknownId
  12014. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12016. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  12017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12018. //AuthorizationCacheEnabled
  12019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12020. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12023. //AuthorizeRemoteTxRequests
  12024. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12025. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12026. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  12027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12028. //BlinkRepeat
  12029. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12031. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12033. //ClockAlignedDataInterval
  12034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12038. //ConnectionTimeOut
  12039. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12040. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12041. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12043. //GetConfigurationMaxKeys
  12044. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12045. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12046. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  12047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12048. // HeartbeatInterval
  12049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  12052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12053. // LightIntensity
  12054. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12055. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12058. // LocalAuthorizeOffline
  12059. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  12060. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12061. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12063. // LocalPreAuthorize
  12064. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  12065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12066. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12068. // MaxEnergyOnInvalidId
  12069. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12073. // MeterValuesAlignedData
  12074. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12075. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12076. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12077. 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" );
  12078. else
  12079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12081. // MeterValuesAlignedDataMaxLength
  12082. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12083. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12084. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "8" );
  12086. else
  12087. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "10" );
  12088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12089. // MeterValuesSampledData
  12090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12092. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12093. 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" );
  12094. else
  12095. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,Current.Offered" );
  12096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12097. // MeterValuesSampledDataMaxLength
  12098. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12100. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12101. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "8" );
  12102. else
  12103. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "10" );
  12104. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12105. // MeterValueSampleInterval
  12106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  12109. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12110. // MinimumStatusDuration
  12111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  12114. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  12115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12116. // NumberOfConnectors
  12117. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12118. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12120. {
  12121. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12122. }
  12123. else
  12124. {
  12125. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12126. }
  12127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12128. // ResetRetries
  12129. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12130. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12131. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12133. // ConnectorPhaseRotation
  12134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12138. // ConnectorPhaseRotationMaxLength
  12139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12143. // StopTransactionOnEVSideDisconnect
  12144. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12145. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12146. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12148. // StopTransactionOnInvalidId
  12149. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  12150. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12151. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12153. // StopTxnAlignedData
  12154. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  12155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12156. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  12157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12158. // StopTxnAlignedDataMaxLength
  12159. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12160. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12163. // StopTxnSampledData
  12164. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12165. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12167. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SoC" );
  12168. else
  12169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  12170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12171. // StopTxnSampledDataMaxLength
  12172. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12173. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12174. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12175. {
  12176. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  12177. }
  12178. else
  12179. {
  12180. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  12181. }
  12182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12183. // SupportedFeatureProfiles
  12184. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12186. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12188. // SupportedFeatureProfilesMaxLength
  12189. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12193. // TransactionMessageAttempts
  12194. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12195. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12197. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12199. // TransactionMessageRetryInterval
  12200. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12201. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12202. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12203. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12205. // UnlockConnectorOnEVSideDisconnect
  12206. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12207. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12208. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12210. // WebSocketPingInterval
  12211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12215. // QueueOffLineMeterValues
  12216. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 1;
  12217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "FALSE" );
  12219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12220. // AuthorizationKey
  12221. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12222. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12223. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  12224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12225. // SecurityProfile
  12226. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12228. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12230. // DefaultPrice
  12231. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12233. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12234. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12235. // CustomDisplayCostAndPrice
  12236. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12237. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12238. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12239. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12240. // CustomIdleFeeAfterStop
  12241. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12242. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12243. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12244. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12245. // Configuration Version
  12246. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  12247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12248. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  12249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12250. //* Local Auth List Management Profile*/
  12251. #if 0
  12252. //For OCTT Test Case
  12253. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  12255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12256. #endif
  12257. #if 1
  12258. //LocalAuthListEnabled
  12259. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12260. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12262. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12263. #endif
  12264. //LocalAuthListMaxLength
  12265. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12266. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12267. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12269. //SendLocalListMaxLength
  12270. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12271. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12272. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  12273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12274. //ReserveConnectorZeroSupported
  12275. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12277. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12279. //* Smart Charging Profile */
  12280. //ChargeProfileMaxStackLevel
  12281. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12282. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12285. // ChargingScheduleAllowedChargingRateUnit
  12286. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12287. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12288. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  12289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12290. // ChargingScheduleMaxPeriods
  12291. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12293. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12295. // ConnectorSwitch3to1PhaseSupported
  12296. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12298. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  12299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12300. // MaxChargingProfilesInstalled
  12301. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12305. fclose(outfile);
  12306. }
  12307. else
  12308. {
  12309. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  12310. char keystr[60]={0};
  12311. char readonlystr[10]={0};
  12312. char valuestr[256]={0};
  12313. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  12314. if(fp == NULL) {
  12315. DEBUG_INFO("Error opening file");
  12316. return FALSE;
  12317. }
  12318. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  12319. {
  12320. //DEBUG_INFO("Get Configuration \n");
  12321. if(strlen(str) > 0)
  12322. {
  12323. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12324. //*************************key*********************************/
  12325. if(strstr(str, "key") != NULL)
  12326. {
  12327. loc = strstr(str, "key");
  12328. c = 0;
  12329. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12330. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12331. {
  12332. sstr[c] = loc[strlen("key")+3+c];
  12333. c++;
  12334. }
  12335. sstr[c] = '\0';
  12336. strcpy(keystr,sstr);
  12337. }
  12338. //*************************readonly*********************************/
  12339. if(strstr(str, "readonly") != NULL)
  12340. {
  12341. loc = strstr(str, "readonly");
  12342. c = 0;
  12343. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12344. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  12345. {
  12346. sstr[c] = loc[strlen("readonly")+2+c];
  12347. c++;
  12348. }
  12349. sstr[c] = '\0';
  12350. strcpy(readonlystr,sstr);
  12351. }
  12352. //*************************value*********************************/
  12353. if(strstr(str, "value") != NULL)
  12354. {
  12355. loc = strstr(str, "value");
  12356. c = 0;
  12357. memset(sstr ,0, ARRAY_SIZE(sstr) );
  12358. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  12359. {
  12360. sstr[c] = loc[strlen("value")+3+c];
  12361. c++;
  12362. }
  12363. sstr[c] = '\0';
  12364. strcpy(valuestr,sstr);
  12365. }
  12366. // DEBUG_INFO("keystr=%s\n",keystr);
  12367. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  12368. // DEBUG_INFO("valuestr=%s\n",valuestr);
  12369. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  12370. {
  12371. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12372. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12373. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  12374. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12375. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  12376. }
  12377. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  12378. {
  12379. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12380. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12381. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  12382. }
  12383. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  12384. {
  12385. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  12387. }
  12388. if(strcmp(keystr, "BlinkRepeat") == 0)
  12389. {
  12390. //Charger.BlinkRepeat = Integer.parseInt(value);
  12391. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  12393. }
  12394. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  12395. {
  12396. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12397. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  12398. }
  12399. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  12400. {
  12401. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  12403. }
  12404. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  12405. {
  12406. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12407. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  12408. }
  12409. if(strcmp(keystr, "HeartbeatInterval") == 0)
  12410. {
  12411. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12412. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  12413. HeartBeatWaitTime = atoi(valuestr);
  12414. }
  12415. if(strcmp(keystr, "LightIntensity") == 0)
  12416. {
  12417. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12418. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  12419. }
  12420. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  12421. {
  12422. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12423. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  12424. }
  12425. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  12426. {
  12427. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12428. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  12429. }
  12430. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  12431. {
  12432. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12433. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  12434. }
  12435. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  12436. {
  12437. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12438. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  12439. }
  12440. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  12441. {
  12442. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12443. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  12444. }
  12445. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  12446. {
  12447. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12448. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  12449. }
  12450. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  12451. {
  12452. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12453. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  12454. }
  12455. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  12456. {
  12457. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12458. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  12459. }
  12460. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  12461. {
  12462. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12463. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  12464. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  12465. }
  12466. if(strcmp(keystr, "NumberOfConnectors") == 0)
  12467. {
  12468. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12469. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  12470. }
  12471. if(strcmp(keystr, "ResetRetries") == 0)
  12472. {
  12473. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12474. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  12475. }
  12476. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  12477. {
  12478. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12479. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  12480. }
  12481. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  12482. {
  12483. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12484. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  12485. }
  12486. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  12487. {
  12488. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  12490. }
  12491. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  12492. {
  12493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12494. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  12495. }
  12496. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  12497. {
  12498. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12499. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  12500. }
  12501. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  12502. {
  12503. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12504. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12505. }
  12506. if(strcmp(keystr, "StopTxnSampledData") == 0)
  12507. {
  12508. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12509. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  12510. }
  12511. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  12512. {
  12513. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12514. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  12515. }
  12516. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  12517. {
  12518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12519. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  12520. }
  12521. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  12522. {
  12523. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12524. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  12525. }
  12526. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  12527. {
  12528. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12529. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  12530. TransactionMessageAttemptsValue = atoi(valuestr);
  12531. }
  12532. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  12533. {
  12534. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12535. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  12536. TransactionMessageRetryIntervalValue = atoi(valuestr);
  12537. }
  12538. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  12539. {
  12540. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12541. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  12542. }
  12543. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  12544. {
  12545. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12546. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  12547. }
  12548. if(strcmp(keystr, "QueueOffLineMeterValues") == 0)
  12549. {
  12550. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12551. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", valuestr);
  12552. }
  12553. if(strcmp(keystr, "AuthorizationKey") == 0)
  12554. {
  12555. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12556. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  12557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  12558. }
  12559. if(strcmp(keystr, "SecurityProfile") == 0)
  12560. {
  12561. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12562. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  12563. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  12564. }
  12565. if(strcmp(keystr, "DefaultPrice") == 0)
  12566. {
  12567. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12568. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  12569. }
  12570. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  12571. {
  12572. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12573. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  12574. }
  12575. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  12576. {
  12577. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12578. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  12579. }
  12580. if(strcmp(keystr, "ConfigurationVersion") == 0)
  12581. {
  12582. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12583. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  12584. }
  12585. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  12586. {
  12587. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12588. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  12589. }
  12590. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  12591. {
  12592. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12593. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  12594. }
  12595. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  12596. {
  12597. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12598. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  12599. }
  12600. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  12601. {
  12602. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12603. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  12604. }
  12605. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  12606. {
  12607. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12608. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  12609. }
  12610. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12611. {
  12612. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12613. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  12614. }
  12615. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  12616. {
  12617. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12618. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  12619. }
  12620. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  12621. {
  12622. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  12624. }
  12625. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  12626. {
  12627. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  12628. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  12629. }
  12630. }
  12631. }
  12632. fclose(fp);
  12633. }
  12634. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  12635. {
  12636. return PASS;
  12637. }
  12638. else
  12639. {
  12640. return FAIL;
  12641. }
  12642. }
  12643. void StoreConfigurationTable(void)
  12644. {
  12645. FILE *outfile;
  12646. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12647. if(outfile == NULL)
  12648. {
  12649. DEBUG_INFO("Error opening file");
  12650. return ;
  12651. }
  12652. /*Core Profile*/
  12653. //AllowOfflineTxForUnknownId
  12654. /*
  12655. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12656. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12658. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12659. */
  12660. //DEBUG_INFO("data=%s\n",data);
  12661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12662. //AuthorizationCacheEnabled
  12663. /*
  12664. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12665. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12667. */
  12668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12669. //AuthorizeRemoteTxRequests
  12670. /*
  12671. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12672. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12673. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12674. */
  12675. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12676. //BlinkRepeat
  12677. /*
  12678. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12679. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12680. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12681. */
  12682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12683. //ClockAlignedDataInterval
  12684. /*
  12685. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12686. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12687. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12688. */
  12689. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12690. //ConnectionTimeOut
  12691. /*
  12692. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12693. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12694. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12695. */
  12696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12697. //GetConfigurationMaxKeys
  12698. /*
  12699. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12700. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12701. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12702. */
  12703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12704. // HeartbeatInterval
  12705. /*
  12706. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12707. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12708. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12709. */
  12710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12711. // LightIntensity
  12712. /*
  12713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12714. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12715. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12716. */
  12717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12718. // LocalAuthorizeOffline
  12719. /*
  12720. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12721. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12722. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12723. */
  12724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12725. // LocalPreAuthorize
  12726. /*
  12727. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12728. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12729. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12730. */
  12731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12732. // MaxEnergyOnInvalidId
  12733. /*
  12734. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12735. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12736. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12737. */
  12738. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12740. // MeterValuesAlignedData
  12741. /*
  12742. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12743. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12744. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12745. */
  12746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12747. // MeterValuesAlignedDataMaxLength
  12748. /*
  12749. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12750. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12751. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12752. */
  12753. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12754. // MeterValuesSampledData
  12755. /*
  12756. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12757. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12758. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12759. */
  12760. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12761. // MeterValuesSampledDataMaxLength
  12762. /*
  12763. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12764. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12765. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12766. */
  12767. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12768. // MeterValueSampleInterval
  12769. /*
  12770. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12771. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12772. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12773. */
  12774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12775. // MinimumStatusDuration
  12776. /*
  12777. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12778. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12779. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12780. */
  12781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12782. // NumberOfConnectors
  12783. /*
  12784. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12785. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12787. {
  12788. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12789. }
  12790. else
  12791. {
  12792. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12793. }
  12794. */
  12795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12796. // ResetRetries
  12797. /*
  12798. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12799. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12800. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12801. */
  12802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12803. // ConnectorPhaseRotation
  12804. /*
  12805. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12806. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12807. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12808. */
  12809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12810. // ConnectorPhaseRotationMaxLength
  12811. /*
  12812. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12813. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12814. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12815. */
  12816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12817. // StopTransactionOnEVSideDisconnect
  12818. /*
  12819. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12820. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12821. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12822. */
  12823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12824. // StopTransactionOnInvalidId
  12825. /*
  12826. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12827. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12828. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12829. */
  12830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12831. // StopTxnAlignedData
  12832. /*
  12833. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12834. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12835. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12836. */
  12837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12838. // StopTxnAlignedDataMaxLength
  12839. /*
  12840. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12841. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12842. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12843. */
  12844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12845. // StopTxnSampledData
  12846. /*
  12847. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12848. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12849. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12850. */
  12851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12852. // StopTxnSampledDataMaxLength
  12853. /*
  12854. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12855. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12856. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12857. */
  12858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12859. // SupportedFeatureProfiles
  12860. /*
  12861. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12862. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12863. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12864. */
  12865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12866. // SupportedFeatureProfilesMaxLength
  12867. /*
  12868. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12869. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12870. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12871. */
  12872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12873. // TransactionMessageAttempts
  12874. /*
  12875. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12876. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12877. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12878. */
  12879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12880. // TransactionMessageRetryInterval
  12881. /*
  12882. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12883. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12884. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12885. */
  12886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12887. // UnlockConnectorOnEVSideDisconnect
  12888. /*
  12889. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12890. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12891. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12892. */
  12893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12894. // WebSocketPingInterval
  12895. /*
  12896. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12897. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12898. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12899. */
  12900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12901. // QueueOffLineMeterValues
  12902. /*
  12903. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility = 0;
  12904. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemName, "QueueOffLineMeterValues");
  12905. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "TRUE" );
  12906. */
  12907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineMeterValues", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData);
  12908. // AuthorizationKey
  12909. /*
  12910. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12911. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12912. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12913. */
  12914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12915. // SecurityProfile
  12916. /*
  12917. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12918. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12919. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12920. */
  12921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12922. // DefaultPrice
  12923. /*
  12924. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12925. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12926. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12927. */
  12928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12929. // CustomDisplayCostAndPrice
  12930. /*
  12931. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12932. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12933. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12934. */
  12935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12936. // CustomIdleFeeAfterStop
  12937. /*
  12938. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12939. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12940. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12941. */
  12942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12943. // ConfigurationVersion
  12944. /*
  12945. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12946. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12947. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12948. */
  12949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12950. //* Local Auth List Management Profile*/
  12951. //LocalAuthListEnabled
  12952. /*
  12953. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12954. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12955. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12956. */
  12957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12958. //LocalAuthListMaxLength
  12959. /*
  12960. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12961. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12962. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12963. */
  12964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12965. //SendLocalListMaxLength
  12966. /*
  12967. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12968. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12969. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12970. */
  12971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12972. //ReserveConnectorZeroSupported
  12973. /*
  12974. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12975. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12976. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12977. */
  12978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12979. //* Smart Charging Profile */
  12980. //ChargeProfileMaxStackLevel
  12981. /*
  12982. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12983. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12984. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12985. */
  12986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12987. // ChargingScheduleAllowedChargingRateUnit
  12988. /*
  12989. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12990. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12991. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12992. */
  12993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12994. // ChargingScheduleMaxPeriods
  12995. /*
  12996. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12997. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12998. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12999. */
  13000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13001. // ConnectorSwitch3to1PhaseSupported
  13002. /*
  13003. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  13004. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  13005. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  13006. */
  13007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13008. // MaxChargingProfilesInstalled
  13009. /*
  13010. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  13011. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  13012. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  13013. */
  13014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13015. fclose(outfile);
  13016. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13017. }
  13018. void getKeyValue(char *keyReq)
  13019. {
  13020. int isEmpty = FALSE;
  13021. int isKnowKey = FALSE;
  13022. DEBUG_INFO("keyReq = %s\n", keyReq);
  13023. if((keyReq == NULL) || (strlen(keyReq) == 0))
  13024. isEmpty = TRUE;
  13025. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  13026. {
  13027. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  13028. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  13029. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13030. {
  13031. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  13032. }
  13033. else
  13034. {
  13035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  13036. }
  13037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  13038. isKnowKey = TRUE;
  13039. }
  13040. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  13041. {
  13042. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  13043. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  13044. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13045. {
  13046. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  13047. }
  13048. else
  13049. {
  13050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  13051. }
  13052. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  13053. isKnowKey = TRUE;
  13054. }
  13055. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  13056. {
  13057. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  13058. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  13059. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13060. {
  13061. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  13062. }
  13063. else
  13064. {
  13065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  13066. }
  13067. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  13068. isKnowKey = TRUE;
  13069. }
  13070. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  13071. {
  13072. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  13073. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  13074. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13075. {
  13076. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  13077. }
  13078. else
  13079. {
  13080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  13081. }
  13082. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  13083. isKnowKey = TRUE;
  13084. }
  13085. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  13086. {
  13087. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  13088. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  13089. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13090. {
  13091. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  13092. }
  13093. else
  13094. {
  13095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  13096. }
  13097. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  13098. isKnowKey = TRUE;
  13099. }
  13100. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  13101. {
  13102. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  13103. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  13104. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13105. {
  13106. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  13107. }
  13108. else
  13109. {
  13110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  13111. }
  13112. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  13113. isKnowKey = TRUE;
  13114. }
  13115. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  13116. {
  13117. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  13118. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  13119. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13120. {
  13121. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  13122. }
  13123. else
  13124. {
  13125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  13126. }
  13127. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  13128. isKnowKey = TRUE;
  13129. }
  13130. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  13131. {
  13132. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  13133. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  13134. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13135. {
  13136. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  13137. }
  13138. else
  13139. {
  13140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  13141. }
  13142. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  13143. isKnowKey = TRUE;
  13144. }
  13145. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  13146. {
  13147. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  13148. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  13149. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13150. {
  13151. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  13152. }
  13153. else
  13154. {
  13155. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  13156. }
  13157. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  13158. isKnowKey = TRUE;
  13159. }
  13160. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  13161. {
  13162. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  13163. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  13164. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13165. {
  13166. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  13167. }
  13168. else
  13169. {
  13170. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  13171. }
  13172. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  13173. isKnowKey = TRUE;
  13174. }
  13175. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  13176. {
  13177. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  13178. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  13179. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13180. {
  13181. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  13182. }
  13183. else
  13184. {
  13185. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  13186. }
  13187. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  13188. isKnowKey = TRUE;
  13189. }
  13190. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  13191. {
  13192. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  13193. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  13194. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13195. {
  13196. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13197. }
  13198. else
  13199. {
  13200. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13201. }
  13202. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  13203. isKnowKey = TRUE;
  13204. }
  13205. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  13206. {
  13207. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  13208. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  13209. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13210. {
  13211. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13212. }
  13213. else
  13214. {
  13215. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13216. }
  13217. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  13218. isKnowKey = TRUE;
  13219. }
  13220. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  13221. {
  13222. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  13223. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  13224. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13225. {
  13226. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13227. }
  13228. else
  13229. {
  13230. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13231. }
  13232. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  13233. isKnowKey = TRUE;
  13234. }
  13235. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  13236. {
  13237. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  13238. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  13239. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13240. {
  13241. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  13242. }
  13243. else
  13244. {
  13245. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  13246. }
  13247. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  13248. isKnowKey = TRUE;
  13249. }
  13250. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  13251. {
  13252. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  13253. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  13254. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13255. {
  13256. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13257. }
  13258. else
  13259. {
  13260. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13261. }
  13262. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  13263. isKnowKey = TRUE;
  13264. }
  13265. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  13266. {
  13267. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  13268. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  13269. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13270. {
  13271. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  13272. }
  13273. else
  13274. {
  13275. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  13276. }
  13277. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  13278. isKnowKey = TRUE;
  13279. }
  13280. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  13281. {
  13282. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  13283. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  13284. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13285. {
  13286. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  13287. }
  13288. else
  13289. {
  13290. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  13291. }
  13292. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  13293. isKnowKey = TRUE;
  13294. }
  13295. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  13296. {
  13297. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  13298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  13299. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13300. {
  13301. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  13302. }
  13303. else
  13304. {
  13305. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  13306. }
  13307. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  13308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  13309. isKnowKey = TRUE;
  13310. }
  13311. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  13312. {
  13313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  13314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  13315. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13316. {
  13317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  13318. }
  13319. else
  13320. {
  13321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  13322. }
  13323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  13324. isKnowKey = TRUE;
  13325. }
  13326. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  13327. {
  13328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  13329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  13330. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13331. {
  13332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  13333. }
  13334. else
  13335. {
  13336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  13337. }
  13338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  13339. isKnowKey = TRUE;
  13340. }
  13341. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  13342. {
  13343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  13344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  13345. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13346. {
  13347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13348. }
  13349. else
  13350. {
  13351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13352. }
  13353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  13354. isKnowKey = TRUE;
  13355. }
  13356. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  13357. {
  13358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  13359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  13360. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13361. {
  13362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13363. }
  13364. else
  13365. {
  13366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13367. }
  13368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  13369. isKnowKey = TRUE;
  13370. }
  13371. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  13372. {
  13373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  13374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  13375. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13376. {
  13377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  13378. }
  13379. else
  13380. {
  13381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  13382. }
  13383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  13384. isKnowKey = TRUE;
  13385. }
  13386. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  13387. {
  13388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  13389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  13390. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13391. {
  13392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  13393. }
  13394. else
  13395. {
  13396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  13397. }
  13398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  13399. isKnowKey = TRUE;
  13400. }
  13401. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  13402. {
  13403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  13404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  13405. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13406. {
  13407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13408. }
  13409. else
  13410. {
  13411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13412. }
  13413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  13414. isKnowKey = TRUE;
  13415. }
  13416. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  13417. {
  13418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  13419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  13420. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13421. {
  13422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  13423. }
  13424. else
  13425. {
  13426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  13427. }
  13428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  13429. isKnowKey = TRUE;
  13430. }
  13431. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  13432. {
  13433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  13434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  13435. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13436. {
  13437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13438. }
  13439. else
  13440. {
  13441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13442. }
  13443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  13444. isKnowKey = TRUE;
  13445. }
  13446. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  13447. {
  13448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  13449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  13450. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13451. {
  13452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  13453. }
  13454. else
  13455. {
  13456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  13457. }
  13458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  13459. isKnowKey = TRUE;
  13460. }
  13461. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  13462. {
  13463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  13464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  13465. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13466. {
  13467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13468. }
  13469. else
  13470. {
  13471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13472. }
  13473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  13474. isKnowKey = TRUE;
  13475. }
  13476. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  13477. {
  13478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  13479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  13480. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13481. {
  13482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  13483. }
  13484. else
  13485. {
  13486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  13487. }
  13488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  13489. isKnowKey = TRUE;
  13490. }
  13491. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  13492. {
  13493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  13494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  13495. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13496. {
  13497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  13498. }
  13499. else
  13500. {
  13501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  13502. }
  13503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  13504. isKnowKey = TRUE;
  13505. }
  13506. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  13507. {
  13508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  13509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  13510. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13511. {
  13512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  13513. }
  13514. else
  13515. {
  13516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  13517. }
  13518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  13519. isKnowKey = TRUE;
  13520. }
  13521. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  13522. {
  13523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  13524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  13525. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13526. {
  13527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  13528. }
  13529. else
  13530. {
  13531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  13532. }
  13533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  13534. isKnowKey = TRUE;
  13535. }
  13536. if(isEmpty || strcmp(keyReq, "QueueOffLineMeterValues") == 0 )
  13537. {
  13538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineMeterValues].Item, "QueueOffLineMeterValues");
  13539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Key, "QueueOffLineMeterValues");
  13540. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  13541. {
  13542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "0"/*"FALSE"*/);
  13543. }
  13544. else
  13545. {
  13546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].ReadOnly, "1"/*"TRUE"*/);
  13547. }
  13548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineMeterValues].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData );
  13549. isKnowKey = TRUE;
  13550. }
  13551. /*
  13552. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  13553. {
  13554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  13555. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  13556. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  13557. {
  13558. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  13559. }
  13560. else
  13561. {
  13562. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  13563. }
  13564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  13565. isKnowKey = TRUE;
  13566. }*/
  13567. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  13568. {
  13569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  13570. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  13571. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13572. {
  13573. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  13574. }
  13575. else
  13576. {
  13577. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  13578. }
  13579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  13580. isKnowKey = TRUE;
  13581. }
  13582. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  13583. {
  13584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  13585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  13586. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  13587. {
  13588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  13589. }
  13590. else
  13591. {
  13592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  13593. }
  13594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  13595. isKnowKey = TRUE;
  13596. }
  13597. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  13598. {
  13599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  13600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  13601. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13602. {
  13603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  13604. }
  13605. else
  13606. {
  13607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  13608. }
  13609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  13610. isKnowKey = TRUE;
  13611. }
  13612. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  13613. {
  13614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  13615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  13616. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13617. {
  13618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  13619. }
  13620. else
  13621. {
  13622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  13623. }
  13624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  13625. isKnowKey = TRUE;
  13626. }
  13627. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  13628. {
  13629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  13630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  13631. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  13632. {
  13633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  13634. }
  13635. else
  13636. {
  13637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13638. }
  13639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13640. isKnowKey = TRUE;
  13641. }
  13642. #if 1
  13643. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13644. {
  13645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13647. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13648. {
  13649. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13650. }
  13651. else
  13652. {
  13653. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13654. }
  13655. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13656. isKnowKey = TRUE;
  13657. }
  13658. #endif
  13659. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13660. {
  13661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13663. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13664. {
  13665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13666. }
  13667. else
  13668. {
  13669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13670. }
  13671. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13672. isKnowKey = TRUE;
  13673. }
  13674. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13675. {
  13676. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13678. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13679. {
  13680. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13681. }
  13682. else
  13683. {
  13684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13685. }
  13686. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13687. isKnowKey = TRUE;
  13688. }
  13689. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13690. {
  13691. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13693. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13694. {
  13695. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13696. }
  13697. else
  13698. {
  13699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13700. }
  13701. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13702. isKnowKey = TRUE;
  13703. }
  13704. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13705. {
  13706. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13708. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13709. {
  13710. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13711. }
  13712. else
  13713. {
  13714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13715. }
  13716. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13717. isKnowKey = TRUE;
  13718. }
  13719. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13720. {
  13721. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13723. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13724. {
  13725. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13726. }
  13727. else
  13728. {
  13729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13730. }
  13731. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13732. isKnowKey = TRUE;
  13733. }
  13734. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13735. {
  13736. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13738. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13739. {
  13740. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13741. }
  13742. else
  13743. {
  13744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13745. }
  13746. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13747. isKnowKey = TRUE;
  13748. }
  13749. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13750. {
  13751. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13753. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13754. {
  13755. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13756. }
  13757. else
  13758. {
  13759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13760. }
  13761. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13762. isKnowKey = TRUE;
  13763. }
  13764. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13765. {
  13766. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13768. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13769. {
  13770. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13771. }
  13772. else
  13773. {
  13774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13775. }
  13776. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13777. isKnowKey = TRUE;
  13778. }
  13779. //=========================================================
  13780. if(!isEmpty && !isKnowKey)
  13781. {
  13782. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13783. strcpy(unknownkey[UnknownKeynum], keyReq);
  13784. UnknownKeynum = UnknownKeynum + 1;
  13785. }
  13786. }
  13787. void processUnkownKey(void)
  13788. {
  13789. DEBUG_INFO("processUnkownKey...\n");
  13790. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13791. for(int index=0; index < UnknownKeynum; index++)
  13792. {
  13793. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13794. {
  13795. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13796. }
  13797. }
  13798. }
  13799. int setKeyValue(char *key, char *value)
  13800. {
  13801. int isSuccess = NotSupported;
  13802. int check_ascii=0;
  13803. char str[256]={0};
  13804. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13805. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13806. {
  13807. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13808. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13809. {
  13810. strcpy(str, (const char*)value);
  13811. for(int i = 0; str[i]; i++){
  13812. str[i] = tolower(str[i]);
  13813. }
  13814. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13815. isSuccess = ConfigurationStatus_Accepted;
  13816. }
  13817. else
  13818. {
  13819. isSuccess = ConfigurationStatus_Rejected;
  13820. }
  13821. }
  13822. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13823. {
  13824. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13825. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13826. {
  13827. strcpy(str, (const char*)value);
  13828. for(int i = 0; str[i]; i++){
  13829. str[i] = tolower(str[i]);
  13830. }
  13831. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13832. isSuccess = ConfigurationStatus_Accepted;
  13833. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13834. }
  13835. else
  13836. {
  13837. isSuccess = ConfigurationStatus_Rejected;
  13838. }
  13839. }
  13840. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13841. {
  13842. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13843. {
  13844. strcpy(str, (const char*)value);
  13845. for(int i = 0; str[i]; i++)
  13846. {
  13847. str[i] = tolower(str[i]);
  13848. }
  13849. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13850. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13851. isSuccess = ConfigurationStatus_Accepted;
  13852. }
  13853. else
  13854. {
  13855. isSuccess = ConfigurationStatus_Rejected;
  13856. }
  13857. }
  13858. if(strcmp(key, "BlinkRepeat") == 0)
  13859. {
  13860. //Charger.BlinkRepeat = Integer.parseInt(value);
  13861. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13862. {
  13863. check_ascii = value[0];
  13864. if( (check_ascii < 48) || (check_ascii > 57) )
  13865. {
  13866. isSuccess = ConfigurationStatus_Rejected;
  13867. }
  13868. else
  13869. {
  13870. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13871. isSuccess = ConfigurationStatus_Accepted;
  13872. }
  13873. }
  13874. else
  13875. {
  13876. isSuccess = ConfigurationStatus_Rejected;
  13877. }
  13878. }
  13879. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13880. {
  13881. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13882. {
  13883. check_ascii = value[0];
  13884. if( (check_ascii < 48) || (check_ascii > 57) )
  13885. {
  13886. isSuccess = ConfigurationStatus_Rejected;
  13887. }
  13888. else
  13889. {
  13890. if((atoi(value) == 0) || (atoi(value) >= 10))
  13891. {
  13892. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13894. isSuccess = ConfigurationStatus_Accepted;
  13895. }
  13896. else
  13897. isSuccess = ConfigurationStatus_Rejected;
  13898. }
  13899. }
  13900. else
  13901. {
  13902. isSuccess = ConfigurationStatus_Rejected;
  13903. }
  13904. }
  13905. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13906. {
  13907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13908. {
  13909. check_ascii = value[0];
  13910. if( (check_ascii < 48) || (check_ascii > 57) )
  13911. {
  13912. isSuccess = ConfigurationStatus_Rejected;
  13913. }
  13914. else
  13915. {
  13916. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13917. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13918. isSuccess = ConfigurationStatus_Accepted;
  13919. }
  13920. }
  13921. else
  13922. {
  13923. isSuccess = ConfigurationStatus_Rejected;
  13924. }
  13925. }
  13926. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13927. {
  13928. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13929. {
  13930. check_ascii = value[0];
  13931. if( (check_ascii < 48) || (check_ascii > 57) )
  13932. {
  13933. isSuccess = ConfigurationStatus_Rejected;
  13934. }
  13935. else
  13936. {
  13937. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13938. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13939. isSuccess = ConfigurationStatus_Accepted;
  13940. }
  13941. }
  13942. else
  13943. {
  13944. isSuccess = ConfigurationStatus_Rejected;
  13945. }
  13946. }
  13947. if(strcmp(key, "HeartbeatInterval") == 0)
  13948. {
  13949. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13950. {
  13951. check_ascii = value[0];
  13952. if( (check_ascii < 48) || (check_ascii > 57) )
  13953. {
  13954. isSuccess = ConfigurationStatus_Rejected;
  13955. }
  13956. else
  13957. {
  13958. if((atoi(value) == 0) || (atoi(value) >= 10))
  13959. {
  13960. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13961. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13962. HeartBeatWaitTime = atoi(value);
  13963. isSuccess = ConfigurationStatus_Accepted;
  13964. }
  13965. else
  13966. {
  13967. isSuccess = ConfigurationStatus_Rejected;
  13968. }
  13969. }
  13970. }
  13971. else
  13972. {
  13973. isSuccess = ConfigurationStatus_Rejected;
  13974. }
  13975. }
  13976. if(strcmp(key, "LightIntensity") == 0)
  13977. {
  13978. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13979. {
  13980. check_ascii = value[0];
  13981. if( (check_ascii < 48) || (check_ascii > 57) )
  13982. {
  13983. isSuccess = ConfigurationStatus_Rejected;
  13984. }
  13985. else
  13986. {
  13987. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13988. isSuccess = ConfigurationStatus_Accepted;
  13989. }
  13990. }
  13991. else
  13992. {
  13993. isSuccess = ConfigurationStatus_Rejected;
  13994. }
  13995. }
  13996. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13997. {
  13998. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13999. {
  14000. strcpy(str, (const char*)value);
  14001. for(int i = 0; str[i]; i++)
  14002. {
  14003. str[i] = tolower(str[i]);
  14004. }
  14005. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14006. isSuccess = ConfigurationStatus_Accepted;
  14007. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  14008. }
  14009. else
  14010. {
  14011. isSuccess = ConfigurationStatus_Rejected;
  14012. }
  14013. }
  14014. if(strcmp(key, "LocalPreAuthorize") == 0)
  14015. {
  14016. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  14017. {
  14018. strcpy(str, (const char*)value);
  14019. for(int i = 0; str[i]; i++)
  14020. {
  14021. str[i] = tolower(str[i]);
  14022. }
  14023. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14024. isSuccess = ConfigurationStatus_Accepted;
  14025. }
  14026. else
  14027. {
  14028. isSuccess = ConfigurationStatus_Rejected;
  14029. }
  14030. }
  14031. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  14032. {
  14033. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  14034. {
  14035. check_ascii = value[0];
  14036. if( (check_ascii < 48) || (check_ascii > 57) )
  14037. {
  14038. isSuccess = ConfigurationStatus_Rejected;
  14039. }
  14040. else
  14041. {
  14042. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  14043. isSuccess = ConfigurationStatus_Accepted;
  14044. }
  14045. }
  14046. else
  14047. {
  14048. isSuccess = ConfigurationStatus_Rejected;
  14049. }
  14050. }
  14051. if(strcmp(key, "MeterValuesAlignedData") == 0)
  14052. {
  14053. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  14054. {
  14055. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  14056. isSuccess = ConfigurationStatus_Accepted;
  14057. }
  14058. else
  14059. {
  14060. isSuccess = ConfigurationStatus_Rejected;
  14061. }
  14062. }
  14063. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  14064. {
  14065. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  14066. {
  14067. check_ascii = value[0];
  14068. if( (check_ascii < 48) || (check_ascii > 57) )
  14069. {
  14070. isSuccess = ConfigurationStatus_Rejected;
  14071. }
  14072. else
  14073. {
  14074. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14075. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  14076. isSuccess = ConfigurationStatus_Accepted;
  14077. }
  14078. }
  14079. else
  14080. {
  14081. isSuccess = ConfigurationStatus_Rejected;
  14082. }
  14083. }
  14084. if(strcmp(key, "MeterValuesSampledData") == 0 )
  14085. {
  14086. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  14087. {
  14088. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  14089. isSuccess = ConfigurationStatus_Accepted;
  14090. }
  14091. else
  14092. {
  14093. isSuccess = ConfigurationStatus_Rejected;
  14094. }
  14095. }
  14096. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  14097. {
  14098. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  14099. {
  14100. check_ascii = value[0];
  14101. if( (check_ascii < 48) || (check_ascii > 57) )
  14102. {
  14103. isSuccess = ConfigurationStatus_Rejected;
  14104. }
  14105. else
  14106. {
  14107. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14108. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  14109. isSuccess = ConfigurationStatus_Accepted;
  14110. }
  14111. }
  14112. else
  14113. {
  14114. isSuccess = ConfigurationStatus_Rejected;
  14115. }
  14116. }
  14117. if(strcmp(key, "MeterValueSampleInterval") == 0)
  14118. {
  14119. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  14120. {
  14121. check_ascii = value[0];
  14122. if( (check_ascii < 48) || (check_ascii > 57) )
  14123. {
  14124. isSuccess = ConfigurationStatus_Rejected;
  14125. }
  14126. else
  14127. {
  14128. if((atoi(value) == 0) || (atoi(value) >= 10))
  14129. {
  14130. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  14131. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  14132. isSuccess = ConfigurationStatus_Accepted;
  14133. }
  14134. else
  14135. {
  14136. isSuccess = ConfigurationStatus_Rejected;
  14137. }
  14138. }
  14139. }
  14140. else
  14141. {
  14142. isSuccess = ConfigurationStatus_Rejected;
  14143. }
  14144. }
  14145. if(strcmp(key, "MinimumStatusDuration") == 0)
  14146. {
  14147. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  14148. {
  14149. check_ascii = value[0];
  14150. if( (check_ascii < 48) || (check_ascii > 57) )
  14151. {
  14152. isSuccess = ConfigurationStatus_Rejected;
  14153. }
  14154. else
  14155. {
  14156. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  14157. {
  14158. isSuccess = ConfigurationStatus_Rejected;
  14159. }
  14160. else
  14161. {
  14162. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  14163. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  14164. server_cycle_Status = atoi(value); //StatusNotification Cycle
  14165. isSuccess = ConfigurationStatus_Accepted;
  14166. }
  14167. }
  14168. }
  14169. else
  14170. {
  14171. isSuccess = ConfigurationStatus_Rejected;
  14172. }
  14173. }
  14174. if(strcmp(key, "NumberOfConnectors") == 0)
  14175. {
  14176. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  14177. {
  14178. check_ascii = value[0];
  14179. if( (check_ascii < 48) || (check_ascii > 57) )
  14180. {
  14181. isSuccess = ConfigurationStatus_Rejected;
  14182. }
  14183. else
  14184. {
  14185. //Charger.ResetRetries = Integer.parseInt(value);
  14186. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  14187. isSuccess = ConfigurationStatus_Accepted;
  14188. }
  14189. }
  14190. else
  14191. {
  14192. isSuccess = ConfigurationStatus_Rejected;
  14193. }
  14194. }
  14195. if(strcmp(key, "ResetRetries") == 0)
  14196. {
  14197. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  14198. {
  14199. check_ascii = value[0];
  14200. if( (check_ascii < 48) || (check_ascii > 57) )
  14201. {
  14202. isSuccess = ConfigurationStatus_Rejected;
  14203. }
  14204. else
  14205. {
  14206. //Charger.ResetRetries = Integer.parseInt(value);
  14207. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  14208. isSuccess = ConfigurationStatus_Accepted;
  14209. }
  14210. }
  14211. else
  14212. {
  14213. isSuccess = ConfigurationStatus_Rejected;
  14214. }
  14215. }
  14216. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  14217. {
  14218. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  14219. {
  14220. strcpy(str, (const char*)value);
  14221. for(int i = 0; str[i]; i++)
  14222. {
  14223. str[i] = tolower(str[i]);
  14224. }
  14225. if(strcmp(str, "notapplicable")== 0)
  14226. {
  14227. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  14228. isSuccess = ConfigurationStatus_Accepted;
  14229. }
  14230. else if(strcmp(str, "unknown")== 0)
  14231. {
  14232. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  14233. isSuccess = ConfigurationStatus_Accepted;
  14234. }
  14235. else if(strcmp(str, "rst")== 0)
  14236. {
  14237. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  14238. isSuccess = ConfigurationStatus_Accepted;
  14239. }
  14240. else if(strcmp(str, "rts")== 0)
  14241. {
  14242. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  14243. isSuccess = ConfigurationStatus_Accepted;
  14244. }
  14245. else if(strcmp(str, "srt")== 0)
  14246. {
  14247. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  14248. isSuccess = ConfigurationStatus_Accepted;
  14249. }
  14250. else if(strcmp(str, "str")== 0)
  14251. {
  14252. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  14253. isSuccess = ConfigurationStatus_Accepted;
  14254. }
  14255. else if(strcmp(str, "trs")== 0)
  14256. {
  14257. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  14258. isSuccess = ConfigurationStatus_Accepted;
  14259. }
  14260. else if(strcmp(str, "tsr")== 0)
  14261. {
  14262. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  14263. isSuccess = ConfigurationStatus_Accepted;
  14264. }
  14265. else
  14266. {
  14267. isSuccess = ConfigurationStatus_Rejected;
  14268. }
  14269. }
  14270. else
  14271. {
  14272. isSuccess = ConfigurationStatus_Rejected;
  14273. }
  14274. }
  14275. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  14276. {
  14277. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  14278. {
  14279. check_ascii = value[0];
  14280. if( (check_ascii < 48) || (check_ascii > 57) )
  14281. {
  14282. isSuccess = ConfigurationStatus_Rejected;
  14283. }
  14284. else
  14285. {
  14286. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  14287. isSuccess = ConfigurationStatus_Accepted;
  14288. }
  14289. }
  14290. else
  14291. {
  14292. isSuccess = ConfigurationStatus_Rejected;
  14293. }
  14294. }
  14295. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  14296. {
  14297. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  14298. {
  14299. strcpy(str, (const char*)value);
  14300. for(int i = 0; str[i]; i++)
  14301. {
  14302. str[i] = tolower(str[i]);
  14303. }
  14304. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14305. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14306. isSuccess = ConfigurationStatus_Accepted;
  14307. }
  14308. else
  14309. {
  14310. isSuccess = ConfigurationStatus_Rejected;
  14311. }
  14312. }
  14313. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  14314. {
  14315. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  14316. {
  14317. strcpy(str, (const char*)value);
  14318. for(int i = 0; str[i]; i++)
  14319. {
  14320. str[i] = tolower(str[i]);
  14321. }
  14322. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  14323. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14324. isSuccess = ConfigurationStatus_Accepted;
  14325. }
  14326. else
  14327. {
  14328. isSuccess = ConfigurationStatus_Rejected;
  14329. }
  14330. }
  14331. if(strcmp(key, "StopTxnAlignedData") == 0)
  14332. {
  14333. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  14334. {
  14335. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  14336. isSuccess = ConfigurationStatus_Accepted;
  14337. }
  14338. else
  14339. {
  14340. isSuccess = ConfigurationStatus_Rejected;
  14341. }
  14342. }
  14343. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  14344. {
  14345. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  14346. {
  14347. check_ascii = value[0];
  14348. if( (check_ascii < 48) || (check_ascii > 57) )
  14349. {
  14350. isSuccess = ConfigurationStatus_Rejected;
  14351. }
  14352. else
  14353. {
  14354. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  14355. isSuccess = ConfigurationStatus_Accepted;
  14356. }
  14357. }
  14358. else
  14359. {
  14360. isSuccess = ConfigurationStatus_Rejected;
  14361. }
  14362. }
  14363. if(strcmp(key, "StopTxnSampledData") == 0)
  14364. {
  14365. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  14366. {
  14367. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  14368. isSuccess = ConfigurationStatus_Accepted;
  14369. }
  14370. else
  14371. {
  14372. isSuccess = ConfigurationStatus_Rejected;
  14373. }
  14374. }
  14375. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  14376. {
  14377. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  14378. {
  14379. check_ascii = value[0];
  14380. if( (check_ascii < 48) || (check_ascii > 57) )
  14381. {
  14382. isSuccess = ConfigurationStatus_Rejected;
  14383. }
  14384. else
  14385. {
  14386. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  14387. isSuccess = ConfigurationStatus_Accepted;
  14388. }
  14389. }
  14390. else
  14391. {
  14392. isSuccess = ConfigurationStatus_Rejected;
  14393. }
  14394. }
  14395. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  14396. {
  14397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  14398. {
  14399. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  14400. isSuccess = ConfigurationStatus_Accepted;
  14401. }
  14402. else
  14403. {
  14404. isSuccess = ConfigurationStatus_Rejected;
  14405. }
  14406. }
  14407. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  14408. {
  14409. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  14410. {
  14411. check_ascii = value[0];
  14412. if( (check_ascii < 48) || (check_ascii > 57) )
  14413. {
  14414. isSuccess = ConfigurationStatus_Rejected;
  14415. }
  14416. else
  14417. {
  14418. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  14419. isSuccess = ConfigurationStatus_Accepted;
  14420. }
  14421. }
  14422. else
  14423. {
  14424. isSuccess = ConfigurationStatus_Rejected;
  14425. }
  14426. }
  14427. if(strcmp(key, "TransactionMessageAttempts") == 0)
  14428. {
  14429. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  14430. {
  14431. check_ascii = value[0];
  14432. if( (check_ascii < 48) || (check_ascii > 57) )
  14433. {
  14434. isSuccess = ConfigurationStatus_Rejected;
  14435. }
  14436. else
  14437. {
  14438. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  14439. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  14440. TransactionMessageAttemptsValue = atoi(value);
  14441. isSuccess = ConfigurationStatus_Accepted;
  14442. }
  14443. }
  14444. else
  14445. {
  14446. isSuccess = ConfigurationStatus_Rejected;
  14447. }
  14448. }
  14449. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  14450. {
  14451. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  14452. {
  14453. check_ascii = value[0];
  14454. if( (check_ascii < 48) || (check_ascii > 57) )
  14455. {
  14456. isSuccess = ConfigurationStatus_Rejected;
  14457. }
  14458. else
  14459. {
  14460. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  14461. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  14462. TransactionMessageRetryIntervalValue = atoi(value);
  14463. isSuccess = ConfigurationStatus_Accepted;
  14464. }
  14465. }
  14466. else
  14467. {
  14468. isSuccess = ConfigurationStatus_Rejected;
  14469. }
  14470. }
  14471. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  14472. {
  14473. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  14474. {
  14475. strcpy(str, (const char*)value);
  14476. for(int i = 0; str[i]; i++)
  14477. {
  14478. str[i] = tolower(str[i]);
  14479. }
  14480. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  14481. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14482. isSuccess = ConfigurationStatus_Accepted;
  14483. }
  14484. else
  14485. {
  14486. isSuccess = ConfigurationStatus_Rejected;
  14487. }
  14488. }
  14489. if(strcmp(key, "WebSocketPingInterval") == 0)
  14490. {
  14491. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  14492. {
  14493. check_ascii = value[0];
  14494. if( (check_ascii < 48) || (check_ascii > 57) )
  14495. {
  14496. isSuccess = ConfigurationStatus_Rejected;
  14497. }
  14498. else
  14499. {
  14500. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  14501. isSuccess = ConfigurationStatus_Accepted;
  14502. }
  14503. }
  14504. else
  14505. {
  14506. isSuccess = ConfigurationStatus_Rejected;
  14507. }
  14508. }
  14509. if(strcmp(key, "QueueOffLineMeterValues") == 0)
  14510. {
  14511. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemAccessibility == 1)
  14512. {
  14513. strcpy(str, (const char*)value);
  14514. for(int i = 0; str[i]; i++)
  14515. {
  14516. str[i] = tolower(str[i]);
  14517. }
  14518. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineMeterValues].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14519. isSuccess = ConfigurationStatus_Accepted;
  14520. }
  14521. else
  14522. {
  14523. isSuccess = ConfigurationStatus_Rejected;
  14524. }
  14525. }
  14526. if(strcmp(key, "AuthorizationKey") == 0)
  14527. {
  14528. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  14529. {
  14530. strcpy(str, (const char*)value);
  14531. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  14532. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14533. isSuccess = ConfigurationStatus_Accepted;
  14534. }
  14535. else
  14536. {
  14537. isSuccess = ConfigurationStatus_Rejected;
  14538. }
  14539. }
  14540. if(strcmp(key, "SecurityProfile") == 0)
  14541. {
  14542. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  14543. {
  14544. check_ascii = value[0];
  14545. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  14546. {
  14547. isSuccess = ConfigurationStatus_Rejected;
  14548. }
  14549. else if(check_ascii == 0x33)
  14550. {
  14551. isSuccess = NotSupported;
  14552. }
  14553. else
  14554. {
  14555. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  14556. {
  14557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  14558. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  14559. isSuccess = ConfigurationStatus_Accepted;
  14560. }
  14561. else
  14562. isSuccess = ConfigurationStatus_Rejected;
  14563. }
  14564. }
  14565. else
  14566. {
  14567. isSuccess = ConfigurationStatus_Rejected;
  14568. }
  14569. }
  14570. if(strcmp(key, "DefaultPrice") == 0)
  14571. {
  14572. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  14573. {
  14574. strcpy(str, (const char*)value);
  14575. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  14576. isSuccess = ConfigurationStatus_Accepted;
  14577. }
  14578. else
  14579. {
  14580. isSuccess = ConfigurationStatus_Rejected;
  14581. }
  14582. }
  14583. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  14584. {
  14585. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  14586. {
  14587. strcpy(str, (const char*)value);
  14588. for(int i = 0; str[i]; i++)
  14589. {
  14590. str[i] = tolower(str[i]);
  14591. }
  14592. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14593. isSuccess = ConfigurationStatus_Accepted;
  14594. }
  14595. else
  14596. {
  14597. isSuccess = ConfigurationStatus_Rejected;
  14598. }
  14599. }
  14600. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  14601. {
  14602. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  14603. {
  14604. strcpy(str, (const char*)value);
  14605. for(int i = 0; str[i]; i++)
  14606. {
  14607. str[i] = tolower(str[i]);
  14608. }
  14609. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14610. isSuccess = ConfigurationStatus_Accepted;
  14611. }
  14612. else
  14613. {
  14614. isSuccess = ConfigurationStatus_Rejected;
  14615. }
  14616. }
  14617. #if 0
  14618. //For OCPP Test Case
  14619. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  14620. {
  14621. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14622. {
  14623. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  14624. isSuccess = ConfigurationStatus_Accepted;
  14625. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14626. }
  14627. else
  14628. {
  14629. isSuccess = ConfigurationStatus_Rejected;
  14630. }
  14631. }
  14632. #endif
  14633. #if 1
  14634. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14635. {
  14636. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14637. {
  14638. strcpy(str, (const char*)value);
  14639. for(int i = 0; str[i]; i++)
  14640. {
  14641. str[i] = tolower(str[i]);
  14642. }
  14643. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14644. isSuccess = ConfigurationStatus_Accepted;
  14645. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14646. }
  14647. else
  14648. {
  14649. isSuccess = ConfigurationStatus_Rejected;
  14650. }
  14651. }
  14652. #endif
  14653. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14654. {
  14655. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14656. {
  14657. check_ascii = value[0];
  14658. if( (check_ascii < 48) || (check_ascii > 57) )
  14659. {
  14660. isSuccess = ConfigurationStatus_Rejected;
  14661. }
  14662. else
  14663. {
  14664. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14665. isSuccess = ConfigurationStatus_Accepted;
  14666. }
  14667. }
  14668. else
  14669. {
  14670. isSuccess = ConfigurationStatus_Rejected;
  14671. }
  14672. }
  14673. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14674. {
  14675. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14676. {
  14677. check_ascii = value[0];
  14678. if( (check_ascii < 48) || (check_ascii > 57) )
  14679. {
  14680. isSuccess = ConfigurationStatus_Rejected;
  14681. }
  14682. else
  14683. {
  14684. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14685. isSuccess = ConfigurationStatus_Accepted;
  14686. }
  14687. }
  14688. else
  14689. {
  14690. isSuccess = ConfigurationStatus_Rejected;
  14691. }
  14692. }
  14693. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14694. {
  14695. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14696. {
  14697. strcpy(str, (const char*)value);
  14698. for(int i = 0; str[i]; i++)
  14699. {
  14700. str[i] = tolower(str[i]);
  14701. }
  14702. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14703. isSuccess = ConfigurationStatus_Accepted;
  14704. }
  14705. else
  14706. {
  14707. isSuccess = ConfigurationStatus_Rejected;
  14708. }
  14709. }
  14710. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14711. {
  14712. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14713. {
  14714. check_ascii = value[0];
  14715. if( (check_ascii < 48) || (check_ascii > 57) )
  14716. {
  14717. isSuccess = ConfigurationStatus_Rejected;
  14718. }
  14719. else
  14720. {
  14721. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14722. isSuccess = ConfigurationStatus_Accepted;
  14723. }
  14724. }
  14725. else
  14726. {
  14727. isSuccess = ConfigurationStatus_Rejected;
  14728. }
  14729. }
  14730. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14731. {
  14732. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14733. {
  14734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14735. isSuccess = ConfigurationStatus_Accepted;
  14736. }
  14737. else
  14738. {
  14739. isSuccess = ConfigurationStatus_Rejected;
  14740. }
  14741. }
  14742. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14743. {
  14744. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14745. {
  14746. check_ascii = value[0];
  14747. if( (check_ascii < 48) || (check_ascii > 57) )
  14748. {
  14749. isSuccess = ConfigurationStatus_Rejected;
  14750. }
  14751. else
  14752. {
  14753. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14754. isSuccess = ConfigurationStatus_Accepted;
  14755. }
  14756. }
  14757. else
  14758. {
  14759. isSuccess = ConfigurationStatus_Rejected;
  14760. }
  14761. }
  14762. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14763. {
  14764. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14765. {
  14766. strcpy(str, (const char*)value);
  14767. for(int i = 0; str[i]; i++)
  14768. {
  14769. str[i] = tolower(str[i]);
  14770. }
  14771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14772. isSuccess = ConfigurationStatus_Accepted;
  14773. }
  14774. else
  14775. {
  14776. isSuccess = ConfigurationStatus_Rejected;
  14777. }
  14778. }
  14779. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14780. {
  14781. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14782. {
  14783. check_ascii = value[0];
  14784. if( (check_ascii < 48) || (check_ascii > 57) )
  14785. {
  14786. isSuccess = ConfigurationStatus_Rejected;
  14787. }
  14788. else
  14789. {
  14790. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14791. isSuccess = ConfigurationStatus_Accepted;
  14792. }
  14793. }
  14794. else
  14795. {
  14796. isSuccess = ConfigurationStatus_Rejected;
  14797. }
  14798. }
  14799. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14800. return isSuccess;
  14801. }
  14802. int TransactionMessageAttemptsGet(void)
  14803. {
  14804. return TransactionMessageAttemptsValue;
  14805. }
  14806. int FirstHeartBeatResponse(void)
  14807. {
  14808. return FirstHeartBeat;
  14809. }
  14810. int TransactionMessageRetryIntervalGet(void)
  14811. {
  14812. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14813. }
  14814. int ReadHttpStatus(int sock)
  14815. {
  14816. //char c;
  14817. char buff[1024]="",*ptr=buff+1;
  14818. int bytes_received, status;
  14819. DEBUG_INFO("Begin Response ..\n");
  14820. while((bytes_received = recv(sock, ptr, 1, 0))){
  14821. if(bytes_received==-1){
  14822. perror("ReadHttpStatus");
  14823. exit(1);
  14824. }
  14825. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14826. ptr++;
  14827. }
  14828. *ptr=0;
  14829. ptr=buff+1;
  14830. sscanf(ptr,"%*s %d ", &status);
  14831. DEBUG_INFO("%s\n",ptr);
  14832. DEBUG_INFO("status=%d\n",status);
  14833. DEBUG_INFO("End Response ..\n");
  14834. return (bytes_received>0)?status:0;
  14835. }
  14836. //the only filed that it parsed is 'Content-Length'
  14837. int ParseHeader(int sock)
  14838. {
  14839. //char c;
  14840. char buff[1024]="",*ptr=buff+4;
  14841. int bytes_received;
  14842. DEBUG_INFO("Begin HEADER ..\n");
  14843. while((bytes_received = recv(sock, ptr, 1, 0))){
  14844. if(bytes_received==-1){
  14845. perror("Parse Header");
  14846. exit(1);
  14847. }
  14848. if(
  14849. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14850. (ptr[-1]=='\r') && (*ptr=='\n' )
  14851. ) break;
  14852. ptr++;
  14853. }
  14854. *ptr=0;
  14855. ptr=buff+4;
  14856. //printf("%s",ptr);
  14857. if(bytes_received){
  14858. ptr=strstr(ptr,"Content-Length:");
  14859. if(ptr){
  14860. sscanf(ptr,"%*s %d",&bytes_received);
  14861. }else
  14862. bytes_received=-1; //unknown size
  14863. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14864. }
  14865. DEBUG_INFO("End HEADER ..\n");
  14866. return bytes_received ;
  14867. }
  14868. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14869. {
  14870. int result = TRUE;
  14871. char rmFileCmd[100]={0};
  14872. char FilePath[100]={0};
  14873. char ftpbuf[200];
  14874. int systemresult;
  14875. sprintf(FilePath,"/mnt/%s",filename);
  14876. system("ping 8.8.8.8 &");
  14877. if((access(FilePath,F_OK))!=-1)
  14878. {
  14879. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14880. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14881. system(rmFileCmd);
  14882. }
  14883. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14884. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  14885. DEBUG_INFO("Download command: %s\n",ftpbuf);
  14886. systemresult = system(ftpbuf);
  14887. if(systemresult != 0)
  14888. {
  14889. DEBUG_INFO("http DownLoad error!\n");
  14890. result = FALSE;
  14891. }
  14892. system("pkill ping");
  14893. return result;
  14894. }
  14895. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14896. {
  14897. int result = TRUE;
  14898. char rmFileCmd[100]={0};
  14899. char FilePath[100]={0};
  14900. char ftpbuf[200];
  14901. int systemresult;
  14902. sprintf(FilePath,"/mnt/%s",filename);
  14903. system("ping 8.8.8.8 &");
  14904. if((access(FilePath,F_OK))!=-1)
  14905. {
  14906. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14907. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14908. system(rmFileCmd);
  14909. }
  14910. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14911. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14912. DEBUG_INFO("Download command: %s\n",ftpbuf);
  14913. systemresult = system(ftpbuf);
  14914. if(systemresult != 0)
  14915. {
  14916. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  14917. DEBUG_INFO("Download command: %s\n",ftpbuf);
  14918. systemresult = system(ftpbuf);
  14919. if(systemresult != 0)
  14920. {
  14921. DEBUG_WARN("wget error!\n");
  14922. result = FALSE;
  14923. }
  14924. }
  14925. system("pkill ping");
  14926. return result;
  14927. }
  14928. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14929. {
  14930. char rmFileCmd[100]={0};
  14931. char FilePath[100]={0};
  14932. char buf[512];
  14933. int systemresult = 0;
  14934. //DEBUG_INFO("filename=%s\n",filename);
  14935. //DEBUG_INFO("url=%s\n",url);
  14936. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14937. if((access(FilePath,F_OK))!=-1)
  14938. {
  14939. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14940. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14941. system(rmFileCmd);
  14942. }
  14943. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14944. if(fp == NULL)
  14945. {
  14946. DEBUG_INFO("log is NULL\n");
  14947. return FALSE;
  14948. }
  14949. else
  14950. {
  14951. fprintf(fp, "%s\n", url);
  14952. fprintf(fp, "%s\n", filename);
  14953. fclose(fp);
  14954. }
  14955. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14956. if(phpFP == NULL)
  14957. {
  14958. DEBUG_INFO("PHP upload fail.\n");
  14959. return FALSE;
  14960. }
  14961. else
  14962. {
  14963. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14964. {
  14965. if(strstr(buf, "result") != NULL)
  14966. {
  14967. sscanf(buf, "result: %d", &systemresult);
  14968. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14969. }
  14970. }
  14971. pclose(phpFP);
  14972. }
  14973. if(systemresult != 1)
  14974. {
  14975. DEBUG_INFO("HTTP upload error!\n");
  14976. return FALSE;
  14977. }
  14978. return TRUE;
  14979. }
  14980. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14981. {
  14982. struct hostent* server;
  14983. char *IPbuffer;
  14984. char ftpbuf[200];
  14985. int systemresult;
  14986. // To retrieve host information
  14987. server = gethostbyname(location);
  14988. // To convert an Internet network
  14989. // address into ASCII string
  14990. IPbuffer = inet_ntoa(*((struct in_addr*)
  14991. server->h_addr_list[0]));
  14992. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14993. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14994. /* format : ftpput -u username -p passwd IP target source*/
  14995. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14996. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14997. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14998. systemresult = system(ftpbuf);
  14999. DEBUG_INFO("systemresult=%d\n",systemresult);
  15000. if(systemresult != 0)
  15001. {
  15002. DEBUG_INFO("ftpput error!\n");
  15003. return FALSE;
  15004. }
  15005. return TRUE;
  15006. }
  15007. int GetOcppServerURL()
  15008. {
  15009. int result = FALSE;
  15010. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  15011. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  15012. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  15013. struct yuarel url;
  15014. char urlStr[512];
  15015. // OCPPPH only
  15016. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  15017. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  15018. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  15019. {
  15020. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  15021. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15022. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  15023. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  15024. if(yuarel_parse(&url, urlStr) != -1)
  15025. {
  15026. sprintf(OcppProtocol, "%s", url.scheme);
  15027. sprintf(OcppHost, "%s", url.host);
  15028. if(url.path == NULL)
  15029. OcppTempPath[0] = '\0';
  15030. else
  15031. sprintf(OcppTempPath, "%s", url.path);
  15032. if(url.port == 0)
  15033. {
  15034. if(strcmp(OcppProtocol, "wss") == 0)
  15035. OcppPort = 443;
  15036. else
  15037. OcppPort = 80;
  15038. }
  15039. else
  15040. OcppPort = url.port;
  15041. result = TRUE;
  15042. }
  15043. }
  15044. else
  15045. {
  15046. strcpy(OcppHost,"");
  15047. }
  15048. return result;
  15049. }
  15050. int GetOcppPath()
  15051. {
  15052. int result = FALSE;
  15053. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  15054. {
  15055. if(OcppTempPath == NULL)
  15056. {
  15057. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  15058. }
  15059. else
  15060. {
  15061. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  15062. }
  15063. result = TRUE;
  15064. goto End;
  15065. }
  15066. else
  15067. {
  15068. strcpy(OcppPath,"");
  15069. }
  15070. End:
  15071. return result;
  15072. }
  15073. int GetOcppPort()
  15074. {
  15075. return OcppPort;
  15076. }
  15077. int GetOcppConnStatus(void)
  15078. {
  15079. return ShmOCPP16DataPH->OcppConnStatus;
  15080. }
  15081. void SetOcppConnStatus(uint8_t status)
  15082. {
  15083. ShmOCPP16DataPH->OcppConnStatus = status;
  15084. }
  15085. int GetHeartBeatWithNOResponse(void)
  15086. {
  15087. return HeartBeatWithNOResponse;
  15088. }
  15089. void SetHeartBeatWithNOResponse(void)
  15090. {
  15091. HeartBeatWithNOResponse = 0;
  15092. }
  15093. void GetStartTransactionIdTag(int gun_index)
  15094. {
  15095. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  15096. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15097. }
  15098. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  15099. {
  15100. char ch;
  15101. FILE *fptr1;
  15102. int temptransactionId;
  15103. char str[100]={0};
  15104. temptransactionId = 0;
  15105. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  15106. {
  15107. DEBUG_INFO("IdTag is empty.\n");
  15108. return temptransactionId;
  15109. }
  15110. /*------ Read the file ----------------*/
  15111. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  15112. if (!fptr1)
  15113. {
  15114. DEBUG_INFO("QueueTransactionId file open error.\n");
  15115. //printf(" File not found or unable to open the input file!!\n");
  15116. return temptransactionId;
  15117. }
  15118. ch=fgetc(fptr1);
  15119. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  15120. rewind(fptr1);
  15121. if(ch!=EOF)
  15122. {
  15123. // printf("%c",ch);
  15124. while (fgets(str, 100, fptr1) != NULL)
  15125. {
  15126. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15127. if(str[0]=='\0')
  15128. {
  15129. break;
  15130. }
  15131. char *revbuf[8] = {0}; // Variable store string split
  15132. int num = 0;// Quantity after string split
  15133. DEBUG_INFO("Transaction queue data= %s\n", str);
  15134. splitstring(str,",",revbuf,&num); // String split
  15135. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  15136. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  15137. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  15138. DEBUG_INFO("------------------------------\n");
  15139. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  15140. {
  15141. if(isStopTransaction)
  15142. {
  15143. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  15144. {
  15145. temptransactionId = atoi(revbuf[2]);
  15146. //break;
  15147. }
  15148. }
  15149. else
  15150. {
  15151. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  15152. {
  15153. temptransactionId = atoi(revbuf[2]);
  15154. //break;
  15155. }
  15156. }
  15157. }
  15158. }
  15159. }
  15160. else
  15161. DEBUG_INFO("EOF\n");
  15162. fclose(fptr1);
  15163. /*------- End of reading ---------------*/
  15164. return temptransactionId;
  15165. }
  15166. void SetTransactionIdZero(int transactionId)
  15167. {
  15168. char ch;
  15169. FILE *fptr1, *fptr2;
  15170. int temptransactionId = 0;
  15171. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  15172. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  15173. if (!fptr1)
  15174. {
  15175. //printf(" File not found or unable to open the input file!!\n");
  15176. return ;
  15177. }
  15178. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  15179. if (!fptr2)
  15180. {
  15181. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  15182. fclose(fptr1);
  15183. return ;
  15184. }
  15185. ch=fgetc(fptr1);
  15186. rewind(fptr1);
  15187. if(ch!=EOF)
  15188. {
  15189. // copy all contents to the temporary file except the specific line
  15190. while (fgets(str, 100, fptr1) != NULL)
  15191. {
  15192. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15193. if(str[0]=='\0')
  15194. {
  15195. break;
  15196. }
  15197. char *revbuf[8] = {0};
  15198. int num = 0;
  15199. strcpy(strtemp, str);
  15200. splitstring(str,",",revbuf,&num);
  15201. if(revbuf[2][0] != '\0')
  15202. {
  15203. temptransactionId = atoi(revbuf[2]);
  15204. if(transactionId != temptransactionId)
  15205. {
  15206. fprintf(fptr2, "%s\n", strtemp);
  15207. }
  15208. }
  15209. }
  15210. }
  15211. fclose(fptr1);
  15212. fclose(fptr2);
  15213. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  15214. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  15215. /*------ Read the file ----------------*/
  15216. }
  15217. int InternetDisconnect(void)
  15218. {
  15219. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  15220. }
  15221. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15222. void storeTempStopTransaction(int gun_index)
  15223. {
  15224. char guid[37]={0};
  15225. int tempIndex = 0;
  15226. char TempStopTransaction[256];
  15227. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15228. DEBUG_INFO("storeTempStopTransaction...\n");
  15229. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  15230. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  15231. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  15232. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15233. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15234. {
  15235. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15236. {
  15237. tempIndex = ((gun_index==2) ? 1: 0);
  15238. }
  15239. else
  15240. {
  15241. tempIndex = gun_index;
  15242. }
  15243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15244. {
  15245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15246. {
  15247. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  15248. }
  15249. }// END OF CHAdeMO_QUANTITY
  15250. }
  15251. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15252. {
  15253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15254. {
  15255. tempIndex = ((gun_index==2) ? 1: 0);
  15256. }
  15257. else
  15258. {
  15259. tempIndex = gun_index;
  15260. }
  15261. for (int index = 0; index < CCS_QUANTITY; index++)
  15262. {
  15263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15264. {
  15265. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  15266. }
  15267. }// END OF CCS_QUANTITY
  15268. }
  15269. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15270. {
  15271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15272. {
  15273. tempIndex = ((gun_index==2) ? 1: 0);
  15274. }
  15275. else
  15276. {
  15277. tempIndex = gun_index;
  15278. }
  15279. for (int index = 0; index < GB_QUANTITY; index++)
  15280. {
  15281. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15282. {
  15283. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  15284. }
  15285. }// END OF GB_QUANTITY
  15286. }
  15287. else if(gunType[gun_index] == GUN_TYPE_DO)
  15288. {
  15289. tempIndex = gun_index;
  15290. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15291. {
  15292. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15293. {
  15294. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  15295. }
  15296. }
  15297. }
  15298. else
  15299. {
  15300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15301. {
  15302. tempIndex = 2;
  15303. }
  15304. else
  15305. {
  15306. tempIndex = gun_index;
  15307. }
  15308. for (int index = 0; index < AC_QUANTITY; index++)
  15309. {
  15310. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15311. {
  15312. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  15313. }
  15314. }// END OF AC_QUANTITY
  15315. }
  15316. //Stop Transaction Time
  15317. struct timeval tmnow;
  15318. struct tm *tm;
  15319. char buf[28];//, usec_buf[6];
  15320. gettimeofday(&tmnow, NULL);
  15321. time_t t;
  15322. t = time(NULL);
  15323. /*UTC time and date*/
  15324. tm = gmtime(&t);
  15325. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15326. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  15327. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  15328. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  15329. random_uuid(guid);
  15330. /***********************************transactionData******************************************************/
  15331. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  15332. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15333. //=================================
  15334. //1. Transaction_Begin
  15335. //=================================
  15336. //============================== Energy.Active.Import.Interval ===========================================
  15337. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15338. {
  15339. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  15340. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15341. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15342. 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*/]);
  15343. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15344. 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))
  15345. {
  15346. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15347. }
  15348. else
  15349. {
  15350. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15351. }
  15352. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15353. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15354. }
  15355. //=================================
  15356. //2. Transaction_End
  15357. //=================================
  15358. //2.1====================================== Current.Import L1 ==============================================
  15359. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15360. {
  15361. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15362. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15363. {
  15364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15365. {
  15366. tempIndex = ((gun_index==2) ? 1: 0);
  15367. }
  15368. else
  15369. {
  15370. tempIndex = gun_index;
  15371. }
  15372. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15373. {
  15374. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15375. {
  15376. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15377. }
  15378. }// End of for CHAdeMO_QUANTITY
  15379. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15380. }
  15381. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15382. {
  15383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15384. {
  15385. tempIndex = ((gun_index==2) ? 1: 0);
  15386. }
  15387. else
  15388. {
  15389. tempIndex = gun_index;
  15390. }
  15391. for (int index = 0; index < CCS_QUANTITY; index++)
  15392. {
  15393. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15394. {
  15395. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15396. }
  15397. }// End of for CCS_QUANTITY
  15398. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15399. }
  15400. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15401. {
  15402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15403. {
  15404. tempIndex = ((gun_index==2) ? 1: 0);
  15405. }
  15406. else
  15407. {
  15408. tempIndex = gun_index;
  15409. }
  15410. for (int index = 0; index < GB_QUANTITY; index++)
  15411. {
  15412. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15413. {
  15414. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15415. }
  15416. }// End of for GB_QUANTITY
  15417. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15418. }
  15419. else if(gunType[gun_index] == GUN_TYPE_DO)
  15420. {
  15421. tempIndex = gun_index;
  15422. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15423. {
  15424. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15425. {
  15426. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15427. }
  15428. }
  15429. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15430. }
  15431. else
  15432. {
  15433. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15434. {
  15435. tempIndex = 2;
  15436. }
  15437. else
  15438. {
  15439. tempIndex = gun_index;
  15440. }
  15441. for (int index = 0; index < AC_QUANTITY; index++)
  15442. {
  15443. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15444. {
  15445. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15446. }
  15447. }// End of for AC_QUANTITY
  15448. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15449. }
  15450. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15451. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15452. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15453. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15454. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15455. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15456. }
  15457. //2.2===================================== Energy.Active.Import.Interval ==========================================
  15458. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  15459. {
  15460. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15461. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15462. {
  15463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15464. {
  15465. tempIndex = ((gun_index==2) ? 1: 0);
  15466. }
  15467. else
  15468. {
  15469. tempIndex = gun_index;
  15470. }
  15471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15472. {
  15473. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15474. {
  15475. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15476. }
  15477. }// END OF CHAdeMO_QUANTITY
  15478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15479. }
  15480. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15481. {
  15482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15483. {
  15484. tempIndex = ((gun_index==2) ? 1: 0);
  15485. }
  15486. else
  15487. {
  15488. tempIndex = gun_index;
  15489. }
  15490. for (int index = 0; index < CCS_QUANTITY; index++)
  15491. {
  15492. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15493. {
  15494. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15495. }
  15496. }// END OF CCS_QUANTITY
  15497. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15498. }
  15499. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15500. {
  15501. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15502. {
  15503. tempIndex = ((gun_index==2) ? 1: 0);
  15504. }
  15505. else
  15506. {
  15507. tempIndex = gun_index;
  15508. }
  15509. for (int index = 0; index < GB_QUANTITY; index++)
  15510. {
  15511. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15512. {
  15513. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15514. }
  15515. }// END OF GB_QUANTITY
  15516. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15517. }
  15518. else if(gunType[gun_index] == GUN_TYPE_DO)
  15519. {
  15520. tempIndex = gun_index;
  15521. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15522. {
  15523. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15524. {
  15525. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15526. }
  15527. }
  15528. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15529. }
  15530. else
  15531. {
  15532. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15533. {
  15534. tempIndex = 2;
  15535. }
  15536. else
  15537. {
  15538. tempIndex = gun_index;
  15539. }
  15540. for (int index = 0; index < AC_QUANTITY; index++)
  15541. {
  15542. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15543. {
  15544. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15545. }
  15546. }// END OF AC_QUANTITY
  15547. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15548. }
  15549. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15550. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15551. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15552. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15553. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15554. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15555. }
  15556. //2.3====================================== Power.Active.Import =========================================
  15557. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  15558. {
  15559. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15560. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15561. {
  15562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15563. {
  15564. tempIndex = ((gun_index==2) ? 1: 0);
  15565. }
  15566. else
  15567. {
  15568. tempIndex = gun_index;
  15569. }
  15570. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15571. {
  15572. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15573. {
  15574. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15575. }
  15576. } // End for CHAdeMO_QUANTITY
  15577. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15578. }
  15579. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15580. {
  15581. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15582. {
  15583. tempIndex = ((gun_index==2) ? 1: 0);
  15584. }
  15585. else
  15586. {
  15587. tempIndex = gun_index;
  15588. }
  15589. for (int index = 0; index < CCS_QUANTITY; index++)
  15590. {
  15591. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15592. {
  15593. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15594. }
  15595. } // END for CCS_QUANTITY
  15596. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15597. }
  15598. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15599. {
  15600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15601. {
  15602. tempIndex = ((gun_index==2) ? 1: 0);
  15603. }
  15604. else
  15605. {
  15606. tempIndex = gun_index;
  15607. }
  15608. for (int index = 0; index < GB_QUANTITY; index++)
  15609. {
  15610. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15611. {
  15612. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15613. }
  15614. }// END for GB_QUANTITY
  15615. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15616. }
  15617. else if(gunType[gun_index] == GUN_TYPE_DO)
  15618. {
  15619. tempIndex = gun_index;
  15620. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15621. {
  15622. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15623. {
  15624. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15625. }
  15626. }
  15627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15628. }
  15629. else
  15630. {
  15631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15632. {
  15633. tempIndex = 2;
  15634. }
  15635. else
  15636. {
  15637. tempIndex = gun_index;
  15638. }
  15639. for (int index = 0; index < AC_QUANTITY; index++)
  15640. {
  15641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15642. {
  15643. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15644. }
  15645. } // END for AC_QUANTITY
  15646. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15647. }
  15648. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15649. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15650. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15651. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15653. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15654. }
  15655. //2.4====================================== Voltage L1 ====================================================
  15656. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15657. {
  15658. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15659. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15660. {
  15661. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15662. {
  15663. tempIndex = ((gun_index==2) ? 1: 0);
  15664. }
  15665. else
  15666. {
  15667. tempIndex = gun_index;
  15668. }
  15669. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15670. {
  15671. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15672. {
  15673. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15674. }
  15675. } // END OF FOR CHAdeMO_QUANTITY
  15676. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15677. }
  15678. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15679. {
  15680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15681. {
  15682. tempIndex = ((gun_index==2) ? 1: 0);
  15683. }
  15684. else
  15685. {
  15686. tempIndex = gun_index;
  15687. }
  15688. for (int index = 0; index < CCS_QUANTITY; index++)
  15689. {
  15690. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15691. {
  15692. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15693. }
  15694. } // END OF FOR CCS_QUANTITY
  15695. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15696. }
  15697. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15698. {
  15699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15700. {
  15701. tempIndex = ((gun_index==2) ? 1: 0);
  15702. }
  15703. else
  15704. {
  15705. tempIndex = gun_index;
  15706. }
  15707. for (int index = 0; index < GB_QUANTITY; index++)
  15708. {
  15709. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15710. {
  15711. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15712. }
  15713. } // END OF FOR GB_QUANTITY
  15714. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15715. }
  15716. else if(gunType[gun_index] == GUN_TYPE_DO)
  15717. {
  15718. tempIndex = gun_index;
  15719. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15720. {
  15721. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15722. {
  15723. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15724. }
  15725. }
  15726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15727. }
  15728. else
  15729. {
  15730. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15731. {
  15732. tempIndex = 2;
  15733. }
  15734. else
  15735. {
  15736. tempIndex = gun_index;
  15737. }
  15738. for (int index = 0; index < AC_QUANTITY; index++)
  15739. {
  15740. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15741. {
  15742. 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
  15743. }
  15744. } // END OF FOR AC_QUANTITY
  15745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15746. }
  15747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15750. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15753. }
  15754. //2.5============================================== End SoC =========================================================
  15755. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  15756. {
  15757. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15758. 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))
  15759. {
  15760. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15761. {
  15762. tempIndex = ((gun_index==2) ? 1: 0);
  15763. }
  15764. else
  15765. {
  15766. tempIndex = gun_index;
  15767. }
  15768. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15769. {
  15770. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15771. {
  15772. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15773. {
  15774. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15775. }
  15776. }
  15777. }
  15778. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15779. {
  15780. for (int index = 0; index < CCS_QUANTITY; index++)
  15781. {
  15782. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15783. {
  15784. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15785. }
  15786. }
  15787. }
  15788. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15789. {
  15790. for (int index = 0; index < GB_QUANTITY; index++)
  15791. {
  15792. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15793. {
  15794. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15795. }
  15796. }
  15797. }
  15798. else if(gunType[gun_index] == GUN_TYPE_DO)
  15799. {
  15800. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15801. {
  15802. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15803. {
  15804. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15805. }
  15806. }
  15807. }
  15808. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15809. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15810. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15811. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15812. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15813. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15814. } // END FOR DC CASE
  15815. }
  15816. //2.6====================================== Current.Import L2 ==============================================
  15817. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15818. {
  15819. // AC 3 phase L2 current
  15820. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15821. {
  15822. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15823. {
  15824. tempIndex = 2;
  15825. }
  15826. else
  15827. {
  15828. tempIndex = gun_index;
  15829. }
  15830. for (int index = 0; index < AC_QUANTITY; index++)
  15831. {
  15832. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15833. {
  15834. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15835. }
  15836. }// End of for AC_QUANTITY
  15837. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15838. }
  15839. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15840. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15841. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15842. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15843. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15844. }
  15845. //2.7====================================== Current.Import L3 ==============================================
  15846. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15847. {
  15848. // AC 3 phase L3 current
  15849. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15850. {
  15851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15852. {
  15853. tempIndex = 2;
  15854. }
  15855. else
  15856. {
  15857. tempIndex = gun_index;
  15858. }
  15859. for (int index = 0; index < AC_QUANTITY; index++)
  15860. {
  15861. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15862. {
  15863. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15864. }
  15865. }// End of for AC_QUANTITY
  15866. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15867. }
  15868. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15869. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15870. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15871. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15872. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15873. }
  15874. //2.9====================================== Voltage L2 ====================================================
  15875. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15876. {
  15877. // AC 3 phase L2 volatge
  15878. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15879. {
  15880. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15881. {
  15882. tempIndex = 2;
  15883. }
  15884. else
  15885. {
  15886. tempIndex = gun_index;
  15887. }
  15888. for (int index = 0; index < AC_QUANTITY; index++)
  15889. {
  15890. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15891. {
  15892. 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
  15893. }
  15894. } // END OF FOR AC_QUANTITY
  15895. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15896. }
  15897. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15898. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15899. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15900. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15901. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15902. }
  15903. //2.10====================================== Voltage L3 ====================================================
  15904. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15905. {
  15906. // AC 3 phase L3 volatge
  15907. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15908. {
  15909. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15910. {
  15911. tempIndex = 2;
  15912. }
  15913. else
  15914. {
  15915. tempIndex = gun_index;
  15916. }
  15917. for (int index = 0; index < AC_QUANTITY; index++)
  15918. {
  15919. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15920. {
  15921. 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
  15922. }
  15923. } // END OF FOR AC_QUANTITY
  15924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15925. }
  15926. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15927. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15928. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15929. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15930. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15931. }
  15932. //====================== Start SoC ================================
  15933. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, MeasurandStr[SoC]) != NULL)
  15934. {
  15935. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15936. 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))
  15937. {
  15938. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15939. {
  15940. tempIndex = ((gun_index==2) ? 1: 0);
  15941. }
  15942. else
  15943. {
  15944. tempIndex = gun_index;
  15945. }
  15946. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15947. {
  15948. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15949. {
  15950. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15951. {
  15952. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15953. }
  15954. }
  15955. }
  15956. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15957. {
  15958. for (int index = 0; index < CCS_QUANTITY; index++)
  15959. {
  15960. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15961. {
  15962. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15963. }
  15964. }
  15965. }
  15966. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15967. {
  15968. for (int index = 0; index < GB_QUANTITY; index++)
  15969. {
  15970. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15971. {
  15972. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15973. }
  15974. }
  15975. }
  15976. else if(gunType[gun_index] == GUN_TYPE_DO)
  15977. {
  15978. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15979. {
  15980. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15981. {
  15982. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15983. }
  15984. }
  15985. }
  15986. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15987. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15988. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15989. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15990. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15991. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15992. } // END FOR DC CASE
  15993. }
  15994. //======================================== Message create ==============================================
  15995. json_object *StopTransaction = json_object_new_object();
  15996. json_object *transactionDatas = json_object_new_array();
  15997. json_object *sampledValues = json_object_new_array();
  15998. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  15999. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  16000. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  16001. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  16002. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  16003. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  16004. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  16005. {
  16006. json_object *transactionData = json_object_new_object();
  16007. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  16008. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  16009. {
  16010. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  16011. {
  16012. json_object *sampledValue = json_object_new_object();
  16013. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  16014. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  16015. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  16016. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  16017. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  16018. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  16019. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  16020. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  16021. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  16022. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  16023. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  16024. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  16025. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  16026. json_object_array_add(sampledValues, sampledValue);
  16027. }
  16028. }
  16029. json_object_object_add(transactionData, "sampledValue", sampledValues);
  16030. json_object_array_add(transactionDatas, transactionData);
  16031. }
  16032. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  16033. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  16034. ,MESSAGE_TYPE_CALL
  16035. ,guid
  16036. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  16037. json_object_put(StopTransaction);
  16038. // Check File "TempStopTransaction" Exist
  16039. if((access(TempStopTransaction,F_OK))!=-1)
  16040. {
  16041. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16042. fclose(fopen(TempStopTransaction, "w"));
  16043. }
  16044. else
  16045. {
  16046. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16047. FILE *log = fopen(TempStopTransaction, "w+");
  16048. if(log == NULL)
  16049. {
  16050. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16051. return ;
  16052. }
  16053. else
  16054. {
  16055. fclose(log);
  16056. }
  16057. }
  16058. //Add TempStopTransaction | Update TempStopTransaction
  16059. // open file for writing
  16060. FILE *outfile;
  16061. outfile = fopen (TempStopTransaction, "a");
  16062. //DEBUG_INFO("data = %s\n", queuedata);
  16063. fputs(queuedata, outfile);
  16064. fputs("\n", outfile);
  16065. fclose (outfile);
  16066. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16067. }
  16068. void checkTempStopTransaction(int gun_index)
  16069. {
  16070. FILE *fptr1;
  16071. char ch;
  16072. char str[QUEUE_MESSAGE_LENGTH]={0};
  16073. char guid[37]={0};
  16074. char tempdata[65]={0};
  16075. char connectorStr[2]={0};
  16076. char TempStopTransaction[256];
  16077. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  16078. fptr1 = fopen(TempStopTransaction, "r");
  16079. //TempStopTransaction格式: 槍號,StopTransaction封包
  16080. if (!fptr1)
  16081. {
  16082. //printf(" File not found or unable to open the input file!!\n");
  16083. return ;
  16084. }
  16085. ch=fgetc(fptr1);
  16086. //printf(" Now the content of the file %s is : \n",fname);
  16087. rewind(fptr1);
  16088. if(ch!=EOF)
  16089. {
  16090. // copy all contents to the temporary file except the specific line
  16091. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16092. {
  16093. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16094. if(str[0]=='\0')
  16095. {
  16096. break;
  16097. }
  16098. //TempStopTransaction格式: 槍號,StopTransaction封包
  16099. strncpy(connectorStr, str, 1);
  16100. if(atoi(connectorStr) != (gun_index+1))
  16101. {
  16102. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  16103. fclose(fptr1);
  16104. return ;
  16105. }
  16106. //random_uuid(guid);
  16107. strncpy(guid, str+6, 36); //copy guid
  16108. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16109. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16110. {
  16111. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16112. }
  16113. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16114. OCPP_insert_transaction_msg(NO, str);
  16115. memset(str,0,ARRAY_SIZE(str));
  16116. }
  16117. }
  16118. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16119. fclose(fptr1);
  16120. remove(TempStopTransaction); // remove the original file
  16121. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16122. }
  16123. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16124. {
  16125. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16126. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16127. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16128. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16129. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16130. }
  16131. int GetWebSocketPingInterval(void)
  16132. {
  16133. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16134. }
  16135. int GetServerSign(void)
  16136. {
  16137. return server_sign;
  16138. }
  16139. uint8_t GetOcppSecurityProfile()
  16140. {
  16141. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  16142. }
  16143. void GetOcppChargerBoxId(uint8_t *data)
  16144. {
  16145. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  16146. }
  16147. void GetOcppSecurityPassword(uint8_t *data)
  16148. {
  16149. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  16150. }
  16151. void SetOcppVersion(uint8_t *version)
  16152. {
  16153. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  16154. DEBUG_INFO("ocpp version: %s\n", version);
  16155. if(strstr((char*)version, "ocpp1.6") != NULL)
  16156. {
  16157. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  16158. }
  16159. else if(strstr((char*)version, "ocpp2.0") != NULL)
  16160. {
  16161. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  16162. system("pkill OcppBackend");
  16163. }
  16164. }
  16165. void SetServerSign(int value)
  16166. {
  16167. server_sign = value;
  16168. }
  16169. int GetBootNotificationInterval(void)
  16170. {
  16171. return BootNotificationInterval;
  16172. }
  16173. int GetInternetConn(void)
  16174. {
  16175. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16176. }
  16177. int GetBackendConnectionTimeout(void)
  16178. {
  16179. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16180. }
  16181. int isConnectorInitMode(int gun_index)
  16182. {
  16183. int tempIndex = 0;
  16184. int result = TRUE;
  16185. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16186. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16187. {
  16188. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16189. {
  16190. tempIndex = ((gun_index==2) ? 1: 0);
  16191. }
  16192. else
  16193. {
  16194. tempIndex = gun_index;
  16195. }
  16196. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16197. {
  16198. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16199. {
  16200. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16201. } //end of the same index
  16202. }//end of for CHAdeMO_QUANTITY
  16203. }
  16204. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16205. {
  16206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16207. {
  16208. tempIndex = ((gun_index==2) ? 1: 0);
  16209. }
  16210. else
  16211. {
  16212. tempIndex = gun_index;
  16213. }
  16214. for (int index = 0; index < CCS_QUANTITY; index++)
  16215. {
  16216. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16217. {
  16218. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16219. } //end of the same index
  16220. } // end of for CCS_QUANTITY
  16221. }
  16222. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16223. {
  16224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16225. {
  16226. tempIndex = ((gun_index==2) ? 1: 0);
  16227. }
  16228. else
  16229. {
  16230. tempIndex = gun_index;
  16231. }
  16232. for (int index = 0; index < GB_QUANTITY; index++)
  16233. {
  16234. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16235. {
  16236. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16237. } //end of the same index
  16238. } // end of for GB_QUANTITY
  16239. }
  16240. else if(gunType[gun_index] == GUN_TYPE_DO)
  16241. {
  16242. tempIndex = gun_index;
  16243. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16244. {
  16245. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16246. {
  16247. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16248. } //end of the same index
  16249. }
  16250. }
  16251. else
  16252. {
  16253. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16254. {
  16255. tempIndex = 2;
  16256. }
  16257. else
  16258. {
  16259. tempIndex = gun_index;
  16260. }
  16261. for (int index = 0; index < AC_QUANTITY; index++)
  16262. {
  16263. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16264. {
  16265. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16266. }//end of the same index
  16267. }//end of for AC_QUANTITY
  16268. }
  16269. return result;
  16270. }
  16271. void refreshProcDogTimer()
  16272. {
  16273. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  16274. }
  16275. void InitialSystemValue(void)
  16276. {
  16277. int connectorIndex = 0;
  16278. //int valueASCII = 0;
  16279. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  16280. gunTotalNumber=0;
  16281. SystemInitial = 0;
  16282. locallistVersion=0;
  16283. BootNotificationInterval = 0;
  16284. authorizeRetryTimes = 0;
  16285. GunStatusInterval = 10;
  16286. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  16287. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16288. //Hear Beat
  16289. HeartBeatWithNOResponse = 0;
  16290. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  16291. FirstHeartBeat = 0;
  16292. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  16293. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  16294. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16295. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16296. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16297. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16298. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16299. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16300. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16301. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16302. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16303. memset(gunType, 0, ARRAY_SIZE(gunType));
  16304. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16305. {
  16306. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  16307. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  16308. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  16309. {
  16310. // DO series
  16311. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  16312. {
  16313. SystemInitial = SystemInitial + 1;
  16314. gunTotalNumber = gunTotalNumber + 1;
  16315. gunType[connectorIndex] = GUN_TYPE_DO;
  16316. connectorIndex = connectorIndex + 1;
  16317. }
  16318. }
  16319. else
  16320. {
  16321. // DM, DW, DS series
  16322. //check connector / socket type (index: 8, 9, 10)
  16323. for(int index=7; index <10 ; index++)
  16324. {
  16325. if(index != 8)
  16326. {
  16327. // DC Connector
  16328. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  16329. {
  16330. SystemInitial = SystemInitial + 1;
  16331. gunTotalNumber = gunTotalNumber + 1;
  16332. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  16333. connectorIndex = connectorIndex + 1;
  16334. }
  16335. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  16336. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  16337. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  16338. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  16339. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  16340. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  16341. {
  16342. SystemInitial = SystemInitial + 1;
  16343. gunTotalNumber = gunTotalNumber + 1;
  16344. gunType[connectorIndex] = GUN_TYPE_CCS;
  16345. connectorIndex = connectorIndex + 1;
  16346. }
  16347. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  16348. {
  16349. SystemInitial = SystemInitial + 1;
  16350. gunTotalNumber = gunTotalNumber + 1;
  16351. gunType[connectorIndex] = GUN_TYPE_GBT;
  16352. connectorIndex = connectorIndex + 1;
  16353. }
  16354. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  16355. {
  16356. SystemInitial = SystemInitial + 1;
  16357. gunTotalNumber = gunTotalNumber + 1;
  16358. gunType[connectorIndex] = GUN_TYPE_DO;
  16359. connectorIndex = connectorIndex + 1;
  16360. }
  16361. }
  16362. else
  16363. {
  16364. // AC Connector
  16365. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16366. {
  16367. SystemInitial = SystemInitial + 1;
  16368. gunTotalNumber = gunTotalNumber + 1;
  16369. gunType[connectorIndex] = GUN_TYPE_AC;
  16370. connectorIndex = connectorIndex + 1;
  16371. }
  16372. }
  16373. }
  16374. }
  16375. //DEBUG_INFO("DC ...\n");
  16376. }
  16377. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16378. {
  16379. //check connector / socket type (index: 8, 9, 10)
  16380. for(int index=7; index <10 ; index++)
  16381. {
  16382. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16383. {
  16384. SystemInitial = SystemInitial + 1;
  16385. gunTotalNumber = gunTotalNumber + 1;
  16386. gunType[connectorIndex] = GUN_TYPE_AC;
  16387. connectorIndex = connectorIndex + 1;
  16388. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16389. }
  16390. }
  16391. }
  16392. //Status && ConnectorPlugIn Setting
  16393. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16394. {
  16395. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16396. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16397. }
  16398. for (int index = 0; index < CCS_QUANTITY; index++)
  16399. {
  16400. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16401. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16402. }
  16403. for (int index = 0; index < GB_QUANTITY; index++)
  16404. {
  16405. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16406. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16407. }
  16408. for (int index = 0; index < AC_QUANTITY; index++)
  16409. {
  16410. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16411. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16412. }
  16413. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16414. {
  16415. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16416. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16417. }
  16418. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16419. {
  16420. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  16421. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16422. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16423. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16424. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  16425. }
  16426. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16427. clientTime.Heartbeat=time((time_t*)NULL);
  16428. sleep(1);
  16429. }
  16430. void LWS_Send(char *str)
  16431. {
  16432. //=====================================================
  16433. // Check InternetConn 0: disconnected, 1: connected
  16434. //====================================================
  16435. if(GetOcppConnStatus() == 0)
  16436. {
  16437. DEBUG_INFO("offline now !!!\n");
  16438. return;
  16439. }
  16440. // Only disable isWebsocketSendable operation initiated by charger
  16441. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16442. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16443. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16444. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16445. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16446. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16447. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16448. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16449. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16450. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16451. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16452. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16453. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16454. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16455. {
  16456. isWebsocketSendable = 0;
  16457. }
  16458. pthread_mutex_lock(&lock_send);
  16459. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16460. sprintf((char *)SendBuffer, "%s", str);
  16461. SendBufLen = strlen(str);
  16462. pthread_mutex_unlock(&lock_send);
  16463. lws_callback_on_writable(wsi_client);
  16464. //lws_service(context, 0);
  16465. //sleep(1);
  16466. }
  16467. void LWS_SendNow(char *str)
  16468. {
  16469. //=====================================================
  16470. // Check InternetConn 0: disconnected, 1: connected
  16471. //====================================================
  16472. if(GetOcppConnStatus() == 0)
  16473. {
  16474. DEBUG_INFO("offline now !!!\n");
  16475. return;
  16476. }
  16477. // Only disable isWebsocketSendable operation initiated by charger
  16478. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16479. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16480. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16481. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  16482. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16483. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16484. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16485. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  16486. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16487. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  16488. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16489. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16490. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16491. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  16492. {
  16493. isWebsocketSendable = 0;
  16494. }
  16495. pthread_mutex_lock(&lock_send);
  16496. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16497. sprintf((char *)SendBuffer, "%s", str);
  16498. SendBufLen = strlen(str);
  16499. pthread_mutex_unlock(&lock_send);
  16500. lws_callback_on_writable(wsi_client);
  16501. lws_service(context, 0);
  16502. //sleep(1);
  16503. }