MessageHandler.c 781 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233
  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 localversion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char :4; //bit 4~7
  117. }bits[CONNECTOR_QUANTITY];
  118. }CpinitiateMsg;
  119. CpinitiateMsg cpinitateMsg;
  120. //GetConfiguration Array
  121. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  124. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  125. #if 0
  126. static char *ChargePointErrorCodeStr[] = {
  127. MACROSTR(ConnectorLockFailure),
  128. MACROSTR(EVCommunicationError),
  129. MACROSTR(GroundFailure),
  130. MACROSTR(HighTemperature),
  131. MACROSTR(InternalError),
  132. MACROSTR(LocalListConflict),
  133. MACROSTR(NoError),
  134. MACROSTR(OtherError),
  135. MACROSTR(OverCurrentFailure),
  136. MACROSTR(OverVoltage),
  137. MACROSTR(PowerMeterFailure),
  138. MACROSTR(PowerSwitchFailure),
  139. MACROSTR(ReaderFailure),
  140. MACROSTR(ResetFailure),
  141. MACROSTR(UnderVoltage),
  142. MACROSTR(WeakSignal)
  143. };
  144. #endif
  145. static char * ChargePointStatusStr[] = {
  146. MACROSTR(Available),
  147. MACROSTR(Preparing),
  148. MACROSTR(Charging),
  149. MACROSTR(SuspendedEVSE),
  150. MACROSTR(SuspendedEV),
  151. MACROSTR(Finishing),
  152. MACROSTR(Reserved),
  153. MACROSTR(Unavailable),
  154. MACROSTR(Faulted)
  155. };
  156. static char *RegistrationStatusStr[] = {
  157. MACROSTR(Accepted),
  158. MACROSTR(Pending),
  159. MACROSTR(Rejected)
  160. };
  161. static char *AvailabilityTypeStr[] = {
  162. MACROSTR(Inoperative),
  163. MACROSTR(Operative)
  164. };
  165. static char *AvailabilityStatusStr[] = {
  166. MACROSTR(Accepted),
  167. MACROSTR(Rejected),
  168. MACROSTR(Scheduled)
  169. };
  170. static char *ConfigurationStatusStr[] = {
  171. MACROSTR(Accepted),
  172. MACROSTR(Rejected),
  173. MACROSTR(RebootRequired),
  174. MACROSTR(NotSupported)
  175. };
  176. static char *ClearCacheStatusStr[] = {
  177. MACROSTR(Accepted),
  178. MACROSTR(Rejected)
  179. };
  180. static char *ChargingProfilePurposeTypeStr[] = {
  181. MACROSTR(ChargePointMaxProfile),
  182. MACROSTR(TxDefaultProfile),
  183. MACROSTR(TxProfile)
  184. };
  185. static char *ChargingProfileStatusStr[] = {
  186. MACROSTR(Accepted),
  187. MACROSTR(Rejected),
  188. MACROSTR(NotSupported)
  189. };
  190. static char *ClearChargingProfileStatusStr[] = {
  191. MACROSTR(Accepted),
  192. MACROSTR(Unknown)
  193. };
  194. static char *GetCompositeScheduleStatusStr[] = {
  195. MACROSTR(Accepted),
  196. MACROSTR(Rejected)
  197. };
  198. static char *UpdateTypeStr[] = {
  199. MACROSTR(Differential),
  200. MACROSTR(Full)
  201. };
  202. static char *UpdateStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Failed),
  205. MACROSTR(NotSupported),
  206. MACROSTR(VersionMismatch)
  207. };
  208. static char *RemoteStartStopStatusStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Rejected)
  211. };
  212. static char *ReservationStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Faulted),
  215. MACROSTR(Occupied),
  216. MACROSTR(Rejected),
  217. MACROSTR(Unavailable)
  218. };
  219. static char *ResetTypeStr[] = {
  220. MACROSTR(Hard),
  221. MACROSTR(Soft)
  222. };
  223. static char *ResetStatusStr[] = {
  224. MACROSTR(Accepted),
  225. MACROSTR(Rejected)
  226. };
  227. static char * DiagnosticsStatusStr[] = {
  228. MACROSTR(Idle),
  229. MACROSTR(Uploaded),
  230. MACROSTR(UploadFailed),
  231. MACROSTR(Uploading)
  232. };
  233. static char * FirmwareStatusStr[] = {
  234. MACROSTR(Downloaded),
  235. MACROSTR(DownloadFailed),
  236. MACROSTR(Downloading),
  237. MACROSTR(Idle),
  238. MACROSTR(InstallationFailed),
  239. MACROSTR(Installing),
  240. MACROSTR(Installed)
  241. };
  242. static char * MessageTriggerStr[] = {
  243. MACROSTR(BootNotification),
  244. MACROSTR(DiagnosticsStatusNotification),
  245. MACROSTR(FirmwareStatusNotification),
  246. MACROSTR(Heartbeat),
  247. MACROSTR(MeterValues),
  248. MACROSTR(StatusNotification)
  249. };
  250. static char * TriggerMessageStatusStr[] = {
  251. MACROSTR(Accepted),
  252. MACROSTR(Rejected),
  253. MACROSTR(NotImplemented)
  254. };
  255. static char * UnlockStatusStr[] = {
  256. MACROSTR(Unlocked),
  257. MACROSTR(UnlockFailed),
  258. MACROSTR(NotSupported)
  259. };
  260. #if 0
  261. static char * StopTransactionReasonStr[] = {
  262. MACROSTR(EmergencyStop),
  263. MACROSTR(EVDisconnected),
  264. MACROSTR(HardReset),
  265. MACROSTR(Local),
  266. MACROSTR(Other),
  267. MACROSTR(PowerLoss),
  268. MACROSTR(Reboot),
  269. MACROSTR(Remote),
  270. MACROSTR(SoftReset),
  271. MACROSTR(UnlockCommand),
  272. MACROSTR(DeAuthorized)
  273. };
  274. #endif
  275. static char * CancelReservationStatusStr[] = {
  276. MACROSTR(Accepted),
  277. MACROSTR(Rejected)
  278. };
  279. static char * ReadingContextStr[] = {
  280. MACROSTR(Interruption.Begin),
  281. MACROSTR(Interruption.End),
  282. MACROSTR(Other),
  283. MACROSTR(Sample.Clock),
  284. MACROSTR(Sample.Periodic),
  285. MACROSTR(Transaction.Begin),
  286. MACROSTR(Transaction.End),
  287. MACROSTR(Trigger)
  288. };
  289. static char * ValueFormatStr[] = {
  290. MACROSTR(Raw),
  291. MACROSTR(SignedData)
  292. };
  293. static char * MeasurandStr[] = {
  294. MACROSTR(Current.Export),
  295. MACROSTR(Current.Import),
  296. MACROSTR(Current.Offered),
  297. MACROSTR(Energy.Active.Export.Register),
  298. MACROSTR(Energy.Active.Import.Register),
  299. MACROSTR(Energy.Reactive.Export.Register),
  300. MACROSTR(Energy.Reactive.Import.Register),
  301. MACROSTR(Energy.Active.Export.Interval),
  302. MACROSTR(Energy.Active.Import.Interval),
  303. MACROSTR(Energy.Reactive.Export.Interval),
  304. MACROSTR(Energy.Reactive.Import.Interval),
  305. MACROSTR(Frequency),
  306. MACROSTR(Power.Active.Export),
  307. MACROSTR(Power.Active.Import),
  308. MACROSTR(Power.Factor),
  309. MACROSTR(Power.Offered),
  310. MACROSTR(Power.Reactive.ExportMACROSTR),
  311. MACROSTR(Power.Reactive.Import),
  312. MACROSTR(RPM),
  313. MACROSTR(SoC),
  314. MACROSTR(Temperature),
  315. MACROSTR(Voltage)
  316. };
  317. static char * LocationStr[] = {
  318. MACROSTR(Body),
  319. MACROSTR(Cable),
  320. MACROSTR(EV),
  321. MACROSTR(Inlet),
  322. MACROSTR(Outlet)
  323. };
  324. static char * PhaseStr[] = {
  325. MACROSTR(L1),
  326. MACROSTR(L2),
  327. MACROSTR(L3),
  328. MACROSTR(N),
  329. MACROSTR(L1-N),
  330. MACROSTR(L2-N),
  331. MACROSTR(L3-N),
  332. MACROSTR(L1-L2),
  333. MACROSTR(L2-L3),
  334. MACROSTR(L3-L1)
  335. };
  336. static char * UnitOfMeasureStr[] = {
  337. MACROSTR(Wh),
  338. MACROSTR(kWh),
  339. MACROSTR(varh),
  340. MACROSTR(kvarh),
  341. MACROSTR(W),
  342. MACROSTR(kW),
  343. MACROSTR(VA),
  344. MACROSTR(kVA),
  345. MACROSTR(var),
  346. MACROSTR(kvar),
  347. MACROSTR(A),
  348. MACROSTR(V),
  349. MACROSTR(Celsius),
  350. MACROSTR(Fahrenheit),
  351. MACROSTR(K),
  352. MACROSTR(Percent)
  353. };
  354. //=========================================
  355. // Save configuration
  356. //=========================================
  357. int runShellCmd(const char*cmd)
  358. {
  359. int result = FAIL;
  360. char buf[256];
  361. FILE *fp;
  362. fp = popen(cmd, "r");
  363. if(fp != NULL)
  364. {
  365. while(fgets(buf, sizeof(buf), fp) != NULL)
  366. {
  367. DEBUG_INFO("%s\n", buf);
  368. }
  369. result = PASS;
  370. }
  371. pclose(fp);
  372. return result;
  373. }
  374. int StoreUsrConfigData(struct SysConfigData *UsrData)
  375. {
  376. int result = PASS;
  377. int fd,wrd;
  378. unsigned int i,Chk;
  379. unsigned char *ptr, *BufTmp;
  380. int MtdBlockSize = 0x300000;
  381. Chk=0;
  382. ptr=(unsigned char *)UsrData;
  383. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  384. {
  385. memset(BufTmp,0,MtdBlockSize);
  386. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  387. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  388. Chk+=*(BufTmp+i);
  389. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  390. // Output configuration to file.
  391. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  392. if (fd < 0)
  393. {
  394. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  395. free(BufTmp);
  396. return 0;
  397. }
  398. wrd=write(fd, BufTmp, MtdBlockSize);
  399. close(fd);
  400. if(wrd<MtdBlockSize)
  401. {
  402. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  403. free(BufTmp);
  404. return 0;
  405. }
  406. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  407. DEBUG_INFO("Erase /dev/mtd10.\n");
  408. runShellCmd("flash_erase /dev/mtd10 0 0");
  409. DEBUG_INFO("Write /dev/mtd10.\n");
  410. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  411. DEBUG_INFO("Erase /dev/mtd11.\n");
  412. runShellCmd("flash_erase /dev/mtd11 0 0");
  413. DEBUG_INFO("Write /dev/mtd11.\n");
  414. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  415. system("rm -f /mnt/EvseConfig.bin");
  416. DEBUG_INFO("EvseConfig write to flash OK\n");
  417. }
  418. else
  419. {
  420. DEBUG_ERROR("alloc BlockSize NG\r\n");
  421. result = FAIL;
  422. }
  423. if(BufTmp!=NULL)
  424. free(BufTmp);
  425. return result;
  426. }
  427. //=========================================
  428. // Sqlite3 related function
  429. //=========================================
  430. static int selectSqlCount = 0;
  431. static int callback(void *data, int argc, char **argv, char **azColName){
  432. int i;
  433. //printf("%s: ", (const char*)data);
  434. selectSqlCount = argc;
  435. for(i = 0; i<argc; i++){
  436. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  437. }
  438. //printf("\n");
  439. return 0;
  440. }
  441. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  442. //int i;
  443. //printf("%s:\n", (const char*)data);
  444. localversion = argv[5] ? atoi(argv[5]) : 0;
  445. //printf("localversion=%d\n", localversion);
  446. return 0;
  447. }
  448. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  449. //printf("%s:\n", (const char*)data);
  450. //idTag
  451. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  452. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. //parentIdTag
  454. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  455. //expir_date
  456. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  457. //status
  458. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  459. //version
  460. if(columenCount > 5)
  461. idTagQuery.listVersionInt = atoi(columnValue[5]);
  462. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  463. return 0;
  464. }
  465. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  466. {
  467. // localversion = argv[5] ? atoi(argv[5]) : 0;
  468. // printf("localversion=%d\n", localversion);
  469. return 0;
  470. }
  471. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  472. {
  473. for (int i = 0; i < n_columns; i++)
  474. {
  475. DEBUG_INFO("%s\t", col_values[i]);
  476. }
  477. DEBUG_INFO("\n");
  478. return 0;
  479. }
  480. int OCPP_cleanLocalCache()
  481. {
  482. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  483. char *errMsg = 0;
  484. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  485. if (SQLITE_OK != rc)
  486. {
  487. DEBUG_INFO("SQL error: %s\n",errMsg);
  488. return FALSE;
  489. }
  490. return TRUE;
  491. }
  492. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  493. {
  494. int isSuccess = TRUE;
  495. int ret = 0;
  496. //const char* data = "Callback function called";
  497. char sql[300];
  498. char zErrMsg[200];
  499. memset(sql, 0, 300);
  500. memset(zErrMsg, 0, 200);
  501. 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);
  502. //* Execute SQL statement */
  503. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  504. if( ret != SQLITE_OK )
  505. {
  506. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  507. isSuccess = FALSE;
  508. }
  509. return isSuccess;
  510. }
  511. void OCPP_getIdTagFromLocalCache(char idTag[])
  512. {
  513. int rc = 0;
  514. char sql[100];
  515. char zErrMsg[100];
  516. memset(sql, 0, 100);
  517. memset(zErrMsg, 0, 100);
  518. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  519. memset(&idTagQuery, 0, sizeof(idTagQuery));
  520. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  521. /* Execute SQL statement */
  522. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  523. if( rc != SQLITE_OK )
  524. {
  525. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  526. }
  527. }
  528. void OCPP_getListVerion()
  529. {
  530. int rc = 0;
  531. // const char* data = "Callback function called";
  532. char sql[100];
  533. char zErrMsg[100];
  534. memset(sql, 0, 100);
  535. memset(zErrMsg, 0, 100);
  536. strcpy(sql, "select * from ocpp_auth_local order by idx");
  537. /* Execute SQL statement */
  538. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  539. if( rc != SQLITE_OK )
  540. {
  541. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  542. }
  543. }
  544. void OCPP_get_TableAuthlocalAllData(void)
  545. {
  546. int rc = 0;
  547. char sql[100];
  548. char zErrMsg[100];
  549. memset(sql, 0, 100);
  550. memset(zErrMsg, 0, 100);
  551. sprintf(sql,"select * from ocpp_auth_local ");
  552. /* Execute SQL statement */
  553. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  554. if( rc != SQLITE_OK )
  555. {
  556. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  557. }
  558. //return ver;
  559. }
  560. int OCPP_cleanLocalList()
  561. {
  562. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  563. char *errMsg = 0;
  564. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  565. if (SQLITE_OK != rc)
  566. {
  567. DEBUG_INFO("%s\n",errMsg);
  568. return FALSE;
  569. }
  570. return TRUE;
  571. }
  572. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  573. {
  574. int isSuccess = FALSE;
  575. int ret = 0;
  576. //const char* data = "Callback function called";
  577. char sql[300];
  578. char zErrMsg[200];
  579. memset(sql, 0, 300);
  580. memset(zErrMsg, 0, 200);
  581. 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);
  582. //* Execute SQL statement */
  583. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  584. if( ret != SQLITE_OK )
  585. {
  586. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  587. return isSuccess;
  588. }
  589. memset(sql, 0, 300);
  590. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  591. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  592. if( ret != SQLITE_OK )
  593. {
  594. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  595. return isSuccess;
  596. }
  597. isSuccess = TRUE;
  598. return isSuccess;
  599. }
  600. void OCPP_getIdTagFromLocalList(char idTag[])
  601. {
  602. int rc = 0;
  603. // const char* data = "Callback function called";
  604. char sql[100];
  605. char zErrMsg[100];
  606. memset(sql, 0, 100);
  607. memset(zErrMsg, 0, 100);
  608. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  609. memset(&idTagQuery, 0, sizeof(idTagQuery));
  610. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  611. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  612. /* Execute SQL statement */
  613. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  614. if( rc != SQLITE_OK )
  615. {
  616. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  617. }
  618. //return ver;
  619. }
  620. void OCPP_deleteIdTagFromLocalList(char idTag[])
  621. {
  622. //int ver = 0;
  623. //int isSuccess = FALSE;
  624. int rc = 0;
  625. char sql[100];
  626. char zErrMsg[100];
  627. memset(sql, 0, 100);
  628. memset(zErrMsg, 0, 100);
  629. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  630. //* Execute SQL statement */
  631. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  632. if( rc != SQLITE_OK )
  633. {
  634. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  635. }
  636. }
  637. int getCurrentYear()
  638. {
  639. int result = 0;
  640. time_t CurrentTime;
  641. struct tm *tm;
  642. CurrentTime = time(NULL);
  643. tm=localtime(&CurrentTime);
  644. result = (tm->tm_year + 1900);
  645. return result;
  646. }
  647. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  648. {
  649. int result = PASS;
  650. char* errMsg = NULL;
  651. char sqlStr[8192];
  652. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  653. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  654. {
  655. result = FAIL;
  656. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  657. }
  658. 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));
  659. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  660. {
  661. result = FAIL;
  662. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  663. }
  664. return result;
  665. }
  666. //==========================================
  667. // Check time passed since today
  668. //==========================================
  669. long long DiffTimebWithNow(struct timeb ST)
  670. {
  671. //return milli-second
  672. struct timeb ET;
  673. long long StartTime,StopTime;
  674. ftime(&ET);
  675. StartTime=(long long)ST.time;
  676. StopTime=(long long)ET.time;
  677. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  678. }
  679. int getTimePassSinceToday(uint8_t gun_index)
  680. {
  681. int result = -1;
  682. static time_t lastTime[4];
  683. time_t t;
  684. struct tm *tmStartToday;
  685. struct timeb tbStartToday;
  686. t=time(NULL);
  687. if(difftime(t, lastTime[gun_index])>0)
  688. {
  689. tmStartToday=localtime(&t);
  690. tmStartToday->tm_hour = 0;
  691. tmStartToday->tm_min = 0;
  692. tmStartToday->tm_sec = 0;
  693. tbStartToday.time = mktime(tmStartToday);
  694. tbStartToday.millitm = 0;
  695. result = DiffTimebWithNow(tbStartToday)/1000;
  696. lastTime[gun_index] = t;
  697. }
  698. return result;
  699. }
  700. void getNowDatetime(uint8_t *data)
  701. {
  702. time_t t = time(NULL);
  703. struct tm tm = *localtime(&t);
  704. 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);
  705. }
  706. int syncDateTimeRTC(uint8_t *data)
  707. {
  708. struct ParsingResult
  709. {
  710. int result;
  711. int scanedElement;
  712. int year;
  713. int month;
  714. int mday;
  715. int hour;
  716. int min;
  717. int sec;
  718. int tz_hour;
  719. int tz_min;
  720. float minSec;
  721. }result;
  722. struct tm tmOrg;
  723. struct tm *tmTarget;
  724. struct timeb tbTarget;
  725. char buf[128];
  726. memset(&result, 0x00, sizeof(struct ParsingResult));
  727. result.result = PASS;
  728. if(strstr((char*)data, ".") != NULL)
  729. {
  730. // Original data with mini second
  731. if(strstr((char*)data, "Z") != NULL)
  732. {
  733. // Original data with Z
  734. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  735. &result.year,
  736. &result.month,
  737. &result.mday,
  738. &result.hour,
  739. &result.min,
  740. &result.sec,
  741. &result.minSec);
  742. }
  743. else
  744. {
  745. // Original data without Z
  746. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  747. &result.year,
  748. &result.month,
  749. &result.mday,
  750. &result.hour,
  751. &result.min,
  752. &result.sec,
  753. &result.minSec,
  754. &result.tz_hour,
  755. &result.tz_min);
  756. }
  757. }
  758. else
  759. {
  760. // Original data without mini second
  761. if(strstr((char*)data, "Z") != NULL)
  762. {
  763. // Original data with Z
  764. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  765. &result.year,
  766. &result.month,
  767. &result.mday,
  768. &result.hour,
  769. &result.min,
  770. &result.sec);
  771. }
  772. else
  773. {
  774. // Original data without Z
  775. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  776. &result.year,
  777. &result.month,
  778. &result.mday,
  779. &result.hour,
  780. &result.min,
  781. &result.sec,
  782. &result.tz_hour,
  783. &result.tz_min);
  784. }
  785. }
  786. tmOrg.tm_year = result.year - 1900;
  787. tmOrg.tm_mon = result.month - 1;
  788. tmOrg.tm_mday = result.mday;
  789. tmOrg.tm_hour = result.hour;
  790. tmOrg.tm_min = result.min;
  791. tmOrg.tm_sec = result.sec;
  792. tmOrg.tm_gmtoff = 0;
  793. tbTarget.time = mktime(&tmOrg);
  794. tbTarget.timezone = 0;
  795. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  796. tmTarget = gmtime(&tbTarget.time);
  797. 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);
  798. //DEBUG_INFO(" org date time: %s\n", data);
  799. //DEBUG_INFO("parse date time: %s\n", buf);
  800. system(buf);
  801. system("/sbin/hwclock -w --systohc");
  802. if(result.scanedElement < 6)
  803. result.result = FAIL;
  804. return result.result;
  805. }
  806. //==========================================
  807. // GetCompositeSchedule logic related function
  808. //==========================================
  809. int DiffTimebSec(struct timeb ST, struct timeb ET)
  810. {
  811. //return milli-second
  812. unsigned int StartTime,StopTime;
  813. StartTime=(unsigned int)ST.time;
  814. StopTime=(unsigned int)ET.time;
  815. return (StopTime-StartTime);
  816. }
  817. int DiffTimebWithNowSec(struct timeb ST)
  818. {
  819. //return milli-second
  820. struct timeb ET;
  821. unsigned int StartTime,StopTime;
  822. ftime(&ET);
  823. StartTime=(unsigned int)ST.time;
  824. StopTime=(unsigned int)ET.time;
  825. return (StopTime-StartTime);
  826. }
  827. int getStartStop(uint8_t *start, uint8_t *stop)
  828. {
  829. int result = -1;
  830. struct tm tmStart;
  831. struct timeb tbStart;
  832. struct tm tmStop;
  833. struct timeb tbStop;
  834. 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) &&
  835. (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))
  836. {
  837. //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);
  838. //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);
  839. tmStart.tm_year -= 1900;
  840. tmStart.tm_mon -= 1;
  841. tbStart.time = mktime(&tmStart);
  842. tbStart.millitm = 0;
  843. tmStop.tm_year -= 1900;
  844. tmStop.tm_mon -= 1;
  845. tbStop.time = mktime(&tmStop);
  846. tbStop.millitm = 0;
  847. result = DiffTimebSec(tbStart, tbStop);
  848. //DEBUG_INFO("getStartStop(): %d\n", result);
  849. }
  850. else
  851. {
  852. DEBUG_WARN("Start or stop date parsing error.\r\n");
  853. }
  854. return result;
  855. }
  856. int isOvertNow(uint8_t *start)
  857. {
  858. int result = NO;
  859. struct tm tmStart;
  860. struct timeb tbStart;
  861. 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))
  862. {
  863. //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);
  864. tmStart.tm_year -= 1900;
  865. tmStart.tm_mon -= 1;
  866. tbStart.time = mktime(&tmStart);
  867. tbStart.millitm = 0;
  868. if(DiffTimebWithNowSec(tbStart) <= 0)
  869. result = NO;
  870. else
  871. result = YES;
  872. }
  873. else
  874. {
  875. DEBUG_WARN("Start date parsing error.\n");
  876. }
  877. return result;
  878. }
  879. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  880. {
  881. int result = -1;
  882. struct tm tmStart;
  883. struct timeb tbStart;
  884. struct tm tmStop;
  885. struct timeb tbStop;
  886. 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) &&
  887. (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))
  888. {
  889. tmStart.tm_year -= 1900;
  890. tmStart.tm_mon -= 1;
  891. tbStart.time = mktime(&tmStart);
  892. tbStart.millitm = 0;
  893. tmStop.tm_year -= 1900;
  894. tmStop.tm_mon -= 1;
  895. tbStop.time = mktime(&tmStop);
  896. tbStop.millitm = 0;
  897. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  898. }
  899. return result;
  900. }
  901. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  902. {
  903. FILE *fp;
  904. char profileFileName[128];
  905. char *line = NULL;
  906. size_t len = 0;
  907. time_t CurrentTime;
  908. struct tm *tmComposite;
  909. struct StructChargingProfile maxProfile;
  910. struct StructChargingProfile defaultTxProfile;
  911. struct StructChargingProfile txProfile;
  912. struct StructChargingSchedulePeriod tmpPeriod;
  913. uint8_t limitMax=0;
  914. uint8_t limitDef=0;
  915. uint8_t limitTx=0;
  916. int compositePeriodIdx = 0;
  917. CurrentTime = time(NULL);
  918. tmComposite=localtime(&CurrentTime);
  919. 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);
  920. if(isUnitA)
  921. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  922. else
  923. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  924. compositeProfile->ChargingSchedule.Duration = durationReq;
  925. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  926. {
  927. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  929. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  930. }
  931. compositeProfile->ChargingProfileId = 0;
  932. compositeProfile->StackLevel = 99 ;
  933. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  934. maxProfile.ChargingProfileId = -1;
  935. defaultTxProfile.ChargingProfileId = -1;
  936. txProfile.ChargingProfileId = -1;
  937. maxProfile.ChargingSchedule.Duration = -1;
  938. defaultTxProfile.ChargingSchedule.Duration = -1;
  939. txProfile.ChargingSchedule.Duration = -1;
  940. system("rm -f /tmp/*.json");
  941. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  942. /*
  943. * Search valid charging profile
  944. */
  945. //DEBUG_INFO("====================================\n");
  946. // Search tx profile
  947. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  948. if((access(profileFileName, F_OK))!=-1)
  949. {
  950. fp = fopen(profileFileName, "r");
  951. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  952. {
  953. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  955. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  956. }
  957. txProfile.ChargingProfileId = -1;
  958. txProfile.StackLevel = -1;
  959. while(getline(&line, &len, fp) != -1)
  960. {
  961. json_object *obj = NULL;
  962. obj = json_tokener_parse(line);
  963. if(is_error(obj))
  964. {
  965. DEBUG_ERROR("Parse txProfile from file error.\n");
  966. }
  967. else
  968. {
  969. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  970. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  971. )
  972. {
  973. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  974. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  975. )
  976. {
  977. struct tm tmFrom, tmTo;
  978. struct timeb tbFrom, tbTo;
  979. 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) &&
  980. (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))
  981. {
  982. tmFrom.tm_year -= 1900;
  983. tmFrom.tm_mon -= 1;
  984. tbFrom.time = mktime(&tmFrom);
  985. tmTo.tm_year -= 1900;
  986. tmTo.tm_mon -= 1;
  987. tbTo.time = mktime(&tmTo);
  988. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  989. {
  990. if(txProfile.ChargingProfileId == -1)
  991. DEBUG_INFO("TxProfile found.\n");
  992. else
  993. DEBUG_INFO("TxProfile updated.\n");
  994. // Required item
  995. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  996. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  997. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  998. if(isUnitA)
  999. {
  1000. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1001. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1002. {
  1003. 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"));
  1004. 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?
  1005. 3:
  1006. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1007. 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")));
  1008. }
  1009. }
  1010. else
  1011. {
  1012. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1013. 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++)
  1014. {
  1015. 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"));
  1016. 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?
  1017. 3:
  1018. 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")));
  1019. 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));
  1020. }
  1021. }
  1022. // Optional item
  1023. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1024. {
  1025. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1026. }
  1027. else
  1028. {
  1029. sprintf((char*)txProfile.ValidFrom, " ");
  1030. }
  1031. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1032. {
  1033. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1034. }
  1035. else
  1036. {
  1037. sprintf((char*)txProfile.ValidTo, " ");
  1038. }
  1039. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1040. {
  1041. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1042. }
  1043. else
  1044. {
  1045. sprintf((char*)txProfile.RecurrencyKind, " ");
  1046. }
  1047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1048. {
  1049. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1050. }
  1051. else
  1052. {
  1053. txProfile.TransactionId = -1;
  1054. }
  1055. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1056. {
  1057. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1058. }
  1059. else
  1060. {
  1061. txProfile.ChargingSchedule.Duration = 86400;
  1062. }
  1063. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1064. {
  1065. 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")));
  1066. }
  1067. else
  1068. {
  1069. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1070. }
  1071. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1072. {
  1073. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1074. }
  1075. else
  1076. {
  1077. txProfile.ChargingSchedule.MinChargingRate = -1;
  1078. }
  1079. }
  1080. }
  1081. }
  1082. else
  1083. {
  1084. if(txProfile.ChargingProfileId == -1)
  1085. DEBUG_INFO("TxProfile found.\n");
  1086. else
  1087. DEBUG_INFO("TxProfile updated.\n");
  1088. // Required item
  1089. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1090. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1091. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1092. if(isUnitA)
  1093. {
  1094. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1095. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1096. {
  1097. 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"));
  1098. 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?
  1099. 3:
  1100. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1101. 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")));
  1102. }
  1103. }
  1104. else
  1105. {
  1106. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1107. 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++)
  1108. {
  1109. 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"));
  1110. 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?
  1111. 3:
  1112. 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")));
  1113. 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));
  1114. }
  1115. }
  1116. // Optional item
  1117. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1118. {
  1119. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1120. }
  1121. else
  1122. {
  1123. sprintf((char*)txProfile.ValidFrom, " ");
  1124. }
  1125. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1126. {
  1127. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1128. }
  1129. else
  1130. {
  1131. sprintf((char*)txProfile.ValidTo, " ");
  1132. }
  1133. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1134. {
  1135. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1136. }
  1137. else
  1138. {
  1139. sprintf((char*)txProfile.RecurrencyKind, " ");
  1140. }
  1141. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1142. {
  1143. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1144. }
  1145. else
  1146. {
  1147. txProfile.TransactionId = -1;
  1148. }
  1149. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1150. {
  1151. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1152. }
  1153. else
  1154. {
  1155. txProfile.ChargingSchedule.Duration = 86400;
  1156. }
  1157. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1158. {
  1159. 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")));
  1160. }
  1161. else
  1162. {
  1163. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1164. }
  1165. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1166. {
  1167. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1168. }
  1169. else
  1170. {
  1171. txProfile.ChargingSchedule.MinChargingRate = -1;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. json_object_put(obj);
  1177. }
  1178. fclose(fp);
  1179. /*
  1180. if(txProfile.ChargingProfileId != -1)
  1181. {
  1182. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1183. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1184. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1185. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1186. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1187. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1188. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1189. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1190. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1191. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1192. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1193. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1194. {
  1195. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1196. {
  1197. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1198. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1199. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1200. }
  1201. }
  1202. }
  1203. else
  1204. DEBUG_INFO("TxProfile not found.\n");*/
  1205. }
  1206. // Search default tx profile
  1207. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1208. if((access(profileFileName, F_OK))==-1)
  1209. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1210. if((access(profileFileName, F_OK))!=-1)
  1211. {
  1212. fp = fopen(profileFileName, "r");
  1213. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1214. {
  1215. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1217. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1218. }
  1219. defaultTxProfile.ChargingProfileId = -1;
  1220. defaultTxProfile.StackLevel = -1;
  1221. while(getline(&line, &len, fp) != -1)
  1222. {
  1223. json_object *obj = NULL;
  1224. obj = json_tokener_parse(line);
  1225. if(is_error(obj))
  1226. {
  1227. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1228. }
  1229. else
  1230. {
  1231. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1232. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1233. )
  1234. {
  1235. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1236. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1237. )
  1238. {
  1239. struct tm tmFrom, tmTo;
  1240. struct timeb tbFrom, tbTo;
  1241. 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) &&
  1242. (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))
  1243. {
  1244. tmFrom.tm_year -= 1900;
  1245. tmFrom.tm_mon -= 1;
  1246. tbFrom.time = mktime(&tmFrom);
  1247. tmTo.tm_year -= 1900;
  1248. tmTo.tm_mon -= 1;
  1249. tbTo.time = mktime(&tmTo);
  1250. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1251. {
  1252. if(defaultTxProfile.ChargingProfileId == -1)
  1253. DEBUG_INFO("TxDefaultProfile found.\n");
  1254. else
  1255. DEBUG_INFO("TxDefaultProfile updated.\n");
  1256. // Required item
  1257. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1258. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1259. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1260. if(isUnitA)
  1261. {
  1262. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1263. 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++)
  1264. {
  1265. 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"));
  1266. 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?
  1267. 3:
  1268. 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")));
  1269. 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")));
  1270. }
  1271. }
  1272. else
  1273. {
  1274. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1275. 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++)
  1276. {
  1277. 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"));
  1278. 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?
  1279. 3:
  1280. 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")));
  1281. 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));
  1282. }
  1283. }
  1284. // Optional item
  1285. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1286. {
  1287. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1288. }
  1289. else
  1290. {
  1291. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1292. }
  1293. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1294. {
  1295. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1296. }
  1297. else
  1298. {
  1299. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1300. }
  1301. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1302. {
  1303. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1304. }
  1305. else
  1306. {
  1307. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1308. }
  1309. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1310. {
  1311. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1312. }
  1313. else
  1314. {
  1315. defaultTxProfile.TransactionId = -1;
  1316. }
  1317. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1318. {
  1319. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1320. }
  1321. else
  1322. {
  1323. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1324. }
  1325. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1326. {
  1327. 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")));
  1328. }
  1329. else
  1330. {
  1331. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1332. }
  1333. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1334. {
  1335. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1336. }
  1337. else
  1338. {
  1339. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1340. }
  1341. }
  1342. }
  1343. }
  1344. else
  1345. {
  1346. if(defaultTxProfile.ChargingProfileId == -1)
  1347. DEBUG_INFO("TxDefaultProfile found.\n");
  1348. else
  1349. DEBUG_INFO("TxDefaultProfile updated.\n");
  1350. // Required item
  1351. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1352. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1353. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1354. if(isUnitA)
  1355. {
  1356. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1357. 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++)
  1358. {
  1359. 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"));
  1360. 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?
  1361. 3:
  1362. 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")));
  1363. 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")));
  1364. }
  1365. }
  1366. else
  1367. {
  1368. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1369. 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++)
  1370. {
  1371. 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"));
  1372. 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?
  1373. 3:
  1374. 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")));
  1375. 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));
  1376. }
  1377. }
  1378. // Optional item
  1379. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1380. {
  1381. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1382. }
  1383. else
  1384. {
  1385. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1386. }
  1387. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1388. {
  1389. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1390. }
  1391. else
  1392. {
  1393. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1394. }
  1395. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1396. {
  1397. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1398. }
  1399. else
  1400. {
  1401. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1402. }
  1403. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1404. {
  1405. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1406. }
  1407. else
  1408. {
  1409. defaultTxProfile.TransactionId = -1;
  1410. }
  1411. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1412. {
  1413. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1414. }
  1415. else
  1416. {
  1417. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1418. }
  1419. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1420. {
  1421. 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")));
  1422. }
  1423. else
  1424. {
  1425. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1426. }
  1427. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1428. {
  1429. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1430. }
  1431. else
  1432. {
  1433. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1434. }
  1435. }
  1436. }
  1437. }
  1438. json_object_put(obj);
  1439. }
  1440. fclose(fp);
  1441. /*
  1442. if(defaultTxProfile.ChargingProfileId != -1)
  1443. {
  1444. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1445. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1446. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1447. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1448. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1449. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1450. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1451. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1452. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1453. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1454. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1456. {
  1457. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1458. {
  1459. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1460. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1461. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1462. }
  1463. }
  1464. }
  1465. else
  1466. DEBUG_INFO("TxDefaultProfile not found.\n");
  1467. DEBUG_INFO("------------------------------------\n");*/
  1468. }
  1469. // Search max profile
  1470. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1471. if((access(profileFileName, F_OK))!=-1)
  1472. {
  1473. fp = fopen(profileFileName, "r");
  1474. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1475. {
  1476. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1478. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1479. }
  1480. maxProfile.ChargingProfileId = -1;
  1481. maxProfile.StackLevel = -1;
  1482. while(getline(&line, &len, fp) != -1)
  1483. {
  1484. json_object *obj = NULL;
  1485. obj = json_tokener_parse(line);
  1486. if(is_error(obj))
  1487. {
  1488. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1489. }
  1490. else
  1491. {
  1492. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1493. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1494. )
  1495. {
  1496. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1497. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1498. )
  1499. {
  1500. struct tm tmFrom, tmTo;
  1501. struct timeb tbFrom, tbTo;
  1502. 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) &&
  1503. (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))
  1504. {
  1505. tmFrom.tm_year -= 1900;
  1506. tmFrom.tm_mon -= 1;
  1507. tbFrom.time = mktime(&tmFrom);
  1508. tmTo.tm_year -= 1900;
  1509. tmTo.tm_mon -= 1;
  1510. tbTo.time = mktime(&tmTo);
  1511. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1512. {
  1513. if(maxProfile.ChargingProfileId == -1)
  1514. DEBUG_INFO("MaxProfile found.\n");
  1515. else
  1516. DEBUG_INFO("MaxProfile updated.\n");
  1517. // Required item
  1518. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1519. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1520. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1521. if(isUnitA)
  1522. {
  1523. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1524. 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++)
  1525. {
  1526. 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"));
  1527. 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?
  1528. 3:
  1529. 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")));
  1530. 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")));
  1531. }
  1532. }
  1533. else
  1534. {
  1535. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1536. 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++)
  1537. {
  1538. 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"));
  1539. 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?
  1540. 3:
  1541. 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")));
  1542. 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));
  1543. }
  1544. }
  1545. // Optional item
  1546. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1547. {
  1548. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1549. }
  1550. else
  1551. {
  1552. sprintf((char*)maxProfile.ValidFrom, " ");
  1553. }
  1554. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1555. {
  1556. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1557. }
  1558. else
  1559. {
  1560. sprintf((char*)maxProfile.ValidTo, " ");
  1561. }
  1562. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1563. {
  1564. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1565. }
  1566. else
  1567. {
  1568. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1569. }
  1570. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1571. {
  1572. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1573. }
  1574. else
  1575. {
  1576. maxProfile.TransactionId = -1;
  1577. }
  1578. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1579. {
  1580. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1581. }
  1582. else
  1583. {
  1584. maxProfile.ChargingSchedule.Duration = 86400;
  1585. }
  1586. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1587. {
  1588. 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")));
  1589. }
  1590. else
  1591. {
  1592. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1593. }
  1594. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1595. {
  1596. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1597. }
  1598. else
  1599. {
  1600. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1601. }
  1602. }
  1603. }
  1604. }
  1605. else
  1606. {
  1607. if(maxProfile.ChargingProfileId == -1)
  1608. DEBUG_INFO("MaxProfile found.\n");
  1609. else
  1610. DEBUG_INFO("MaxProfile updated.\n");
  1611. // Required item
  1612. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1613. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1614. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1615. if(isUnitA)
  1616. {
  1617. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1618. 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++)
  1619. {
  1620. 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"));
  1621. 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?
  1622. 3:
  1623. 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")));
  1624. 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")));
  1625. }
  1626. }
  1627. else
  1628. {
  1629. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1630. 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++)
  1631. {
  1632. 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"));
  1633. 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?
  1634. 3:
  1635. 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")));
  1636. 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));
  1637. }
  1638. }
  1639. // Optional item
  1640. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1641. {
  1642. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1643. }
  1644. else
  1645. {
  1646. sprintf((char*)maxProfile.ValidFrom, " ");
  1647. }
  1648. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1649. {
  1650. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1651. }
  1652. else
  1653. {
  1654. sprintf((char*)maxProfile.ValidTo, " ");
  1655. }
  1656. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1657. {
  1658. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1659. }
  1660. else
  1661. {
  1662. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1663. }
  1664. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1665. {
  1666. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1667. }
  1668. else
  1669. {
  1670. maxProfile.TransactionId = -1;
  1671. }
  1672. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1673. {
  1674. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1675. }
  1676. else
  1677. {
  1678. maxProfile.ChargingSchedule.Duration = 86400;
  1679. }
  1680. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1681. {
  1682. 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")));
  1683. }
  1684. else
  1685. {
  1686. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1687. }
  1688. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1689. {
  1690. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1691. }
  1692. else
  1693. {
  1694. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1695. }
  1696. }
  1697. }
  1698. }
  1699. json_object_put(obj);
  1700. }
  1701. fclose(fp);
  1702. /*
  1703. if(maxProfile.ChargingProfileId !=-1)
  1704. {
  1705. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1706. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1707. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1708. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1709. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1710. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1711. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1712. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1713. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1714. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1715. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1717. {
  1718. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1719. {
  1720. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1721. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1722. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1723. }
  1724. }
  1725. }
  1726. else
  1727. DEBUG_INFO("MaxProfile not found.\n");
  1728. DEBUG_INFO("------------------------------------\n");*/
  1729. }
  1730. /*
  1731. * Align found profile start schedule & periods
  1732. */
  1733. //DEBUG_INFO("====================================\n");
  1734. /*
  1735. // For local test usage, force modify found profile start schedule info
  1736. 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);
  1737. 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);
  1738. 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);
  1739. */
  1740. if(txProfile.ChargingProfileId != -1)
  1741. {
  1742. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1743. {
  1744. if(txProfile.ChargingSchedule.Duration != -1)
  1745. {
  1746. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1747. 0:
  1748. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1749. }
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1753. {
  1754. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1755. 0:
  1756. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1757. if(idxPeriod > 0)
  1758. {
  1759. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1760. {
  1761. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1762. }
  1763. }
  1764. }
  1765. }
  1766. }
  1767. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1768. {
  1769. if(txProfile.ChargingSchedule.Duration != -1)
  1770. {
  1771. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1772. 0:
  1773. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1774. }
  1775. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1776. {
  1777. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1778. {
  1779. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1780. 0:
  1781. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1782. if(idxPeriod > 0)
  1783. {
  1784. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1785. {
  1786. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1787. }
  1788. }
  1789. }
  1790. }
  1791. }
  1792. else
  1793. {
  1794. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1795. {
  1796. if(txProfile.ChargingSchedule.Duration != -1)
  1797. {
  1798. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1799. 0:
  1800. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1801. }
  1802. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1803. {
  1804. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1805. {
  1806. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1807. 0:
  1808. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1809. if(idxPeriod > 0)
  1810. {
  1811. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1812. {
  1813. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1814. }
  1815. }
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(txProfile.ChargingSchedule.Duration != -1)
  1822. {
  1823. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1824. 0:
  1825. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1826. }
  1827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1828. {
  1829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1830. {
  1831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1832. 0:
  1833. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1834. if(idxPeriod > 0)
  1835. {
  1836. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1837. {
  1838. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. }
  1845. /*
  1846. DEBUG_INFO("txProfile after align.\n");
  1847. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1848. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1849. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1850. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1851. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1852. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1853. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1854. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1855. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1856. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1857. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1858. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1859. {
  1860. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1861. {
  1862. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1863. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1864. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1865. }
  1866. }*/
  1867. }
  1868. if(defaultTxProfile.ChargingProfileId != -1)
  1869. {
  1870. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1871. {
  1872. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1873. {
  1874. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1875. 0:
  1876. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1877. }
  1878. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1879. {
  1880. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1881. {
  1882. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1883. 0:
  1884. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1885. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1886. {
  1887. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1888. }
  1889. if(idxPeriod > 0)
  1890. {
  1891. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1892. {
  1893. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1894. }
  1895. }
  1896. }
  1897. }
  1898. }
  1899. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1900. {
  1901. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1902. {
  1903. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1904. 0:
  1905. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1906. }
  1907. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1908. {
  1909. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1910. {
  1911. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1912. 0:
  1913. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1914. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1915. {
  1916. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1917. }
  1918. if(idxPeriod > 0)
  1919. {
  1920. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1921. {
  1922. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1923. }
  1924. }
  1925. }
  1926. }
  1927. }
  1928. else
  1929. {
  1930. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1931. {
  1932. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1933. {
  1934. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1935. 0:
  1936. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1937. }
  1938. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1939. {
  1940. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1941. {
  1942. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1943. 0:
  1944. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1945. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1946. {
  1947. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1948. }
  1949. if(idxPeriod > 0)
  1950. {
  1951. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1952. {
  1953. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1954. }
  1955. }
  1956. }
  1957. }
  1958. }
  1959. else
  1960. {
  1961. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1962. {
  1963. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1964. 0:
  1965. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1966. }
  1967. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1968. {
  1969. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1970. {
  1971. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1972. 0:
  1973. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1974. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1975. {
  1976. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1977. }
  1978. if(idxPeriod > 0)
  1979. {
  1980. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1981. {
  1982. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1983. }
  1984. }
  1985. }
  1986. }
  1987. }
  1988. }
  1989. /*
  1990. DEBUG_INFO("defaultTxProfile after align.\n");
  1991. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1992. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1993. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1994. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1995. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1996. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1997. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1998. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1999. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2000. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2001. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2002. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2003. {
  2004. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2005. {
  2006. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2007. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2008. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2009. }
  2010. }
  2011. DEBUG_INFO("------------------------------------\n");*/
  2012. }
  2013. if(maxProfile.ChargingProfileId != -1)
  2014. {
  2015. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2016. {
  2017. if(maxProfile.ChargingSchedule.Duration != -1)
  2018. {
  2019. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2020. 0:
  2021. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2022. }
  2023. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2024. {
  2025. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2026. {
  2027. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2028. 0:
  2029. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2030. if(idxPeriod > 0)
  2031. {
  2032. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2033. {
  2034. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2035. }
  2036. }
  2037. }
  2038. }
  2039. }
  2040. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2041. {
  2042. if(maxProfile.ChargingSchedule.Duration != -1)
  2043. {
  2044. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2045. 0:
  2046. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2047. }
  2048. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2049. {
  2050. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2051. {
  2052. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16DataPH->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2053. 0:
  2054. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2055. if(idxPeriod > 0)
  2056. {
  2057. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2058. {
  2059. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. else
  2066. {
  2067. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2068. {
  2069. if(maxProfile.ChargingSchedule.Duration != -1)
  2070. {
  2071. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2072. 0:
  2073. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2074. }
  2075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2076. {
  2077. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2078. {
  2079. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2080. 0:
  2081. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2082. if(idxPeriod > 0)
  2083. {
  2084. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2085. {
  2086. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2087. }
  2088. }
  2089. }
  2090. }
  2091. }
  2092. else
  2093. {
  2094. if(maxProfile.ChargingSchedule.Duration != -1)
  2095. {
  2096. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2097. 0:
  2098. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2099. }
  2100. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2101. {
  2102. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2103. {
  2104. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2105. 0:
  2106. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2107. if(idxPeriod > 0)
  2108. {
  2109. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2110. {
  2111. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2112. }
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. /*
  2119. DEBUG_INFO("MaxProfile after align.\n");
  2120. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2121. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2122. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2123. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2124. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2125. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2126. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2127. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2128. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2129. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2130. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2131. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2132. {
  2133. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2134. {
  2135. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2136. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2137. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2138. }
  2139. }
  2140. DEBUG_INFO("------------------------------------\n");*/
  2141. }
  2142. /*
  2143. * Merge to conposite schedule
  2144. */
  2145. //DEBUG_INFO("====================================\n");
  2146. // Find each profile period quantity
  2147. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2148. {
  2149. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2150. limitMax = idx+1;
  2151. }
  2152. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2153. {
  2154. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2155. limitDef = idx+1;
  2156. }
  2157. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2158. {
  2159. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2160. limitTx = idx+1;
  2161. }
  2162. // TxProfile found, composite schedule based on it
  2163. if(txProfile.ChargingProfileId != -1)
  2164. {
  2165. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2166. {
  2167. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2168. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2169. (txProfile.ChargingSchedule.Duration > 0))
  2170. {
  2171. if(maxProfile.ChargingProfileId != -1)
  2172. {
  2173. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2174. {
  2175. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2176. {
  2177. if((maxProfile.ChargingSchedule.Duration > 0))
  2178. {
  2179. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2180. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2181. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2182. }
  2183. else
  2184. {
  2185. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2186. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2187. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2188. }
  2189. }
  2190. if(idxMaxPeriod == (limitMax-1))
  2191. {
  2192. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2193. {
  2194. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2195. {
  2196. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2197. compositePeriodIdx++;
  2198. }
  2199. else
  2200. {
  2201. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. else
  2208. {
  2209. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2210. {
  2211. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2212. compositePeriodIdx++;
  2213. }
  2214. else
  2215. {
  2216. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2217. }
  2218. }
  2219. }
  2220. if(idxTxPeriod == (limitTx-1))
  2221. {
  2222. if(defaultTxProfile.ChargingProfileId != -1)
  2223. {
  2224. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2225. {
  2226. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2227. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2228. (defaultTxProfile.ChargingSchedule.Duration>0))
  2229. {
  2230. if(maxProfile.ChargingProfileId != -1)
  2231. {
  2232. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2233. {
  2234. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2235. {
  2236. if((maxProfile.ChargingSchedule.Duration > 0))
  2237. {
  2238. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2239. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2240. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2241. }
  2242. else
  2243. {
  2244. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2245. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2246. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2247. }
  2248. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2249. {
  2250. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2251. {
  2252. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2253. compositePeriodIdx++;
  2254. }
  2255. else
  2256. {
  2257. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2258. }
  2259. }
  2260. // Delete duplicate period
  2261. if(compositePeriodIdx > 1)
  2262. {
  2263. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2264. {
  2265. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2266. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2267. compositePeriodIdx -= 1;
  2268. }
  2269. }
  2270. }
  2271. else
  2272. break;
  2273. }
  2274. }
  2275. else
  2276. {
  2277. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2278. {
  2279. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2280. compositePeriodIdx++;
  2281. }
  2282. else
  2283. {
  2284. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2285. }
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. }
  2293. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2294. else if(defaultTxProfile.ChargingProfileId != -1)
  2295. {
  2296. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2297. {
  2298. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2299. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2300. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2301. {
  2302. if(maxProfile.ChargingProfileId != -1)
  2303. {
  2304. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2305. {
  2306. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2307. {
  2308. if((maxProfile.ChargingSchedule.Duration > 0))
  2309. {
  2310. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2311. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2312. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2313. }
  2314. else
  2315. {
  2316. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2317. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2318. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2319. }
  2320. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2321. {
  2322. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2323. {
  2324. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2325. compositePeriodIdx++;
  2326. }
  2327. else
  2328. {
  2329. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2330. }
  2331. }
  2332. // Delete duplicate period
  2333. if(compositePeriodIdx > 1)
  2334. {
  2335. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2336. {
  2337. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2338. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2339. compositePeriodIdx -= 1;
  2340. }
  2341. }
  2342. }
  2343. else
  2344. break;
  2345. }
  2346. }
  2347. else
  2348. {
  2349. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2350. {
  2351. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2352. compositePeriodIdx++;
  2353. }
  2354. else
  2355. {
  2356. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2357. }
  2358. }
  2359. }
  2360. }
  2361. }
  2362. // Fill other period by MaxProfile
  2363. if(maxProfile.ChargingProfileId != -1)
  2364. {
  2365. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2366. {
  2367. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2368. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2369. (maxProfile.ChargingSchedule.Duration > 0))
  2370. {
  2371. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2372. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2373. {
  2374. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2375. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2376. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2377. }
  2378. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2379. {
  2380. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2381. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2382. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2383. }
  2384. if(tmpPeriod.Limit != -1)
  2385. {
  2386. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2387. {
  2388. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2389. {
  2390. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2391. compositePeriodIdx++;
  2392. }
  2393. else
  2394. {
  2395. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2396. }
  2397. }
  2398. // Delete duplicate period
  2399. if(compositePeriodIdx > 1)
  2400. {
  2401. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2402. {
  2403. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2404. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2405. compositePeriodIdx -= 1;
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2413. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2414. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2415. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2416. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2417. {
  2418. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2419. {
  2420. compositeProfile->ChargingProfileId = 1;
  2421. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2422. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2423. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2424. }
  2425. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2426. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2427. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2428. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2429. }
  2430. if(line)
  2431. free(line);
  2432. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2433. }
  2434. //==========================================
  2435. // Init all share memory
  2436. //==========================================
  2437. int InitShareMemory()
  2438. {
  2439. int result = PASS;
  2440. int MeterSMId;
  2441. //creat ShmSysConfigAndInfo
  2442. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2443. {
  2444. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2445. result = FAIL;
  2446. }
  2447. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2448. {
  2449. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2450. result = FAIL;
  2451. }
  2452. else
  2453. {}
  2454. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2455. {
  2456. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2457. result = FAIL;
  2458. }
  2459. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2460. {
  2461. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2462. result = FAIL;
  2463. }
  2464. else
  2465. {}
  2466. //creat ShmPsuData
  2467. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2468. {
  2469. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2470. result = FAIL;
  2471. }
  2472. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2473. {
  2474. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2475. result = FAIL;
  2476. }
  2477. else
  2478. {}
  2479. //link ShmOCPP16Data
  2480. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2481. {
  2482. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2483. result = FAIL;
  2484. }
  2485. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2486. {
  2487. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2488. result = FAIL;
  2489. }
  2490. else
  2491. {}
  2492. //creat ShmOCPP16DataPH
  2493. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  2494. {
  2495. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  2496. result = FAIL;
  2497. }
  2498. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2499. {
  2500. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  2501. result = FAIL;
  2502. }
  2503. else
  2504. {}
  2505. /****************************** For Initial Settings************************************************/
  2506. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  2507. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  2508. // allocate Configuration memory address
  2509. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  2510. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2511. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2512. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2513. //offline MeterValue Interval
  2514. TempMeterValueInterval = 0;
  2515. return result;
  2516. }
  2517. int ProcessShareMemory()
  2518. {
  2519. if(InitShareMemory() == FAIL)
  2520. {
  2521. DEBUG_ERROR("InitShareMemory NG\n");
  2522. if(ShmStatusCodeData!=NULL)
  2523. {
  2524. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2525. }
  2526. sleep(5);
  2527. return FAIL;
  2528. }
  2529. return PASS;
  2530. }
  2531. void CheckSystemValue(void)
  2532. {
  2533. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2534. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2535. char filenmae[100]={0};
  2536. char str[100]={0};
  2537. int tempIndex = 0;
  2538. //===============================
  2539. // send Heartbeat
  2540. //===============================
  2541. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  2542. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2543. {
  2544. clientTime.Heartbeat=time((time_t*)NULL);
  2545. if(server_sign == TRUE)
  2546. {
  2547. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  2548. }
  2549. else
  2550. {
  2551. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2552. }
  2553. }
  2554. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2555. {
  2556. //parameter for test
  2557. sendHeartbeatRequest(0);
  2558. //==============================================
  2559. // Reset Waiting Time
  2560. //==============================================
  2561. HeartBeatWithNOResponse += 2;
  2562. }
  2563. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2564. {
  2565. //==========================================
  2566. // csu trigger DataTransferReq
  2567. //==========================================
  2568. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  2569. {
  2570. sendDataTransferRequest(gun_index);
  2571. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  2572. }
  2573. //===============================
  2574. // CSU Trigger Authorize Request
  2575. //===============================
  2576. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2577. {
  2578. sendAuthorizeRequest(0);
  2579. authorizeRetryTimes = authorizeRetryTimes + 1;
  2580. if(authorizeRetryTimes < 3)
  2581. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  2582. }
  2583. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2584. {
  2585. authorizeRetryTimes = 0;
  2586. SetOcppConnStatus(FALSE);
  2587. server_sign = FALSE;
  2588. }
  2589. 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))
  2590. {
  2591. sendAuthorizeRequest(0);
  2592. }
  2593. //==============================================
  2594. // CSU Trigger Smart Charging Profilw
  2595. //==============================================
  2596. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2597. {
  2598. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  2599. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2600. }
  2601. //==============================================
  2602. // Charger start transaction
  2603. //==============================================
  2604. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2605. {
  2606. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2607. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  2608. sendStartTransactionRequest(gun_index);
  2609. clientTime.StartTransaction = time((time_t*)NULL);
  2610. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2611. storeTempStopTransaction(gun_index);
  2612. }
  2613. //==============================================
  2614. // Charger stop transaction
  2615. //==============================================
  2616. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2617. {
  2618. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2619. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  2620. sendStopTransactionRequest(gun_index);
  2621. clientTime.StopTransaction = time((time_t*)NULL);
  2622. }
  2623. //==============================================
  2624. // Charger status report
  2625. //==============================================
  2626. //--- Check Mode Change ---//
  2627. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2628. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2629. {
  2630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2631. {
  2632. tempIndex = ((gun_index==2) ? 1: 0);
  2633. }
  2634. else
  2635. {
  2636. tempIndex = gun_index;
  2637. }
  2638. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2639. {
  2640. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2641. {
  2642. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2643. {
  2644. // Sent unplug message for California pricing logic
  2645. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2646. {
  2647. uint8_t ts[20];
  2648. getNowDatetime(ts);
  2649. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2650. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2651. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2652. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2653. }
  2654. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2655. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2656. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2657. }
  2658. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2659. {
  2660. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2661. if((access(filenmae,F_OK))!=-1)
  2662. {
  2663. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2664. sprintf(str,"rm -f %s",filenmae);
  2665. system(str);
  2666. }
  2667. }
  2668. #if 1 // for TempStopTransaction
  2669. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2670. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2671. {
  2672. checkTempStopTransaction(gun_index);
  2673. }
  2674. #endif
  2675. }
  2676. }
  2677. }
  2678. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2679. {
  2680. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2681. {
  2682. tempIndex = ((gun_index==2) ? 1: 0);
  2683. }
  2684. else
  2685. {
  2686. tempIndex = gun_index;
  2687. }
  2688. for (int index = 0; index < CCS_QUANTITY; index++)
  2689. {
  2690. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2691. {
  2692. 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]*/ )
  2693. {
  2694. // Sent unplug message for California pricing logic
  2695. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2696. {
  2697. uint8_t ts[20];
  2698. getNowDatetime(ts);
  2699. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2700. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2701. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2702. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2703. }
  2704. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2705. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2706. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2707. }
  2708. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2709. {
  2710. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2711. if((access(filenmae,F_OK))!=-1)
  2712. {
  2713. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2714. sprintf(str,"rm -f %s",filenmae);
  2715. system(str);
  2716. }
  2717. }
  2718. #if 1 // for TempStopTransaction
  2719. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2720. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2721. {
  2722. checkTempStopTransaction(gun_index);
  2723. }
  2724. #endif
  2725. }
  2726. }
  2727. }
  2728. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2729. {
  2730. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2731. {
  2732. tempIndex = ((gun_index==2) ? 1: 0);
  2733. }
  2734. else
  2735. {
  2736. tempIndex = gun_index;
  2737. }
  2738. for (int index = 0; index < GB_QUANTITY; index++)
  2739. {
  2740. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2741. {
  2742. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2743. {
  2744. // Sent unplug message for California pricing logic
  2745. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2746. {
  2747. uint8_t ts[20];
  2748. getNowDatetime(ts);
  2749. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2750. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2751. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2752. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2753. }
  2754. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2755. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2756. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2757. }
  2758. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2759. {
  2760. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2761. if((access(filenmae,F_OK))!=-1)
  2762. {
  2763. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2764. sprintf(str,"rm -f %s",filenmae);
  2765. system(str);
  2766. }
  2767. }
  2768. #if 1 // for TempStopTransaction
  2769. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2770. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2771. {
  2772. checkTempStopTransaction(gun_index);
  2773. }
  2774. #endif
  2775. }
  2776. }
  2777. }
  2778. else if(gunType[gun_index] == GUN_TYPE_DO)
  2779. {
  2780. tempIndex = gun_index;
  2781. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2782. {
  2783. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2784. {
  2785. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2786. {
  2787. // Sent unplug message for California pricing logic
  2788. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2789. {
  2790. uint8_t ts[20];
  2791. getNowDatetime(ts);
  2792. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2793. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2794. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2795. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2796. }
  2797. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2798. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2799. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2800. }
  2801. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2802. {
  2803. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2804. if((access(filenmae,F_OK))!=-1)
  2805. {
  2806. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2807. sprintf(str,"rm -f %s",filenmae);
  2808. system(str);
  2809. }
  2810. }
  2811. #if 1 // for TempStopTransaction
  2812. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2813. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2814. {
  2815. checkTempStopTransaction(gun_index);
  2816. }
  2817. #endif
  2818. }
  2819. }
  2820. }
  2821. else
  2822. {
  2823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2824. {
  2825. tempIndex = 2;
  2826. }
  2827. else
  2828. {
  2829. tempIndex = gun_index;
  2830. }
  2831. for (int index = 0; index < AC_QUANTITY; index++)
  2832. {
  2833. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2834. {
  2835. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2836. {
  2837. // Sent unplug message for California pricing logic
  2838. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2839. {
  2840. uint8_t ts[20];
  2841. getNowDatetime(ts);
  2842. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2843. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2844. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2845. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2846. }
  2847. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2848. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2849. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2850. }
  2851. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2852. {
  2853. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2854. if((access(filenmae,F_OK))!=-1)
  2855. {
  2856. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2857. sprintf(str,"rm -f %s",filenmae);
  2858. system(str);
  2859. }
  2860. }
  2861. #if 1 // for TempStopTransaction
  2862. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2863. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2864. {
  2865. checkTempStopTransaction(gun_index);
  2866. }
  2867. #endif
  2868. }
  2869. }// END
  2870. }
  2871. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  2872. (
  2873. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  2874. )
  2875. )
  2876. {
  2877. if(SystemInitial > 0)
  2878. SystemInitial -= 1;
  2879. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  2880. sendStatusNotificationRequest(gun_index);
  2881. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2882. }
  2883. //==============================================
  2884. // Meter report
  2885. //==============================================
  2886. // Trigger MeterValue
  2887. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2888. {
  2889. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2890. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2891. }
  2892. // ClockAlign MeterValue
  2893. 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))
  2894. {
  2895. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2896. {
  2897. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2898. {
  2899. tempIndex = ((gun_index==2) ? 1: 0);
  2900. }
  2901. else
  2902. {
  2903. tempIndex = gun_index;
  2904. }
  2905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2906. {
  2907. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2908. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2909. {
  2910. reqClockAlignMeter[gun_index] = 1;
  2911. }
  2912. }// End for CHAdeMO
  2913. }
  2914. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2915. {
  2916. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2917. {
  2918. tempIndex = ((gun_index==2) ? 1: 0);
  2919. }
  2920. else
  2921. {
  2922. tempIndex = gun_index;
  2923. }
  2924. for (int index = 0; index < CCS_QUANTITY; index++)
  2925. {
  2926. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2927. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2928. {
  2929. reqClockAlignMeter[gun_index] = 1;
  2930. }
  2931. } // End for CCS
  2932. }
  2933. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2934. {
  2935. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2936. {
  2937. tempIndex = ((gun_index==2) ? 1: 0);
  2938. }
  2939. else
  2940. {
  2941. tempIndex = gun_index;
  2942. }
  2943. for (int index = 0; index < GB_QUANTITY; index++)
  2944. {
  2945. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2946. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2947. {
  2948. reqClockAlignMeter[gun_index] = 1;
  2949. }
  2950. }// End for GB
  2951. }
  2952. else if(gunType[gun_index] == GUN_TYPE_DO)
  2953. {
  2954. tempIndex = gun_index;
  2955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2956. {
  2957. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2958. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2959. {
  2960. reqClockAlignMeter[gun_index] = 1;
  2961. }
  2962. }
  2963. }
  2964. else
  2965. {
  2966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2967. {
  2968. tempIndex = 2;
  2969. }
  2970. else
  2971. {
  2972. tempIndex = gun_index;
  2973. }
  2974. for (int index = 0; index < AC_QUANTITY; index++)
  2975. {
  2976. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2977. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2978. {
  2979. reqClockAlignMeter[gun_index] = 1;
  2980. }
  2981. }//End for AC
  2982. }
  2983. if(reqClockAlignMeter[gun_index] == 1)
  2984. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2985. }
  2986. // Sample period MeterValue
  2987. 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))))
  2988. {
  2989. //check Transaction active
  2990. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2991. {
  2992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2993. {
  2994. tempIndex = ((gun_index==2) ? 1: 0);
  2995. }
  2996. else
  2997. {
  2998. tempIndex = gun_index;
  2999. }
  3000. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3001. {
  3002. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3003. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3004. {
  3005. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3006. {
  3007. reqSampleMeter[gun_index] = 1;
  3008. }
  3009. }
  3010. }// End for CHAdeMO
  3011. }
  3012. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3013. {
  3014. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3015. {
  3016. tempIndex = ((gun_index==2) ? 1: 0);
  3017. }
  3018. else
  3019. {
  3020. tempIndex = gun_index;
  3021. }
  3022. for (int index = 0; index < CCS_QUANTITY; index++)
  3023. {
  3024. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3025. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3026. {
  3027. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3028. {
  3029. reqSampleMeter[gun_index] = 1;
  3030. }
  3031. }
  3032. } // End for CCS
  3033. }
  3034. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3035. {
  3036. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3037. {
  3038. tempIndex = ((gun_index==2) ? 1: 0);
  3039. }
  3040. else
  3041. {
  3042. tempIndex = gun_index;
  3043. }
  3044. for (int index = 0; index < GB_QUANTITY; index++)
  3045. {
  3046. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3047. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3048. {
  3049. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3050. {
  3051. reqSampleMeter[gun_index] = 1;
  3052. }
  3053. }
  3054. }// End for GB
  3055. }
  3056. else if(gunType[gun_index] == GUN_TYPE_DO)
  3057. {
  3058. tempIndex = gun_index;
  3059. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3060. {
  3061. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3062. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3063. {
  3064. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3065. {
  3066. reqSampleMeter[gun_index] = 1;
  3067. }
  3068. }
  3069. }
  3070. }
  3071. else
  3072. {
  3073. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3074. {
  3075. tempIndex = 2;
  3076. }
  3077. else
  3078. {
  3079. tempIndex = gun_index;
  3080. }
  3081. for (int index = 0; index < AC_QUANTITY; index++)
  3082. {
  3083. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3084. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3085. {
  3086. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3087. {
  3088. reqSampleMeter[gun_index] = 1;
  3089. }
  3090. }
  3091. }//End for AC
  3092. }
  3093. if(reqSampleMeter[gun_index] == 1)
  3094. {
  3095. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3096. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3097. storeTempStopTransaction(gun_index);
  3098. }
  3099. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3100. }
  3101. //==============================================
  3102. // Check Connector reserved
  3103. //==============================================
  3104. //===============================
  3105. // Check if Reserve is expired
  3106. //===============================
  3107. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3108. {
  3109. double diff_t;
  3110. struct tm tp;
  3111. // current time
  3112. time_t t = time(NULL);
  3113. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3114. tp.tm_isdst = -1;
  3115. time_t utc = mktime(&tp);
  3116. diff_t = difftime(utc, t);
  3117. if(diff_t <= 0)
  3118. {
  3119. DEBUG_INFO("reserve expired.\n");
  3120. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3121. }
  3122. }//END OF Check if Reserve is expired
  3123. //==========================================
  3124. // csu trigger FirmwareStatusNotificationReq
  3125. //==========================================
  3126. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3127. {
  3128. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3129. }
  3130. //==========================================
  3131. // csu trigger DiagnosticsStatusNotificationReq
  3132. //==========================================
  3133. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3134. {
  3135. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3136. }
  3137. //==========================================
  3138. // csu trigger CancelReservationConf
  3139. //==========================================
  3140. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3141. {
  3142. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3143. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3144. }
  3145. //==========================================
  3146. // csu trigger ChangeAvailabilityConf
  3147. //==========================================
  3148. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3149. {
  3150. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3151. }
  3152. //==========================================
  3153. // csu trigger UnlockConnectorConf
  3154. //==========================================
  3155. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3156. {
  3157. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3158. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3159. }
  3160. //==========================================
  3161. // csu trigger ReserveNowConf
  3162. //==========================================
  3163. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3164. {
  3165. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3166. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3167. }
  3168. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3169. {
  3170. sendSignCertificateRequest();
  3171. }
  3172. }
  3173. }
  3174. //==========================================
  3175. // send request routine
  3176. //==========================================
  3177. int sendAuthorizeRequest(int gun_index)
  3178. {
  3179. mtrace();
  3180. int result = FAIL;
  3181. char message[100]={0};
  3182. char guid[37];
  3183. char tempdata[65]={0};
  3184. DEBUG_INFO("sendAuthorizeRequest...\n");
  3185. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3186. //Local Authorize
  3187. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3188. {
  3189. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3190. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3191. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3192. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3193. result = PASS;
  3194. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3195. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3196. authorizeRetryTimes = 0;
  3197. return result;
  3198. }
  3199. 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))||
  3200. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3201. {
  3202. // Query from cache
  3203. DEBUG_INFO("Authorize from cache.\n");
  3204. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3205. // Query from list
  3206. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3207. {
  3208. DEBUG_INFO("Authorize from list.\n");
  3209. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3210. }
  3211. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3212. {
  3213. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3214. {
  3215. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3216. }
  3217. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3218. {
  3219. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3220. }
  3221. if(!GetOcppConnStatus())
  3222. {
  3223. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3224. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3225. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3226. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3227. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3228. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3229. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3230. authorizeRetryTimes = 0;
  3231. return result;
  3232. }
  3233. }
  3234. else
  3235. {
  3236. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3237. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3238. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3239. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3240. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3241. else
  3242. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3243. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3244. result = PASS;
  3245. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3246. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3247. authorizeRetryTimes = 0;
  3248. return result;
  3249. }
  3250. }
  3251. //initialize struct Authorize
  3252. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3253. //get data from shared memory
  3254. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3255. random_uuid(guid);
  3256. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3257. LWS_Send(message);
  3258. sprintf(tempdata, "Authorize,%d", gun_index);
  3259. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3260. {
  3261. result = PASS;
  3262. DEBUG_INFO("Authorize mapItem pass\n");
  3263. }
  3264. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3265. return result;
  3266. }
  3267. int sendBootNotificationRequest(void)
  3268. {
  3269. mtrace();
  3270. int result = FAIL;
  3271. char message[500]={0}, payload[700]={0};
  3272. char guid[37]={0};
  3273. char tempdata[65]={0};
  3274. // Fill BootNotification fields
  3275. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3276. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3277. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3278. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3279. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3280. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3281. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3282. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3283. ShmOCPP16DataPH->ChargeBoxId
  3284. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3285. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3286. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3287. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3288. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3289. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3290. random_uuid(guid);
  3291. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3292. LWS_Send(message);
  3293. sprintf(tempdata, "BootNotification,0");
  3294. 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*/)
  3295. {
  3296. result = PASS;
  3297. }
  3298. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3299. strcpy(queuedata,message);
  3300. return result;
  3301. }
  3302. int sendDataTransferRequest(int gun_index)
  3303. {
  3304. mtrace();
  3305. char message[1000]={0};
  3306. char guid[37]={0};
  3307. char tempdata[65]={0};
  3308. int result = FAIL;
  3309. random_uuid(guid);
  3310. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3311. MESSAGE_TYPE_CALL,
  3312. guid,
  3313. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  3314. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  3315. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  3316. LWS_Send(message);
  3317. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3318. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3319. {
  3320. result = PASS;
  3321. DEBUG_INFO("DataTransfer mapItem pass\n");
  3322. }
  3323. return result;
  3324. }
  3325. int sendDiagnosticsStatusNotificationRequest(char *status)
  3326. {
  3327. mtrace();
  3328. int result = FAIL;
  3329. char message[110]={0};
  3330. char guid[37]={0};
  3331. char tempdata[65]={0};
  3332. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3333. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3334. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3335. random_uuid(guid);
  3336. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3337. LWS_SendNow(message);
  3338. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3339. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3340. {
  3341. result = PASS;
  3342. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3343. }
  3344. //#ifdef SystemLogMessage
  3345. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3346. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3347. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3348. //#endif
  3349. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3350. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3351. //record status
  3352. if(strcmp(status,"Idle")==0)
  3353. {
  3354. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3355. }
  3356. else if(strcmp(status,"Uploaded")==0)
  3357. {
  3358. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3359. }
  3360. else if(strcmp(status,"UploadFailed")==0)
  3361. {
  3362. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3363. }
  3364. else if(strcmp(status,"Uploading")==0)
  3365. {
  3366. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3367. }
  3368. return result;
  3369. }
  3370. int sendFirmwareStatusNotificationRequest(char *status)
  3371. {
  3372. mtrace();
  3373. int result = FAIL;
  3374. char message[110]={0};
  3375. char guid[37]={0};
  3376. char tempdata[65]={0};
  3377. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3378. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3379. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3380. random_uuid(guid);
  3381. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3382. LWS_SendNow(message);
  3383. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3384. 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*/)
  3385. {
  3386. result = PASS;
  3387. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3388. }
  3389. //#ifdef SystemLogMessage
  3390. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3391. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3392. //#endif
  3393. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3394. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3395. //record status
  3396. if(strcmp(status,"Downloaded")==0)
  3397. {
  3398. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3399. }
  3400. else if(strcmp(status,"DownloadFailed")==0)
  3401. {
  3402. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3403. }
  3404. else if(strcmp(status,"Downloading")==0)
  3405. {
  3406. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3407. }
  3408. else if(strcmp(status,"Idle")==0)
  3409. {
  3410. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3411. }
  3412. else if(strcmp(status,"InstallationFailed")==0)
  3413. {
  3414. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3415. }
  3416. else if(strcmp(status,"Installing")==0)
  3417. {
  3418. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3419. }
  3420. else if(strcmp(status,"Installed")==0)
  3421. {
  3422. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3423. }
  3424. return result;
  3425. }
  3426. int sendHeartbeatRequest(int gun_index)
  3427. {
  3428. mtrace();
  3429. int result = FAIL;
  3430. char message[80]={0};
  3431. char guid[37]={0};
  3432. char tempdata[65]={0};
  3433. random_uuid(guid);
  3434. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3435. , MESSAGE_TYPE_CALL
  3436. , guid );
  3437. LWS_Send(message);
  3438. sprintf(tempdata, "Heartbeat,%d", 0);
  3439. 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*/)
  3440. {
  3441. result = PASS;
  3442. }
  3443. return result;
  3444. }
  3445. int sendStartTransactionRequest(int gun_index)
  3446. {
  3447. mtrace();
  3448. int result = FAIL;
  3449. char message[250]={0};
  3450. char guid[37]={0};
  3451. struct timeval tmnow;
  3452. struct tm *tm;
  3453. char buf[28];//, usec_buf[6];
  3454. char tempdata[65]={0};
  3455. int tempIndex = 0;
  3456. DEBUG_INFO("sendStartTransactionRequest...\n");
  3457. gettimeofday(&tmnow, NULL);
  3458. time_t t;
  3459. t = time(NULL);
  3460. /*UTC time and date*/
  3461. tm = gmtime(&t);
  3462. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3463. #if 0 // remove temporally
  3464. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3465. strcat(buf,".");
  3466. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3467. strcat(buf,usec_buf);
  3468. #endif
  3469. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3470. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  3471. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3472. // clear StartTransaction Response
  3473. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3474. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3475. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3476. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  3477. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3478. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3479. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3480. {
  3481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3482. {
  3483. tempIndex = ((gun_index==2) ? 1: 0);
  3484. }
  3485. else
  3486. {
  3487. tempIndex = gun_index;
  3488. }
  3489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3490. {
  3491. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3492. {
  3493. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3494. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3495. }
  3496. }
  3497. }
  3498. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3499. {
  3500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3501. {
  3502. tempIndex = ((gun_index==2) ? 1: 0);
  3503. }
  3504. else
  3505. {
  3506. tempIndex = gun_index;
  3507. }
  3508. for (int index = 0; index < CCS_QUANTITY; index++)
  3509. {
  3510. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3511. {
  3512. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3513. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3514. }
  3515. }
  3516. }
  3517. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3518. {
  3519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3520. {
  3521. tempIndex = ((gun_index==2) ? 1: 0);
  3522. }
  3523. else
  3524. {
  3525. tempIndex = gun_index;
  3526. }
  3527. for (int index = 0; index < GB_QUANTITY; index++)
  3528. {
  3529. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3530. {
  3531. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3532. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3533. }
  3534. }
  3535. }
  3536. else if(gunType[gun_index] == GUN_TYPE_DO)
  3537. {
  3538. tempIndex = gun_index;
  3539. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3540. {
  3541. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3542. {
  3543. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3544. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3545. }
  3546. }
  3547. }
  3548. else
  3549. {
  3550. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3551. {
  3552. tempIndex = 2;
  3553. }
  3554. else
  3555. {
  3556. tempIndex = gun_index;
  3557. }
  3558. for (int index = 0; index < AC_QUANTITY; index++)
  3559. {
  3560. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3561. {
  3562. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3563. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3564. }
  3565. }
  3566. }
  3567. random_uuid(guid);
  3568. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3569. {
  3570. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3571. , gun_index +1
  3572. , MESSAGE_TYPE_CALL
  3573. , guid
  3574. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  3575. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  3576. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  3577. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  3578. }
  3579. else
  3580. {
  3581. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3582. , gun_index +1
  3583. , MESSAGE_TYPE_CALL
  3584. , guid
  3585. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  3586. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  3587. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  3588. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  3589. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  3590. }
  3591. #if 1
  3592. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3593. 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*/)
  3594. {
  3595. result = PASS;
  3596. }
  3597. #endif
  3598. strcpy(queuedata, message);
  3599. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3600. OCPP_insert_transaction_msg(YES, queuedata);
  3601. return result;
  3602. }
  3603. int sendStatusNotificationRequest(int gun_index)
  3604. {
  3605. mtrace();
  3606. int result = FAIL;
  3607. char message[600]={0};
  3608. char guid[37];
  3609. int currentStatus = 0;
  3610. struct timeval tmnow;
  3611. struct tm *tm;
  3612. char buf[28];//, usec_buf[6];
  3613. char tempdata[65]={0};
  3614. int tempIndex = 0;
  3615. uint8_t isStateChanged = TRUE;
  3616. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3617. gettimeofday(&tmnow, NULL);
  3618. time_t t;
  3619. t = time(NULL);
  3620. /*UTC time and date*/
  3621. tm = gmtime(&t);
  3622. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3623. #if 0 // remove temporally
  3624. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3625. strcat(buf,".");
  3626. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3627. strcat(buf,usec_buf);
  3628. #endif
  3629. printf("%s",buf);
  3630. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3631. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3632. // it's option
  3633. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  3634. /*
  3635. enum _SYSTEM_STATUS
  3636. {
  3637. S_BOOTING = 0,
  3638. S_IDLE, = 1
  3639. S_AUTHORIZING, =2
  3640. S_REASSIGN_CHECK, =3
  3641. S_REASSIGN, =4
  3642. S_PRECHARGE, =5
  3643. S_PREPARING_FOR_EV, =6
  3644. S_PREPARING_FOR_EVSE, =7
  3645. S_CHARGING, =8
  3646. S_TERMINATING, =9
  3647. S_COMPLETE, =10
  3648. S_ALARM, =11
  3649. S_FAULT =12
  3650. }
  3651. */
  3652. //check Transaction active
  3653. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3654. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3655. {
  3656. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3657. {
  3658. tempIndex = ((gun_index==2) ? 1: 0);
  3659. }
  3660. else
  3661. {
  3662. tempIndex = gun_index;
  3663. }
  3664. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3665. {
  3666. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3667. {
  3668. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3669. {
  3670. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3671. {
  3672. currentStatus = Preparing; //OCPP Status: Preparing
  3673. }
  3674. else
  3675. {
  3676. currentStatus = Available; //OCPP Status: Available
  3677. }
  3678. }
  3679. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3680. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3681. ) //S_PRECHARGE
  3682. {
  3683. currentStatus = Preparing; //OCPP Status: Preparing
  3684. }
  3685. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3686. {
  3687. currentStatus = Charging; //OCPP Status: Charging
  3688. }
  3689. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3690. {
  3691. currentStatus = Finishing; //OCPP Status: Finishing
  3692. }
  3693. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3694. {
  3695. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3696. }
  3697. 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
  3698. {
  3699. currentStatus = Unavailable; //OCPP Status: Unavailable
  3700. }
  3701. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3702. {
  3703. currentStatus = Faulted; //OCPP Status: Faulted
  3704. }
  3705. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3706. {
  3707. currentStatus = Reserved; //OCPP Status: Reserved
  3708. }
  3709. } //end of the same index
  3710. }//end of for CHAdeMO_QUANTITY
  3711. }
  3712. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3713. {
  3714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3715. {
  3716. tempIndex = ((gun_index==2) ? 1: 0);
  3717. }
  3718. else
  3719. {
  3720. tempIndex = gun_index;
  3721. }
  3722. for (int index = 0; index < CCS_QUANTITY; index++)
  3723. {
  3724. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3725. {
  3726. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3727. {
  3728. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3729. {
  3730. currentStatus = Preparing; //OCPP Status: Preparing
  3731. }
  3732. else
  3733. {
  3734. currentStatus = Available; //OCPP Status: Available
  3735. }
  3736. }
  3737. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3738. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3739. ) //S_PRECHARGE
  3740. {
  3741. currentStatus = Preparing; //OCPP Status: Preparing
  3742. }
  3743. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3744. {
  3745. currentStatus = Charging; //OCPP Status: Charging
  3746. }
  3747. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3748. {
  3749. currentStatus = Finishing; //OCPP Status: Finishing
  3750. }
  3751. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3752. {
  3753. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3754. }
  3755. 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
  3756. {
  3757. currentStatus = Unavailable; //OCPP Status : Unavailable
  3758. }
  3759. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3760. {
  3761. currentStatus = Faulted; //OCPP Status: Faulted
  3762. }
  3763. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3764. {
  3765. currentStatus = Reserved; //OCPP Status: Reserved
  3766. }
  3767. } //end of the same index
  3768. } // end of for CCS_QUANTITY
  3769. }
  3770. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3771. {
  3772. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3773. {
  3774. tempIndex = ((gun_index==2) ? 1: 0);
  3775. }
  3776. else
  3777. {
  3778. tempIndex = gun_index;
  3779. }
  3780. for (int index = 0; index < GB_QUANTITY; index++)
  3781. {
  3782. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3783. {
  3784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3785. {
  3786. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3787. {
  3788. currentStatus = Preparing; //OCPP Status: Preparing
  3789. }
  3790. else
  3791. {
  3792. currentStatus = Available; //OCPP Status: Available
  3793. }
  3794. }
  3795. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3796. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3797. ) //S_PRECHARGE
  3798. {
  3799. currentStatus = Preparing; //OCPP Status: Preparing
  3800. }
  3801. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3802. {
  3803. currentStatus = Charging; //OCPP Status: Charging
  3804. }
  3805. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3806. {
  3807. currentStatus = Finishing; //OCPP Status: Finishing
  3808. }
  3809. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3810. {
  3811. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3812. }
  3813. 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
  3814. {
  3815. currentStatus = Unavailable; //OCPP Status: Unavailable
  3816. }
  3817. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3818. {
  3819. currentStatus = Faulted; //OCPP Status: Faulted
  3820. }
  3821. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3822. {
  3823. currentStatus = Reserved; //OCPP Status: Reserved
  3824. }
  3825. } //end of the same index
  3826. } // end of for GB_QUANTITY
  3827. }
  3828. else if(gunType[gun_index] == GUN_TYPE_DO)
  3829. {
  3830. tempIndex = gun_index;
  3831. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3832. {
  3833. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3834. {
  3835. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3836. {
  3837. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3838. {
  3839. currentStatus = Preparing; //OCPP Status: Preparing
  3840. }
  3841. else
  3842. {
  3843. currentStatus = Available; //OCPP Status: Available
  3844. }
  3845. }
  3846. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3847. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3848. ) //S_PRECHARGE
  3849. {
  3850. currentStatus = Preparing; //OCPP Status: Preparing
  3851. }
  3852. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3853. {
  3854. currentStatus = Charging; //OCPP Status: Charging
  3855. }
  3856. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3857. {
  3858. currentStatus = Finishing; //OCPP Status: Finishing
  3859. }
  3860. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3861. {
  3862. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3863. }
  3864. 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
  3865. {
  3866. currentStatus = Unavailable; //OCPP Status: Unavailable
  3867. }
  3868. 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
  3869. {
  3870. currentStatus = Faulted; //OCPP Status: Faulted
  3871. }
  3872. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3873. {
  3874. currentStatus = Reserved; //OCPP Status: Reserved
  3875. }
  3876. } //end of the same index
  3877. }
  3878. }
  3879. else
  3880. {
  3881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3882. {
  3883. tempIndex = 2;
  3884. }
  3885. else
  3886. {
  3887. tempIndex = gun_index;
  3888. }
  3889. for (int index = 0; index < AC_QUANTITY; index++)
  3890. {
  3891. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3892. {
  3893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3894. {
  3895. 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))
  3896. {
  3897. currentStatus = Preparing; //OCPP Status: Preparing
  3898. }
  3899. else
  3900. {
  3901. currentStatus = Available; //OCPP Status: Available
  3902. }
  3903. }
  3904. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3905. {
  3906. currentStatus = Preparing; //OCPP Status: Preparing
  3907. }
  3908. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3909. {
  3910. currentStatus = Charging; //OCPP Status: Charging
  3911. }
  3912. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3913. {
  3914. currentStatus = Finishing; //OCPP Status: Finishing
  3915. }
  3916. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3917. {
  3918. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3919. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3920. else
  3921. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3922. }
  3923. 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
  3924. {
  3925. currentStatus = Unavailable; //OCPP Status: Unavailable
  3926. }
  3927. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3928. {
  3929. currentStatus = Faulted; //OCPP Status: Faulted
  3930. }
  3931. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3932. {
  3933. currentStatus = Reserved; //OCPP Status: Reserved
  3934. }
  3935. }//end of the same index
  3936. }//end of for AC_QUANTITY
  3937. }
  3938. //it's option
  3939. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3940. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  3941. {
  3942. isStateChanged = FALSE;
  3943. }
  3944. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3945. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  3946. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3947. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3948. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  3949. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  3950. random_uuid(guid);
  3951. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3952. , MESSAGE_TYPE_CALL
  3953. , guid
  3954. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  3955. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  3956. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  3957. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  3958. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  3959. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  3960. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  3961. if((server_sign == TRUE) && isStateChanged)
  3962. {
  3963. LWS_Send(message);
  3964. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3965. 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*/)
  3966. {
  3967. //DEBUG_ERROR("statusNotification mapitem pass");
  3968. result = PASS;
  3969. }
  3970. }
  3971. else
  3972. {
  3973. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3974. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3975. result = PASS;
  3976. }
  3977. return result;
  3978. }
  3979. int sendStopTransactionRequest(int gun_index)
  3980. {
  3981. mtrace();
  3982. int result = FAIL;
  3983. //char message[1500]={0};
  3984. char guid[37]={0};
  3985. char tempdata[65]={0};
  3986. int tempIndex = 0;
  3987. char TempStopTransaction[256];
  3988. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  3989. //int idx_sample=0;
  3990. DEBUG_INFO("sendStopTransactionRequest \n");
  3991. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3992. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  3993. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3994. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3995. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3996. {
  3997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3998. {
  3999. tempIndex = ((gun_index==2) ? 1: 0);
  4000. }
  4001. else
  4002. {
  4003. tempIndex = gun_index;
  4004. }
  4005. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4006. {
  4007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4008. {
  4009. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4010. }
  4011. }// END OF CHAdeMO_QUANTITY
  4012. }
  4013. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4014. {
  4015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4016. {
  4017. tempIndex = ((gun_index==2) ? 1: 0);
  4018. }
  4019. else
  4020. {
  4021. tempIndex = gun_index;
  4022. }
  4023. for (int index = 0; index < CCS_QUANTITY; index++)
  4024. {
  4025. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4026. {
  4027. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4028. }
  4029. }// END OF CCS_QUANTITY
  4030. }
  4031. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4032. {
  4033. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4034. {
  4035. tempIndex = ((gun_index==2) ? 1: 0);
  4036. }
  4037. else
  4038. {
  4039. tempIndex = gun_index;
  4040. }
  4041. for (int index = 0; index < GB_QUANTITY; index++)
  4042. {
  4043. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4044. {
  4045. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4046. }
  4047. }// END OF GB_QUANTITY
  4048. }
  4049. else if(gunType[gun_index] == GUN_TYPE_DO)
  4050. {
  4051. tempIndex = gun_index;
  4052. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4053. {
  4054. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4055. {
  4056. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4057. }
  4058. }// END OF GB_QUANTITY
  4059. }
  4060. else
  4061. {
  4062. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4063. {
  4064. tempIndex = 2;
  4065. }
  4066. else
  4067. {
  4068. tempIndex = gun_index;
  4069. }
  4070. for (int index = 0; index < AC_QUANTITY; index++)
  4071. {
  4072. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4073. {
  4074. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4075. }
  4076. }// END OF AC_QUANTITY
  4077. }
  4078. //====================================== Stop Transaction Time =====================================================
  4079. struct timeval tmnow;
  4080. struct tm *tm;
  4081. char buf[28];//, usec_buf[6];
  4082. gettimeofday(&tmnow, NULL);
  4083. time_t t;
  4084. t = time(NULL);
  4085. /*UTC time and date*/
  4086. tm = gmtime(&t);
  4087. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4089. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4090. random_uuid(guid);
  4091. /***********************************transactionData******************************************************/
  4092. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4093. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4094. //=================================
  4095. // Transaction_Begin
  4096. //=================================
  4097. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4098. {
  4099. //============================================ Energy.Active.Import.Interval ================================
  4100. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4101. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4102. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4103. 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*/]);
  4104. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4105. 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))
  4106. {
  4107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4108. }
  4109. else
  4110. {
  4111. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4112. }
  4113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4115. }
  4116. //=================================
  4117. // Transaction_End
  4118. //=================================
  4119. // ================================= Current.Import L1 ===============================================
  4120. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4121. {
  4122. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4123. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4134. {
  4135. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4136. {
  4137. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4138. }
  4139. }// End of for CHAdeMO_QUANTITY
  4140. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4141. }
  4142. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4145. {
  4146. tempIndex = ((gun_index==2) ? 1: 0);
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < CCS_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4157. }
  4158. }// End of for CCS_QUANTITY
  4159. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4160. }
  4161. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4162. {
  4163. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4164. {
  4165. tempIndex = ((gun_index==2) ? 1: 0);
  4166. }
  4167. else
  4168. {
  4169. tempIndex = gun_index;
  4170. }
  4171. for (int index = 0; index < GB_QUANTITY; index++)
  4172. {
  4173. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4174. {
  4175. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4176. }
  4177. }// End of for GB_QUANTITY
  4178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4179. }
  4180. else if(gunType[gun_index] == GUN_TYPE_DO)
  4181. {
  4182. tempIndex = gun_index;
  4183. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4184. {
  4185. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4186. {
  4187. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4188. }
  4189. }
  4190. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4191. }
  4192. else
  4193. {
  4194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4195. {
  4196. tempIndex = 2;
  4197. }
  4198. else
  4199. {
  4200. tempIndex = gun_index;
  4201. }
  4202. for (int index = 0; index < AC_QUANTITY; index++)
  4203. {
  4204. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4205. {
  4206. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4207. }
  4208. }// End of for AC_QUANTITY
  4209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4210. }
  4211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4212. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4213. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4214. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4216. }
  4217. // ================================= Energy.Active.Import.Interval ==============================================
  4218. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4219. {
  4220. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4221. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4222. {
  4223. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4224. {
  4225. tempIndex = ((gun_index==2) ? 1: 0);
  4226. }
  4227. else
  4228. {
  4229. tempIndex = gun_index;
  4230. }
  4231. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4232. {
  4233. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4234. {
  4235. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4236. }
  4237. }// END OF CHAdeMO_QUANTITY
  4238. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4239. }
  4240. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4241. {
  4242. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4243. {
  4244. tempIndex = ((gun_index==2) ? 1: 0);
  4245. }
  4246. else
  4247. {
  4248. tempIndex = gun_index;
  4249. }
  4250. for (int index = 0; index < CCS_QUANTITY; index++)
  4251. {
  4252. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4253. {
  4254. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4255. }
  4256. }// END OF CCS_QUANTITY
  4257. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4258. }
  4259. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4260. {
  4261. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4262. {
  4263. tempIndex = ((gun_index==2) ? 1: 0);
  4264. }
  4265. else
  4266. {
  4267. tempIndex = gun_index;
  4268. }
  4269. for (int index = 0; index < GB_QUANTITY; index++)
  4270. {
  4271. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4272. {
  4273. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4274. }
  4275. }// END OF GB_QUANTITY
  4276. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4277. }
  4278. else if(gunType[gun_index] == GUN_TYPE_DO)
  4279. {
  4280. tempIndex = gun_index;
  4281. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4282. {
  4283. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4284. {
  4285. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4286. }
  4287. }
  4288. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4289. }
  4290. else
  4291. {
  4292. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4293. {
  4294. tempIndex = 2;
  4295. }
  4296. else
  4297. {
  4298. tempIndex = gun_index;
  4299. }
  4300. for (int index = 0; index < AC_QUANTITY; index++)
  4301. {
  4302. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4303. {
  4304. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4305. }
  4306. }// END OF AC_QUANTITY
  4307. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4308. }
  4309. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4310. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4311. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4312. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4313. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4314. }
  4315. //=================================== Power.Active.Import ==================================================
  4316. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4317. {
  4318. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4319. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4320. {
  4321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4322. {
  4323. tempIndex = ((gun_index==2) ? 1: 0);
  4324. }
  4325. else
  4326. {
  4327. tempIndex = gun_index;
  4328. }
  4329. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4330. {
  4331. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4332. {
  4333. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4334. }
  4335. } // End for CHAdeMO_QUANTITY
  4336. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4337. }
  4338. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4339. {
  4340. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4341. {
  4342. tempIndex = ((gun_index==2) ? 1: 0);
  4343. }
  4344. else
  4345. {
  4346. tempIndex = gun_index;
  4347. }
  4348. for (int index = 0; index < CCS_QUANTITY; index++)
  4349. {
  4350. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4351. {
  4352. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4353. }
  4354. } // END for CCS_QUANTITY
  4355. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4356. }
  4357. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4358. {
  4359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4360. {
  4361. tempIndex = ((gun_index==2) ? 1: 0);
  4362. }
  4363. else
  4364. {
  4365. tempIndex = gun_index;
  4366. }
  4367. for (int index = 0; index < GB_QUANTITY; index++)
  4368. {
  4369. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4370. {
  4371. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4372. }
  4373. }// END for GB_QUANTITY
  4374. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4375. }
  4376. else if(gunType[gun_index] == GUN_TYPE_DO)
  4377. {
  4378. tempIndex = gun_index;
  4379. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4380. {
  4381. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4382. {
  4383. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4384. }
  4385. }
  4386. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4387. }
  4388. else
  4389. {
  4390. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4391. {
  4392. tempIndex = 2;
  4393. }
  4394. else
  4395. {
  4396. tempIndex = gun_index;
  4397. }
  4398. for (int index = 0; index < AC_QUANTITY; index++)
  4399. {
  4400. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4401. {
  4402. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4403. }
  4404. } // END for AC_QUANTITY
  4405. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4406. }
  4407. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4408. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4409. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4410. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4411. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4412. }
  4413. //============================ Voltage L1 ====================================
  4414. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4415. {
  4416. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4417. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4418. {
  4419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4420. {
  4421. tempIndex = ((gun_index==2) ? 1: 0);
  4422. }
  4423. else
  4424. {
  4425. tempIndex = gun_index;
  4426. }
  4427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4428. {
  4429. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4430. {
  4431. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4432. }
  4433. } // END OF FOR CHAdeMO_QUANTITY
  4434. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4435. }
  4436. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4437. {
  4438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4439. {
  4440. tempIndex = ((gun_index==2) ? 1: 0);
  4441. }
  4442. else
  4443. {
  4444. tempIndex = gun_index;
  4445. }
  4446. for (int index = 0; index < CCS_QUANTITY; index++)
  4447. {
  4448. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4449. {
  4450. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4451. }
  4452. } // END OF FOR CCS_QUANTITY
  4453. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4454. }
  4455. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4456. {
  4457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4458. {
  4459. tempIndex = ((gun_index==2) ? 1: 0);
  4460. }
  4461. else
  4462. {
  4463. tempIndex = gun_index;
  4464. }
  4465. for (int index = 0; index < GB_QUANTITY; index++)
  4466. {
  4467. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4468. {
  4469. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4470. }
  4471. } // END OF FOR GB_QUANTITY
  4472. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4473. }
  4474. else if(gunType[gun_index] == GUN_TYPE_DO)
  4475. {
  4476. tempIndex = gun_index;
  4477. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4478. {
  4479. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4480. {
  4481. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4482. }
  4483. }
  4484. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4485. }
  4486. else
  4487. {
  4488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4489. {
  4490. tempIndex = 2;
  4491. }
  4492. else
  4493. {
  4494. tempIndex = gun_index;
  4495. }
  4496. for (int index = 0; index < AC_QUANTITY; index++)
  4497. {
  4498. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4499. {
  4500. 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
  4501. }
  4502. } // END OF FOR AC_QUANTITY
  4503. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4504. }
  4505. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4506. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4507. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4508. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4510. }
  4511. //====================== End SoC ================================
  4512. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4513. {
  4514. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4515. 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))
  4516. {
  4517. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4518. {
  4519. tempIndex = ((gun_index==2) ? 1: 0);
  4520. }
  4521. else
  4522. {
  4523. tempIndex = gun_index;
  4524. }
  4525. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4526. {
  4527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4528. {
  4529. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4530. {
  4531. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4532. }
  4533. }
  4534. }
  4535. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4536. {
  4537. for (int index = 0; index < CCS_QUANTITY; index++)
  4538. {
  4539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4540. {
  4541. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4542. }
  4543. }
  4544. }
  4545. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4546. {
  4547. for (int index = 0; index < GB_QUANTITY; index++)
  4548. {
  4549. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4550. {
  4551. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4552. }
  4553. }
  4554. }
  4555. else if(gunType[gun_index] == GUN_TYPE_DO)
  4556. {
  4557. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4558. {
  4559. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4560. {
  4561. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4562. }
  4563. }
  4564. }
  4565. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4566. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4567. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4568. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4569. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4570. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4571. } // END FOR DC CASE
  4572. }
  4573. // ================================= Current.Import L2 ===============================================
  4574. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4575. {
  4576. // AC 3 phse L2 current
  4577. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4578. {
  4579. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4580. {
  4581. tempIndex = 2;
  4582. }
  4583. else
  4584. {
  4585. tempIndex = gun_index;
  4586. }
  4587. for (int index = 0; index < AC_QUANTITY; index++)
  4588. {
  4589. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4590. {
  4591. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4592. }
  4593. }// End of for AC_QUANTITY
  4594. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4595. }
  4596. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4597. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4598. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4599. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4601. }
  4602. // ================================= Current.Import L3 ===============================================
  4603. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4604. {
  4605. // AC 3 phse L3 current
  4606. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4607. {
  4608. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4609. {
  4610. tempIndex = 2;
  4611. }
  4612. else
  4613. {
  4614. tempIndex = gun_index;
  4615. }
  4616. for (int index = 0; index < AC_QUANTITY; index++)
  4617. {
  4618. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4619. {
  4620. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4621. }
  4622. }// End of for AC_QUANTITY
  4623. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4624. }
  4625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4626. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4630. }
  4631. //============================ Voltage L2 ====================================
  4632. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4633. {
  4634. // AC 3 phse L2 voltage
  4635. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4636. {
  4637. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4638. {
  4639. tempIndex = 2;
  4640. }
  4641. else
  4642. {
  4643. tempIndex = gun_index;
  4644. }
  4645. for (int index = 0; index < AC_QUANTITY; index++)
  4646. {
  4647. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4648. {
  4649. 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
  4650. }
  4651. } // END OF FOR AC_QUANTITY
  4652. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4653. }
  4654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4655. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4656. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4657. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4659. }
  4660. //============================ Voltage L3 ====================================
  4661. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4662. {
  4663. // AC 3 phse L3 voltage
  4664. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4665. {
  4666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4667. {
  4668. tempIndex = 2;
  4669. }
  4670. else
  4671. {
  4672. tempIndex = gun_index;
  4673. }
  4674. for (int index = 0; index < AC_QUANTITY; index++)
  4675. {
  4676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4677. {
  4678. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4679. }
  4680. } // END OF FOR AC_QUANTITY
  4681. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4682. }
  4683. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4684. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4685. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4686. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4688. }
  4689. //====================== Start SoC ================================
  4690. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4691. {
  4692. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4693. 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))
  4694. {
  4695. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4696. {
  4697. tempIndex = ((gun_index==2) ? 1: 0);
  4698. }
  4699. else
  4700. {
  4701. tempIndex = gun_index;
  4702. }
  4703. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4704. {
  4705. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4706. {
  4707. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4708. {
  4709. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4710. }
  4711. }
  4712. }
  4713. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4714. {
  4715. for (int index = 0; index < CCS_QUANTITY; index++)
  4716. {
  4717. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4718. {
  4719. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4720. }
  4721. }
  4722. }
  4723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4724. {
  4725. for (int index = 0; index < GB_QUANTITY; index++)
  4726. {
  4727. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4728. {
  4729. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4730. }
  4731. }
  4732. }
  4733. else if(gunType[gun_index] == GUN_TYPE_DO)
  4734. {
  4735. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4736. {
  4737. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4738. {
  4739. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4740. }
  4741. }
  4742. }
  4743. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4744. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4745. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4746. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4748. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4749. } // END FOR DC CASE
  4750. }
  4751. //================================================ Message create ====================================================
  4752. json_object *StopTransaction = json_object_new_object();
  4753. json_object *transactionDatas = json_object_new_array();
  4754. json_object *sampledValues = json_object_new_array();
  4755. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  4756. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  4757. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  4758. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  4759. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  4760. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  4761. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  4762. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  4763. {
  4764. json_object *transactionData = json_object_new_object();
  4765. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4766. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4767. {
  4768. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4769. {
  4770. json_object *sampledValue = json_object_new_object();
  4771. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4772. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4773. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4774. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4775. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4776. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4777. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4778. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4779. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4780. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4781. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4782. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4783. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4784. json_object_array_add(sampledValues, sampledValue);
  4785. }
  4786. }
  4787. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4788. json_object_array_add(transactionDatas, transactionData);
  4789. }
  4790. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4791. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4792. ,MESSAGE_TYPE_CALL
  4793. ,guid
  4794. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4795. json_object_put(StopTransaction);
  4796. #if 1 // for TempStopTransaction
  4797. //Delete TempStopTransaction
  4798. if((access(TempStopTransaction,F_OK))!=-1)
  4799. {
  4800. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4801. }
  4802. #endif
  4803. #if 1
  4804. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4805. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4806. {
  4807. result = PASS;
  4808. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4809. }
  4810. #endif
  4811. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4812. OCPP_insert_transaction_msg(NO, queuedata);
  4813. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4814. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  4815. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  4816. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4817. {
  4818. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  4819. }
  4820. //for test
  4821. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4822. return result;
  4823. }
  4824. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4825. {
  4826. mtrace();
  4827. int result = FAIL;
  4828. char guid[37]={0};
  4829. char tempdata[65]={0};
  4830. int tempIndex = 0;
  4831. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4832. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4833. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4834. //set value
  4835. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4836. 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) )?
  4837. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  4838. -1);
  4839. random_uuid(guid);
  4840. //UTC Date time
  4841. struct timeval tmnow;
  4842. struct tm *tm;
  4843. char buf[28];//, usec_buf[6];
  4844. gettimeofday(&tmnow, NULL);
  4845. time_t t;
  4846. t = time(NULL);
  4847. /*UTC time and date*/
  4848. tm = gmtime(&t);
  4849. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4850. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4851. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4852. //********************************(1)Current.Import L1************************************************/
  4853. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4854. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4855. (dataType == ReadingContext_Trigger))
  4856. {
  4857. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4858. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4859. {
  4860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4861. {
  4862. tempIndex = ((gun_index==2) ? 1: 0);
  4863. }
  4864. else
  4865. {
  4866. tempIndex = gun_index;
  4867. }
  4868. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4869. {
  4870. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4871. {
  4872. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4873. }
  4874. }
  4875. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4876. }
  4877. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4878. {
  4879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4880. {
  4881. tempIndex = ((gun_index==2) ? 1: 0);
  4882. }
  4883. else
  4884. {
  4885. tempIndex = gun_index;
  4886. }
  4887. for (int index = 0; index < CCS_QUANTITY; index++)
  4888. {
  4889. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4890. {
  4891. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4892. }
  4893. }
  4894. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4895. }
  4896. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4897. {
  4898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4899. {
  4900. tempIndex = ((gun_index==2) ? 1: 0);
  4901. }
  4902. else
  4903. {
  4904. tempIndex = gun_index;
  4905. }
  4906. for (int index = 0; index < GB_QUANTITY; index++)
  4907. {
  4908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4909. {
  4910. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4911. }
  4912. }
  4913. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4914. }
  4915. else if(gunType[gun_index] == GUN_TYPE_DO)
  4916. {
  4917. tempIndex = gun_index;
  4918. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4919. {
  4920. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4921. {
  4922. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4923. }
  4924. }
  4925. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4926. }
  4927. else
  4928. {
  4929. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4930. {
  4931. tempIndex = 2;
  4932. }
  4933. else
  4934. {
  4935. tempIndex = gun_index;
  4936. }
  4937. for (int index = 0; index < AC_QUANTITY; index++)
  4938. {
  4939. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4940. {
  4941. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4942. }
  4943. }
  4944. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4945. }
  4946. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4947. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4948. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4949. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4950. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4951. }
  4952. //********************************(2)Energy.Active.Import.Register ************************************************/
  4953. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4954. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4955. (dataType == ReadingContext_Trigger))
  4956. {
  4957. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4958. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  4969. {
  4970. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4971. {
  4972. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4973. }
  4974. }
  4975. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4976. }
  4977. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4978. {
  4979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4980. {
  4981. tempIndex = ((gun_index==2) ? 1: 0);
  4982. }
  4983. else
  4984. {
  4985. tempIndex = gun_index;
  4986. }
  4987. for (int index = 0; index < CCS_QUANTITY; index++)
  4988. {
  4989. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4990. {
  4991. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4992. }
  4993. }
  4994. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4995. }
  4996. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4997. {
  4998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4999. {
  5000. tempIndex = ((gun_index==2) ? 1: 0);
  5001. }
  5002. else
  5003. {
  5004. tempIndex = gun_index;
  5005. }
  5006. for (int index = 0; index < GB_QUANTITY; index++)
  5007. {
  5008. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5009. {
  5010. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5011. }
  5012. }
  5013. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5014. }
  5015. else if(gunType[gun_index] == GUN_TYPE_DO)
  5016. {
  5017. tempIndex = gun_index;
  5018. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5019. {
  5020. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5021. {
  5022. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5023. }
  5024. }
  5025. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5026. }
  5027. else
  5028. {
  5029. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5030. {
  5031. tempIndex = 2;
  5032. }
  5033. else
  5034. {
  5035. tempIndex = gun_index;
  5036. }
  5037. for (int index = 0; index < AC_QUANTITY; index++)
  5038. {
  5039. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5040. {
  5041. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5042. }
  5043. }
  5044. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5045. }
  5046. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5047. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5048. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5049. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5050. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5051. }
  5052. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5053. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5054. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5055. (dataType == ReadingContext_Trigger))
  5056. {
  5057. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5058. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5059. {
  5060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5061. {
  5062. tempIndex = ((gun_index==2) ? 1: 0);
  5063. }
  5064. else
  5065. {
  5066. tempIndex = gun_index;
  5067. }
  5068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5069. {
  5070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5071. {
  5072. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5073. }
  5074. } // END OF FOR CHAdeMO_QUANTITY
  5075. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5076. }
  5077. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5078. {
  5079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5080. {
  5081. tempIndex = ((gun_index==2) ? 1: 0);
  5082. }
  5083. else
  5084. {
  5085. tempIndex = gun_index;
  5086. }
  5087. for (int index = 0; index < CCS_QUANTITY; index++)
  5088. {
  5089. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5090. {
  5091. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5092. }
  5093. } // END OF CCS_QUANTITY
  5094. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5095. }
  5096. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5097. {
  5098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5099. {
  5100. tempIndex = ((gun_index==2) ? 1: 0);
  5101. }
  5102. else
  5103. {
  5104. tempIndex = gun_index;
  5105. }
  5106. for (int index = 0; index < GB_QUANTITY; index++)
  5107. {
  5108. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5109. {
  5110. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5111. }
  5112. } // END OF GB_QUANTITY
  5113. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5114. }
  5115. else if(gunType[gun_index] == GUN_TYPE_DO)
  5116. {
  5117. tempIndex = gun_index;
  5118. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5119. {
  5120. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5121. {
  5122. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5123. }
  5124. }
  5125. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5126. }
  5127. else
  5128. {
  5129. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5130. {
  5131. tempIndex = 2;
  5132. }
  5133. else
  5134. {
  5135. tempIndex = gun_index;
  5136. }
  5137. for (int index = 0; index < AC_QUANTITY; index++)
  5138. {
  5139. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5140. {
  5141. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5142. }
  5143. }
  5144. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5145. }
  5146. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5147. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5148. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5149. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5150. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5151. }
  5152. //********************************(4)Power.Active.Import************************************************/
  5153. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5154. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5155. (dataType == ReadingContext_Trigger))
  5156. {
  5157. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5158. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5159. {
  5160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5161. {
  5162. tempIndex = ((gun_index==2) ? 1: 0);
  5163. }
  5164. else
  5165. {
  5166. tempIndex = gun_index;
  5167. }
  5168. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5169. {
  5170. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5171. {
  5172. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5173. }
  5174. } // END OF FOR
  5175. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5176. }
  5177. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5178. {
  5179. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5180. {
  5181. tempIndex = ((gun_index==2) ? 1: 0);
  5182. }
  5183. else
  5184. {
  5185. tempIndex = gun_index;
  5186. }
  5187. for (int index = 0; index < CCS_QUANTITY; index++)
  5188. {
  5189. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5190. {
  5191. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5192. }
  5193. }
  5194. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5195. }
  5196. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5197. {
  5198. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5199. {
  5200. tempIndex = ((gun_index==2) ? 1: 0);
  5201. }
  5202. else
  5203. {
  5204. tempIndex = gun_index;
  5205. }
  5206. for (int index = 0; index < GB_QUANTITY; index++)
  5207. {
  5208. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5209. {
  5210. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5211. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5212. }
  5213. }
  5214. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5215. }
  5216. else if(gunType[gun_index] == GUN_TYPE_DO)
  5217. {
  5218. tempIndex = gun_index;
  5219. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5220. {
  5221. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5222. {
  5223. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5224. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5225. }
  5226. }
  5227. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5228. }
  5229. else
  5230. {
  5231. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5232. {
  5233. tempIndex = 2;
  5234. }
  5235. else
  5236. {
  5237. tempIndex = gun_index;
  5238. }
  5239. for (int index = 0; index < AC_QUANTITY; index++)
  5240. {
  5241. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5242. {
  5243. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5244. }
  5245. }
  5246. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5247. }
  5248. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5249. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5250. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5251. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5252. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5253. }
  5254. //***********************************************(5)VOLTAGE L1******************************************************/
  5255. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5256. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5257. (dataType == ReadingContext_Trigger))
  5258. {
  5259. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5260. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5261. {
  5262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5263. {
  5264. tempIndex = ((gun_index==2) ? 1: 0);
  5265. }
  5266. else
  5267. {
  5268. tempIndex = gun_index;
  5269. }
  5270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5273. {
  5274. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5275. }
  5276. }
  5277. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5278. }
  5279. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5280. {
  5281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5282. {
  5283. tempIndex = ((gun_index==2) ? 1: 0);
  5284. }
  5285. else
  5286. {
  5287. tempIndex = gun_index;
  5288. }
  5289. for (int index = 0; index < CCS_QUANTITY; index++)
  5290. {
  5291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5292. {
  5293. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5294. }
  5295. }
  5296. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5297. }
  5298. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5299. {
  5300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5301. {
  5302. tempIndex = ((gun_index==2) ? 1: 0);
  5303. }
  5304. else
  5305. {
  5306. tempIndex = gun_index;
  5307. }
  5308. for (int index = 0; index < GB_QUANTITY; index++)
  5309. {
  5310. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5311. {
  5312. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5313. }
  5314. }
  5315. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5316. }
  5317. else if(gunType[gun_index] == GUN_TYPE_DO)
  5318. {
  5319. tempIndex = gun_index;
  5320. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5321. {
  5322. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5323. {
  5324. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5325. }
  5326. }
  5327. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5328. }
  5329. else
  5330. {
  5331. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5332. {
  5333. tempIndex = 2;
  5334. }
  5335. else
  5336. {
  5337. tempIndex = gun_index;
  5338. }
  5339. for (int index = 0; index < AC_QUANTITY; index++)
  5340. {
  5341. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5342. {
  5343. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5344. }
  5345. }
  5346. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5347. }
  5348. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5349. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5350. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5351. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5352. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5353. }
  5354. //***********************************************(6)SOC******************************************************/
  5355. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5356. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5357. (dataType == ReadingContext_Trigger))
  5358. {
  5359. 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))
  5360. {
  5361. //idx_sample=5;
  5362. //sampledValue = NULL;
  5363. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5364. {
  5365. tempIndex = ((gun_index==2) ? 1: 0);
  5366. }
  5367. else
  5368. {
  5369. tempIndex = gun_index;
  5370. }
  5371. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5372. {
  5373. //tempIndex = ((gun_index==2) ? 1: 0);
  5374. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5375. {
  5376. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5377. {
  5378. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5379. }
  5380. }
  5381. }
  5382. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5383. {
  5384. //tempIndex = ((gun_index==2) ? 1: 0);
  5385. for (int index = 0; index < CCS_QUANTITY; index++)
  5386. {
  5387. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5388. {
  5389. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5390. }
  5391. }
  5392. }
  5393. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5394. {
  5395. //tempIndex = ((gun_index==2) ? 1: 0);
  5396. for (int index = 0; index < GB_QUANTITY; index++)
  5397. {
  5398. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5399. {
  5400. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5401. }
  5402. }
  5403. }
  5404. else if(gunType[gun_index] == GUN_TYPE_DO)
  5405. {
  5406. //tempIndex = ((gun_index==2) ? 1: 0);
  5407. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5408. {
  5409. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5410. {
  5411. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5412. }
  5413. }
  5414. }
  5415. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5416. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5417. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5418. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5419. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5420. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5421. }
  5422. }
  5423. //********************************(7)Current.Import L2************************************************/
  5424. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5425. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5426. (dataType == ReadingContext_Trigger))
  5427. {
  5428. // Only for AC 3 phase
  5429. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5430. {
  5431. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5432. {
  5433. tempIndex = 2;
  5434. }
  5435. else
  5436. {
  5437. tempIndex = gun_index;
  5438. }
  5439. for (int index = 0; index < AC_QUANTITY; index++)
  5440. {
  5441. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5442. {
  5443. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5444. }
  5445. }
  5446. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5447. }
  5448. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5449. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5450. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5451. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5453. }
  5454. //********************************(8)Current.Import L3************************************************/
  5455. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5456. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5457. (dataType == ReadingContext_Trigger))
  5458. {
  5459. // Only for AC 3 phase
  5460. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5461. {
  5462. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5463. {
  5464. tempIndex = 2;
  5465. }
  5466. else
  5467. {
  5468. tempIndex = gun_index;
  5469. }
  5470. for (int index = 0; index < AC_QUANTITY; index++)
  5471. {
  5472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5473. {
  5474. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5475. }
  5476. }
  5477. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5478. }
  5479. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5480. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5481. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5482. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5483. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5484. }
  5485. //***********************************************(9)VOLTAGE L2******************************************************/
  5486. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5487. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5488. (dataType == ReadingContext_Trigger))
  5489. {
  5490. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5491. {
  5492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5493. {
  5494. tempIndex = 2;
  5495. }
  5496. else
  5497. {
  5498. tempIndex = gun_index;
  5499. }
  5500. for (int index = 0; index < AC_QUANTITY; index++)
  5501. {
  5502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5503. {
  5504. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5505. }
  5506. }
  5507. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5508. }
  5509. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5510. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5511. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5512. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5513. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5514. }
  5515. //***********************************************(10)VOLTAGE L3******************************************************/
  5516. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5517. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5518. (dataType == ReadingContext_Trigger))
  5519. {
  5520. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5521. {
  5522. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5523. {
  5524. tempIndex = 2;
  5525. }
  5526. else
  5527. {
  5528. tempIndex = gun_index;
  5529. }
  5530. for (int index = 0; index < AC_QUANTITY; index++)
  5531. {
  5532. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5533. {
  5534. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5535. }
  5536. }
  5537. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5538. }
  5539. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5540. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5541. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5542. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5543. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5544. }
  5545. // Message create ====================================================================================================
  5546. if(TRUE)
  5547. {
  5548. json_object *MeterValueReq = json_object_new_object();
  5549. json_object *MeterValues = json_object_new_array();
  5550. json_object *sampledValues = json_object_new_array();
  5551. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  5552. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  5553. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  5554. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  5555. {
  5556. json_object *MeterValue = json_object_new_object();
  5557. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5558. {
  5559. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5560. {
  5561. json_object *sampledValue = json_object_new_object();
  5562. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5563. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5564. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5565. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5566. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5567. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5568. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5569. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5570. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5571. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5572. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5573. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5574. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5575. json_object_array_add(sampledValues, sampledValue);
  5576. }
  5577. }
  5578. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5579. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5580. json_object_array_add(MeterValues, MeterValue);
  5581. }
  5582. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5583. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5584. ,gun_index + 1
  5585. ,MESSAGE_TYPE_CALL
  5586. ,guid
  5587. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5588. json_object_put(MeterValueReq);
  5589. }
  5590. // Put request guid to hash map
  5591. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5592. 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*/)
  5593. {
  5594. result = PASS;
  5595. //DEBUG_INFO("MeterValues mapitem pass\n");
  5596. }
  5597. if((dataType != ReadingContext_Trigger) &&
  5598. (dataType != ReadingContext_Sample_Clock) &&
  5599. (ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1))
  5600. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5601. else
  5602. {
  5603. if(FirstHeartBeat)
  5604. LWS_Send(queuedata +2);
  5605. }
  5606. return result;
  5607. }
  5608. int sendLogStatusNotificationRequest(char *status)
  5609. {
  5610. mtrace();
  5611. int result = PASS;
  5612. char message[4096]={0};
  5613. char guid[37]={0};
  5614. char tempdata[128]={0};
  5615. json_object *LogStatusNotification = json_object_new_object();
  5616. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5617. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  5618. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  5619. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  5620. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  5621. random_uuid(guid);
  5622. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5623. json_object_put(LogStatusNotification);
  5624. LWS_Send(message);
  5625. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5626. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5627. {
  5628. result = PASS;
  5629. }
  5630. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  5631. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  5632. return result;
  5633. }
  5634. int sendSecurityEventNotificationRequest()
  5635. {
  5636. mtrace();
  5637. int result = PASS;
  5638. char message[4096]={0};
  5639. char guid[37]={0};
  5640. char tempdata[128]={0};
  5641. json_object *SecurityEventNotification = json_object_new_object();
  5642. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5643. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  5644. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  5645. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  5646. random_uuid(guid);
  5647. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5648. json_object_put(SecurityEventNotification);
  5649. LWS_Send(message);
  5650. sprintf(tempdata, "SecurityEventNotification,0");
  5651. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5652. {
  5653. result = PASS;
  5654. }
  5655. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  5656. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  5657. return result;
  5658. }
  5659. int sendSignCertificateRequest()
  5660. {
  5661. mtrace();
  5662. int result = PASS;
  5663. char message[4096]={0};
  5664. char guid[37]={0};
  5665. char tempdata[128]={0};
  5666. json_object *SignCertificate = json_object_new_object();
  5667. DEBUG_INFO("sendSignCertificateRequest...\n");
  5668. // Read csr file content
  5669. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  5670. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  5671. char *line = NULL;
  5672. size_t len = 0;
  5673. while(getline(&line, &len, fp) != -1)
  5674. {
  5675. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5676. {
  5677. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  5678. }
  5679. }
  5680. fclose(fp);
  5681. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  5682. random_uuid(guid);
  5683. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5684. json_object_put(SignCertificate);
  5685. LWS_Send(message);
  5686. sprintf(tempdata, "SignCertificate,0");
  5687. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5688. {
  5689. result = PASS;
  5690. }
  5691. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  5692. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  5693. return result;
  5694. }
  5695. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5696. {
  5697. mtrace();
  5698. int result = PASS;
  5699. char message[110]={0};
  5700. char guid[37]={0};
  5701. char tempdata[65]={0};
  5702. json_object *FirmwareStatusNotification = json_object_new_object();
  5703. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5704. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5705. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  5706. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  5707. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  5708. random_uuid(guid);
  5709. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5710. json_object_put(FirmwareStatusNotification);
  5711. LWS_Send(message);
  5712. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5713. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5714. {
  5715. result = PASS;
  5716. }
  5717. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5718. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5719. return result;
  5720. }
  5721. //==========================================
  5722. // send confirm routine
  5723. //==========================================
  5724. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5725. {
  5726. mtrace();
  5727. int result = FAIL;
  5728. char message[100]={0};
  5729. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5730. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5731. LWS_Send(message);
  5732. result = TRUE;
  5733. return result;
  5734. }
  5735. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5736. {
  5737. mtrace();
  5738. int result = FAIL;
  5739. char message[100]={0};
  5740. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5741. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5742. LWS_Send(message);
  5743. result = TRUE;
  5744. return result;
  5745. }
  5746. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5747. {
  5748. mtrace();
  5749. int result = FAIL;
  5750. char message[100]={0};
  5751. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5752. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5753. LWS_Send(message);
  5754. result = TRUE;
  5755. return result;
  5756. }
  5757. int sendClearCacheConfirmation(char *uuid,char *payload)
  5758. {
  5759. mtrace();
  5760. int result = FAIL;
  5761. char message[500]={0};
  5762. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5763. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5764. LWS_Send(message);
  5765. return result;
  5766. }
  5767. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5768. {
  5769. mtrace();
  5770. int result = FAIL;
  5771. char message[500]={0};
  5772. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5773. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5774. LWS_Send(message);
  5775. return result;
  5776. }
  5777. int sendDataTransferConfirmation(char *uuid,char *payload)
  5778. {
  5779. mtrace();
  5780. char statusStr[20]={0};
  5781. char dataStr[10]={0};
  5782. char sstr[20]={0};
  5783. int c = 0;
  5784. char *loc;
  5785. int result = FAIL;
  5786. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5787. /**********************status**************************/
  5788. loc = strstr(payload, "status");
  5789. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5790. c = 0;
  5791. while (loc[3+strlen("status")+c] != '\"')
  5792. {
  5793. sstr[c] = loc[3+strlen("status")+c];
  5794. c++;
  5795. }
  5796. sstr[c] = '\0';
  5797. strcpy(statusStr, sstr);
  5798. /**********************data**************************/
  5799. loc = strstr(payload, "data");
  5800. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5801. c = 0;
  5802. while (loc[3+strlen("data")+c] != '\"')
  5803. {
  5804. sstr[c] = loc[3+strlen("data")+c];
  5805. c++;
  5806. }
  5807. sstr[c] = '\0';
  5808. strcpy(dataStr, sstr);
  5809. return result;
  5810. }
  5811. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5812. {
  5813. mtrace();
  5814. int result = FAIL;
  5815. char message[1000]={0};
  5816. int CompositeScheduleIndex = 0;
  5817. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5818. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5819. if(nPeriod == 0)
  5820. {
  5821. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5822. {
  5823. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5824. ,MESSAGE_TYPE_CALLRESULT
  5825. ,uuid
  5826. ,payload
  5827. ,connectorIdInt);
  5828. }
  5829. else
  5830. {
  5831. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5832. ,MESSAGE_TYPE_CALLRESULT
  5833. ,uuid
  5834. ,payload
  5835. ,connectorIdInt
  5836. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5837. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5838. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5839. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5840. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5841. }
  5842. }
  5843. else
  5844. {
  5845. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5846. ,MESSAGE_TYPE_CALLRESULT
  5847. ,uuid
  5848. ,payload
  5849. ,connectorIdInt
  5850. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5851. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5852. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5853. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5854. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5855. {
  5856. if (idx_sample == 0)
  5857. {
  5858. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5859. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5860. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5861. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5862. }
  5863. else
  5864. {
  5865. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5866. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5867. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5868. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5869. }
  5870. }
  5871. sprintf(message + strlen(message), "]}}]");
  5872. }
  5873. LWS_Send(message);
  5874. result = TRUE;
  5875. return result;
  5876. }
  5877. int sendGetConfigurationConfirmation(char *uuid)
  5878. {
  5879. mtrace();
  5880. int result = FAIL;
  5881. int MaxKeySupported = 0;
  5882. int sentConfigurationNumber= 0;
  5883. int sentunConfigurationNumber= 0;
  5884. char message[4000]={0};
  5885. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5886. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5887. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5888. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5889. ,MESSAGE_TYPE_CALLRESULT
  5890. ,uuid );
  5891. //configuration key
  5892. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5893. {
  5894. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5895. {
  5896. if (sentConfigurationNumber == 0)
  5897. {
  5898. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5899. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5900. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5901. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5902. }
  5903. else
  5904. {
  5905. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5906. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5907. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5908. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5909. }
  5910. sentConfigurationNumber = sentConfigurationNumber + 1;
  5911. }
  5912. }
  5913. sprintf(message + strlen(message), "]");
  5914. if(UnknownKeynum != 0)
  5915. {
  5916. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5917. //unkown key
  5918. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5919. {
  5920. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5921. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5922. if(sentunConfigurationNumber == 0)
  5923. {
  5924. sprintf(message + strlen(message), "\"%s\""
  5925. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5926. }
  5927. else
  5928. {
  5929. sprintf(message + strlen(message), ",\"%s\""
  5930. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5931. }
  5932. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5933. }
  5934. sprintf(message + strlen(message), "]");
  5935. }
  5936. sprintf(message + strlen(message), "}]");
  5937. LWS_Send(message);
  5938. return result;
  5939. }
  5940. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5941. {
  5942. mtrace();
  5943. int result = FAIL;
  5944. char message[400]={0};
  5945. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5946. if(strcmp(payload,"")==0)
  5947. {
  5948. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5949. }
  5950. else
  5951. {
  5952. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5953. }
  5954. LWS_Send(message);
  5955. result = TRUE;
  5956. return result;
  5957. }
  5958. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5959. {
  5960. mtrace();
  5961. int result = FAIL;
  5962. char message[80]={0};
  5963. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5964. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  5965. LWS_Send(message);
  5966. result = TRUE;
  5967. return result;
  5968. }
  5969. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5970. {
  5971. mtrace();
  5972. int result = FAIL;
  5973. char message[80]={0};
  5974. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5975. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5976. LWS_Send(message);
  5977. result = TRUE;
  5978. return result;
  5979. }
  5980. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5981. {
  5982. mtrace();
  5983. int result = FAIL;
  5984. char message[80]={0};
  5985. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5986. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5987. LWS_Send(message);
  5988. result = TRUE;
  5989. return result;
  5990. }
  5991. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5992. {
  5993. mtrace();
  5994. int result = FAIL;
  5995. char message[80]={0};
  5996. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5997. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5998. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5999. LWS_Send(message);
  6000. result = TRUE;
  6001. return result;
  6002. }
  6003. int sendResetConfirmation(char *uuid,char *payload)
  6004. {
  6005. mtrace();
  6006. int result = FAIL;
  6007. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6008. char message[80]={0};
  6009. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6010. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6011. LWS_Send(message);
  6012. result = TRUE;
  6013. return result;
  6014. }
  6015. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6016. {
  6017. mtrace();
  6018. int result = FAIL;
  6019. char message[500]={0};
  6020. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6021. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6022. LWS_Send(message);
  6023. result = TRUE;
  6024. return result;
  6025. }
  6026. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6027. {
  6028. mtrace();
  6029. int result = FAIL;
  6030. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6031. char message[80]={0};
  6032. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6033. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6034. LWS_Send(message);
  6035. result = TRUE;
  6036. return result;
  6037. }
  6038. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6039. {
  6040. mtrace();
  6041. int result = FAIL;
  6042. char message[80]={0};
  6043. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6044. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6045. LWS_Send(message);
  6046. result = TRUE;
  6047. return result;
  6048. }
  6049. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6050. {
  6051. mtrace();
  6052. int result = FAIL;
  6053. char message[80]={0};
  6054. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6055. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6056. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6057. LWS_Send(message);
  6058. result = TRUE;
  6059. return result;
  6060. }
  6061. int sendUpdateFirmwareConfirmation(char *uuid)
  6062. {
  6063. mtrace();
  6064. int result = FAIL;
  6065. char message[60]={0};
  6066. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6067. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6068. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6069. LWS_Send(message);
  6070. result = TRUE;
  6071. return result;
  6072. }
  6073. int sendCertificateSignedConfirmation(char *uuid)
  6074. {
  6075. mtrace();
  6076. int result = PASS;
  6077. char message[4096]={0};
  6078. json_object *CertificateSigned = json_object_new_object();
  6079. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6080. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6081. sprintf(message,"[%d,\"%s\",%s]"
  6082. ,MESSAGE_TYPE_CALLRESULT
  6083. ,uuid
  6084. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6085. json_object_put(CertificateSigned);
  6086. LWS_Send(message);
  6087. return result;
  6088. }
  6089. int sendDeleteCertificateConfirmation(char *uuid)
  6090. {
  6091. mtrace();
  6092. int result = PASS;
  6093. char message[4096]={0};
  6094. json_object *DeleteCertificate = json_object_new_object();
  6095. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6096. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6097. sprintf(message,"[%d,\"%s\",%s]"
  6098. ,MESSAGE_TYPE_CALLRESULT
  6099. ,uuid
  6100. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6101. json_object_put(DeleteCertificate);
  6102. LWS_Send(message);
  6103. return result;
  6104. }
  6105. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6106. {
  6107. mtrace();
  6108. int result = PASS;
  6109. char message[4096]={0};
  6110. json_object *ExtendedTriggerMessage = json_object_new_object();
  6111. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6112. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6113. sprintf(message,"[%d,\"%s\",%s]"
  6114. ,MESSAGE_TYPE_CALLRESULT
  6115. ,uuid
  6116. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6117. json_object_put(ExtendedTriggerMessage);
  6118. LWS_Send(message);
  6119. return result;
  6120. }
  6121. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6122. {
  6123. mtrace();
  6124. int result = PASS;
  6125. char message[4096]={0};
  6126. json_object *GetInstalledCertificateIds = json_object_new_object();
  6127. json_object *certificateHashDataDatas = json_object_new_array();
  6128. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6129. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6130. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6131. {
  6132. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6133. {
  6134. json_object *certificateHashData = json_object_new_object();
  6135. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6136. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6137. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6138. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6139. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6140. }
  6141. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6142. }
  6143. else
  6144. {
  6145. json_object_put(certificateHashDataDatas);
  6146. }
  6147. sprintf(message,"[%d,\"%s\",%s]"
  6148. ,MESSAGE_TYPE_CALLRESULT
  6149. ,uuid
  6150. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6151. json_object_put(GetInstalledCertificateIds);
  6152. LWS_Send(message);
  6153. return result;
  6154. }
  6155. int sendGetLogConfirmation(char *uuid)
  6156. {
  6157. mtrace();
  6158. int result = PASS;
  6159. char message[4096]={0};
  6160. json_object *GetLog = json_object_new_object();
  6161. DEBUG_INFO("sendGetLogConfirmation...\n");
  6162. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6163. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6164. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6165. sprintf(message,"[%d,\"%s\",%s]"
  6166. ,MESSAGE_TYPE_CALLRESULT
  6167. ,uuid
  6168. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6169. json_object_put(GetLog);
  6170. LWS_Send(message);
  6171. return result;
  6172. }
  6173. int sendInstallCertificateConfirmation(char *uuid)
  6174. {
  6175. mtrace();
  6176. int result = PASS;
  6177. char message[4096]={0};
  6178. json_object *InstallCertificate = json_object_new_object();
  6179. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6180. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6181. sprintf(message,"[%d,\"%s\",%s]"
  6182. ,MESSAGE_TYPE_CALLRESULT
  6183. ,uuid
  6184. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6185. json_object_put(InstallCertificate);
  6186. LWS_Send(message);
  6187. return result;
  6188. }
  6189. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6190. {
  6191. mtrace();
  6192. int result = PASS;
  6193. char message[4096]={0};
  6194. json_object *SignedUpdateFirmware = json_object_new_object();
  6195. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6196. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  6197. sprintf(message,"[%d,\"%s\",%s]"
  6198. ,MESSAGE_TYPE_CALLRESULT
  6199. ,uuid
  6200. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6201. json_object_put(SignedUpdateFirmware);
  6202. LWS_Send(message);
  6203. return result;
  6204. }
  6205. int sendUnknownConfirmation(char *uuid)
  6206. {
  6207. mtrace();
  6208. int result = PASS;
  6209. char message[256]={0};
  6210. DEBUG_INFO("sendUnknownConfirmation...\n");
  6211. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6212. LWS_Send(message);
  6213. return result;
  6214. }
  6215. //==========================================
  6216. // Handle server request routine Start
  6217. //==========================================
  6218. int handleCancelReservationRequest(char *uuid, char *payload)
  6219. {
  6220. mtrace();
  6221. int result = FAIL;
  6222. int gunNO = 0;
  6223. int reservationIdInt = -1;
  6224. char comfirmstr[20];
  6225. DEBUG_INFO("handleCancelReservationRequest...\n");
  6226. json_object *CancelReservation;
  6227. CancelReservation = json_tokener_parse(payload);
  6228. if(!is_error(CancelReservation))
  6229. {
  6230. // Required data
  6231. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6232. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6233. }
  6234. json_object_put(CancelReservation);
  6235. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6236. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6237. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6238. if(reservationIdInt != -1)
  6239. {
  6240. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6241. //check Transaction active
  6242. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6243. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6244. {
  6245. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6246. {
  6247. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6248. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6249. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6250. {
  6251. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6252. }
  6253. else
  6254. {
  6255. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6256. }
  6257. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6258. goto end;
  6259. }
  6260. }
  6261. for (int index = 0; index < CCS_QUANTITY; index++)
  6262. {
  6263. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6264. {
  6265. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6266. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6267. if(gunType[2] == GUN_TYPE_CCS)
  6268. {
  6269. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6270. }
  6271. else
  6272. {
  6273. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6274. }
  6275. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6276. goto end;
  6277. }
  6278. }
  6279. for (int index = 0; index < GB_QUANTITY; index++)
  6280. {
  6281. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6282. {
  6283. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6284. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6285. if(gunType[2] == GUN_TYPE_GBT)
  6286. {
  6287. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6288. }
  6289. else
  6290. {
  6291. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6292. }
  6293. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6294. goto end;
  6295. }
  6296. }
  6297. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6298. {
  6299. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6300. {
  6301. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6302. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6303. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6304. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6305. goto end;
  6306. }
  6307. }
  6308. for (int index = 0; index < AC_QUANTITY; index++)
  6309. {
  6310. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6311. {
  6312. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6313. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6314. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6315. {
  6316. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6317. }
  6318. else
  6319. {
  6320. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6321. }
  6322. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6323. goto end;
  6324. }
  6325. }
  6326. }
  6327. //The reservationId does NOT match the reservationId
  6328. sendCancelReservationConfirmation(uuid, comfirmstr);
  6329. end:
  6330. // Fill in ocpp packet uuid
  6331. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  6332. return result;
  6333. }
  6334. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6335. {
  6336. mtrace();
  6337. int result = FAIL;
  6338. int gunIndex = 0;
  6339. char typeStr[16]={0};
  6340. char comfirmstr[20];
  6341. int specificId = FALSE;
  6342. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6343. json_object *ChangeAvailability;
  6344. ChangeAvailability = json_tokener_parse(payload);
  6345. if(!is_error(ChangeAvailability))
  6346. {
  6347. // Required data
  6348. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6349. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6350. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6351. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6352. }
  6353. json_object_put(ChangeAvailability);
  6354. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6355. {
  6356. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6357. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6358. }
  6359. else if(gunIndex == 0)
  6360. {
  6361. for(int i=0; i < gunTotalNumber; i++)
  6362. {
  6363. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  6364. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  6365. }
  6366. }
  6367. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6368. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6369. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6370. {
  6371. specificId = TRUE;
  6372. }
  6373. if(specificId == FALSE)
  6374. goto end;
  6375. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6376. {
  6377. //----------------------gunIndex is 0 ------------------------------------------------//
  6378. if(gunIndex == 0)
  6379. {
  6380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6381. {
  6382. for(int i=0; i < gunTotalNumber; i++)
  6383. {
  6384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6385. {
  6386. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6387. {
  6388. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6389. {
  6390. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6391. goto end;
  6392. }
  6393. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6394. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6395. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6396. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6397. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6398. {
  6399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6400. goto end;
  6401. }
  6402. }
  6403. }//END FOR CHAdeMO_QUANTITY
  6404. for (int index = 0; index < CCS_QUANTITY; index++)
  6405. {
  6406. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6407. {
  6408. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6409. {
  6410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6411. goto end;
  6412. }
  6413. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6414. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6415. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6416. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6417. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6418. {
  6419. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6420. goto end;
  6421. }
  6422. }
  6423. }//END FOR CCS_QUANTITY
  6424. for (int index = 0; index < GB_QUANTITY; index++)
  6425. {
  6426. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6427. {
  6428. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6429. {
  6430. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6431. goto end;
  6432. }
  6433. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6434. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6435. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6436. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6437. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6438. {
  6439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6440. goto end;
  6441. }
  6442. }
  6443. }// END FOR GB_QUANTITY
  6444. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6445. {
  6446. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6447. {
  6448. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6449. {
  6450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6451. goto end;
  6452. }
  6453. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6454. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6455. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6456. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6457. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6458. {
  6459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6460. goto end;
  6461. }
  6462. }
  6463. }// END FOR GENERAL_GUN_QUANTITY
  6464. for (int index = 0; index < AC_QUANTITY; index++)
  6465. {
  6466. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6467. {
  6468. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6469. {
  6470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6471. goto end;
  6472. }
  6473. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6474. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6475. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6476. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6477. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6478. {
  6479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6480. goto end;
  6481. }
  6482. }
  6483. }//END FOR AC_QUANTITY
  6484. }// END FOR gunTotalNumber
  6485. }
  6486. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6487. {
  6488. for(int i=0; i < gunTotalNumber; i++)
  6489. {
  6490. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6491. {
  6492. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6493. goto end;
  6494. }
  6495. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6496. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6497. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6498. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6499. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6500. {
  6501. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6502. goto end;
  6503. }
  6504. }
  6505. }
  6506. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6507. goto end;
  6508. }
  6509. //----------------------gunIndex is not 0 ------------------------------------------------//
  6510. //check Transaction active
  6511. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6512. {
  6513. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6514. {
  6515. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6516. {
  6517. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6518. goto end;
  6519. }
  6520. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6521. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6522. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6523. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6524. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6525. {
  6526. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6527. goto end;
  6528. }
  6529. else
  6530. {
  6531. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6532. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6533. goto end;
  6534. }
  6535. }
  6536. }//END FOR CHAdeMO_QUANTITY
  6537. for (int index = 0; index < CCS_QUANTITY; index++)
  6538. {
  6539. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6540. {
  6541. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6542. {
  6543. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6544. goto end;
  6545. }
  6546. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6547. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6548. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6549. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6550. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6551. {
  6552. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6553. goto end;
  6554. }
  6555. else
  6556. {
  6557. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6558. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6559. goto end;
  6560. }
  6561. }
  6562. }//END FOR CCS_QUANTITY
  6563. for (int index = 0; index < GB_QUANTITY; index++)
  6564. {
  6565. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6566. {
  6567. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6568. {
  6569. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6570. goto end;
  6571. }
  6572. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6573. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6574. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6575. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6576. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6577. {
  6578. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6579. goto end;
  6580. }
  6581. else
  6582. {
  6583. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6585. goto end;
  6586. }
  6587. }
  6588. }// END FOR GB_QUANTITY
  6589. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6590. {
  6591. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6592. {
  6593. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6594. {
  6595. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6596. goto end;
  6597. }
  6598. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6599. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6600. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6601. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6602. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6603. {
  6604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6605. goto end;
  6606. }
  6607. else
  6608. {
  6609. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6611. goto end;
  6612. }
  6613. }
  6614. }// END FOR GENERAL_GUN_QUANTITY
  6615. for (int index = 0; index < AC_QUANTITY; index++)
  6616. {
  6617. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6618. {
  6619. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6620. {
  6621. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6622. goto end;
  6623. }
  6624. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6625. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6626. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6627. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6628. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6629. {
  6630. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6631. goto end;
  6632. }
  6633. else
  6634. {
  6635. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6637. goto end;
  6638. }
  6639. }
  6640. }//END FOR AC_QUANTITY
  6641. }//END FOR AvailabilityTypeStr[Inoperative]
  6642. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6643. {
  6644. //----------------------gunIndex is 0 ------------------------------------------------//
  6645. if(gunIndex == 0)
  6646. {
  6647. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6648. {
  6649. for(int i=0; i < gunTotalNumber; i++)
  6650. {
  6651. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6652. {
  6653. 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
  6654. {
  6655. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6656. goto end;
  6657. }
  6658. }//END FOR CHAdeMO_QUANTITY
  6659. for (int index = 0; index < CCS_QUANTITY; index++)
  6660. {
  6661. 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
  6662. {
  6663. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6664. goto end;
  6665. }
  6666. }//END FOR CCS_QUANTITY
  6667. for (int index = 0; index < GB_QUANTITY; index++)
  6668. {
  6669. 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
  6670. {
  6671. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6672. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6673. goto end;
  6674. }
  6675. }// END FOR GB_QUANTITY
  6676. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6677. {
  6678. 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
  6679. {
  6680. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6681. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6682. goto end;
  6683. }
  6684. }// END FOR GENERAL_GUN_QUANTITY
  6685. for (int index = 0; index < AC_QUANTITY; index++)
  6686. {
  6687. 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
  6688. {
  6689. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6690. goto end;
  6691. }
  6692. }//END FOR CHAdeMO_QUANTITY
  6693. }// END FOR gunTotalNumber
  6694. }
  6695. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6696. {
  6697. for(int i=0; i < gunTotalNumber; i++)
  6698. {
  6699. for (int index = 0; index < AC_QUANTITY; index++)
  6700. {
  6701. 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
  6702. {
  6703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6704. goto end;
  6705. }
  6706. }//END FOR CHAdeMO_QUANTITY
  6707. } // END FOR gunTotalNumber
  6708. }
  6709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6710. goto end;
  6711. }
  6712. //----------------------gunIndex is not 0 ------------------------------------------------//
  6713. //check Transaction active
  6714. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6715. {
  6716. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6717. {
  6718. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6719. goto end;
  6720. }
  6721. }//END FOR CHAdeMO_QUANTITY
  6722. for (int index = 0; index < CCS_QUANTITY; index++)
  6723. {
  6724. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6725. {
  6726. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6727. goto end;
  6728. }
  6729. }//END FOR CCS_QUANTITY
  6730. for (int index = 0; index < GB_QUANTITY; index++)
  6731. {
  6732. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6733. {
  6734. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6735. goto end;
  6736. }
  6737. }// END FOR GB_QUANTITY
  6738. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6739. {
  6740. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6741. {
  6742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6743. goto end;
  6744. }
  6745. }// END FOR GENERAL_GUN_QUANTITY
  6746. for (int index = 0; index < AC_QUANTITY; index++)
  6747. {
  6748. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6749. {
  6750. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6751. goto end;
  6752. }
  6753. }//END FOR AC_QUANTITY
  6754. }//END FOR AvailabilityTypeStr[Operative]
  6755. end:
  6756. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6757. {
  6758. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6759. }
  6760. else
  6761. {
  6762. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6763. }
  6764. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6765. {
  6766. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6767. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6768. }
  6769. else if(gunIndex == 0)
  6770. {
  6771. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6772. {
  6773. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6774. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6775. }
  6776. }
  6777. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6778. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6779. return result;
  6780. }
  6781. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6782. {
  6783. mtrace();
  6784. int result = FAIL;
  6785. char keystr[40]={0};
  6786. char valuestr[256]={0};
  6787. char comfirmstr[20]={0};
  6788. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6789. json_object *ChangeConfiguration;
  6790. ChangeConfiguration = json_tokener_parse(payload);
  6791. if(!is_error(ChangeConfiguration))
  6792. {
  6793. // Required data
  6794. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6795. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6796. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6797. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6798. }
  6799. json_object_put(ChangeConfiguration);
  6800. if((uuid==NULL) || (payload ==NULL) )
  6801. {
  6802. DEBUG_ERROR("Payload is null\n");
  6803. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6804. }
  6805. else
  6806. {
  6807. int status = setKeyValue(keystr, valuestr);
  6808. switch(status)
  6809. {
  6810. case ConfigurationStatus_Accepted:
  6811. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6812. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  6813. StoreConfigurationTable();
  6814. break;
  6815. case RebootRequired:
  6816. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6817. StoreConfigurationTable();
  6818. break;
  6819. case NotSupported:
  6820. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6821. break;
  6822. case ConfigurationStatus_Rejected:
  6823. default:
  6824. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6825. break;
  6826. }
  6827. }
  6828. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6829. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  6830. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6831. {
  6832. ChageWebSocketPingInterval(atoi(valuestr));
  6833. }
  6834. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6835. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6836. {
  6837. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6838. SetOcppConnStatus(FALSE);
  6839. }
  6840. return result;
  6841. }
  6842. int handleClearCacheRequest(char *uuid, char *payload)
  6843. {
  6844. mtrace();
  6845. int result = FAIL;
  6846. char comfirmstr[20];
  6847. char rmFileCmd[100]={0};
  6848. struct stat stats;
  6849. DEBUG_INFO("handleClearCacheRequest...\n");
  6850. stat("/Storage/OCPP_PH", &stats);
  6851. // Check for directory existence
  6852. if (S_ISDIR(stats.st_mode) == 1)
  6853. {}
  6854. else
  6855. {
  6856. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6857. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  6858. system(rmFileCmd);
  6859. }
  6860. if(OCPP_cleanLocalCache())
  6861. {
  6862. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6863. }
  6864. else
  6865. {
  6866. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6867. }
  6868. sendClearCacheConfirmation(uuid, comfirmstr);
  6869. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6870. return result;
  6871. }
  6872. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6873. {
  6874. mtrace();
  6875. int result = FAIL;
  6876. int resultRename;
  6877. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6878. char chargingProfilePurposeStr[26]={0};
  6879. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6880. char tempchargingProfilePurposeStr[26]={0};
  6881. char str[100]={0};
  6882. char fname[200]={0};
  6883. char comfirmstr[20]={0};
  6884. char word[1600]={0};
  6885. int clearflag = FALSE;
  6886. int chargingProfileIdIsNULL = FALSE;
  6887. int connectorIsNULL = FALSE;
  6888. int chargingProfilePurposeIsNULL = FALSE;
  6889. int stackLevelIsNULL = FALSE;
  6890. //int GotoEnd = FALSE;
  6891. FILE *fptr1, *fptr2;
  6892. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  6893. int n_chargingProfile=0;
  6894. int isEmptyFile = FALSE;
  6895. char sLineWord[1600]={0};
  6896. char chargingProfiles[10][100]={0};
  6897. int ChargeProfileCount = 0;
  6898. int ch;
  6899. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6900. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6901. json_object *ClearChargingProfile;
  6902. ClearChargingProfile = json_tokener_parse(payload);
  6903. if(!is_error(ClearChargingProfile))
  6904. {
  6905. // Optional data
  6906. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6907. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6908. else
  6909. chargingProfileIdIsNULL = TRUE;
  6910. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6911. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6912. else
  6913. connectorIsNULL = TRUE;
  6914. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6915. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6916. else
  6917. chargingProfilePurposeIsNULL = TRUE;
  6918. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6919. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6920. else
  6921. stackLevelIsNULL = TRUE;
  6922. }
  6923. json_object_put(ClearChargingProfile);
  6924. if(connectorIsNULL == FALSE)
  6925. {
  6926. switch(connectorIdInt)
  6927. {
  6928. case 0:
  6929. if(chargingProfilePurposeIsNULL == TRUE)
  6930. {
  6931. int l = 0;
  6932. strcpy(fname, ChargePointMaxProfile_JSON);
  6933. if((access(fname,F_OK))!=-1)
  6934. {
  6935. strcpy(chargingProfiles[l], fname);
  6936. l = l + 1;
  6937. }
  6938. strcpy(fname, TxDefaultProfile_0_JSON);
  6939. if((access(fname,F_OK))!=-1)
  6940. {
  6941. strcpy(chargingProfiles[l], fname);
  6942. l = l + 1;
  6943. }
  6944. ChargeProfileCount = l;
  6945. }
  6946. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6947. {
  6948. strcpy(fname, ChargePointMaxProfile_JSON);
  6949. if((access(fname,F_OK))!=-1)
  6950. {
  6951. strcpy(chargingProfiles[0], fname);
  6952. ChargeProfileCount = 1;
  6953. }
  6954. }
  6955. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6956. {
  6957. strcpy(fname, TxDefaultProfile_0_JSON);
  6958. if((access(fname,F_OK))!=-1)
  6959. {
  6960. strcpy(chargingProfiles[0], fname);
  6961. ChargeProfileCount = 1;
  6962. }
  6963. }
  6964. break;
  6965. default:
  6966. if(chargingProfilePurposeIsNULL == TRUE)
  6967. {
  6968. int m = 0;
  6969. memset(fname, 0, ARRAY_SIZE(fname));
  6970. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6971. if((access(fname,F_OK))!=-1)
  6972. {
  6973. strcpy(chargingProfiles[m], fname);
  6974. m = m + 1;
  6975. }
  6976. memset(fname, 0, ARRAY_SIZE(fname));
  6977. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  6978. if((access(fname,F_OK))!=-1)
  6979. {
  6980. strcpy(chargingProfiles[m], fname);
  6981. m = m + 1;
  6982. }
  6983. ChargeProfileCount = m;
  6984. }
  6985. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6986. {
  6987. //strcpy(fname, TxDefaultProfile_1_JSON);
  6988. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6989. if((access(fname,F_OK))!=-1)
  6990. {
  6991. strcpy(chargingProfiles[0], fname);
  6992. ChargeProfileCount = 1;
  6993. }
  6994. }
  6995. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6996. {
  6997. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  6998. if((access(fname,F_OK))!=-1)
  6999. {
  7000. strcpy(chargingProfiles[0], fname);
  7001. ChargeProfileCount = 1;
  7002. }
  7003. //strcpy(fname, TxProfile_1_JSON);
  7004. }
  7005. //strcpy(fname, ChargePointMaxProfile_JSON );
  7006. break;
  7007. }
  7008. }
  7009. else // Check all Charging Profiles
  7010. {
  7011. int i = 0;
  7012. char fnametemp[200]={0};
  7013. ChargeProfileCount = 0;
  7014. //Check ChargePointMaxProfile.json exit
  7015. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7016. {
  7017. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7018. i = i + 1;
  7019. }
  7020. //Check TxDefaultProfile_0.json exit
  7021. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7022. {
  7023. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7024. i = i + 1;
  7025. }
  7026. //Check TxDefaultProfile_%d.json
  7027. for(int j=1; j <= gunTotalNumber; j++)
  7028. {
  7029. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7030. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7031. if((access(fnametemp,F_OK))!=-1)
  7032. {
  7033. strcpy(chargingProfiles[i], fnametemp);
  7034. i = i + 1;
  7035. }
  7036. }
  7037. //Check TxProfile_%d.json
  7038. for(int j=1; j <= gunTotalNumber; j++)
  7039. {
  7040. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7041. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7042. if((access(fnametemp,F_OK))!=-1)
  7043. {
  7044. strcpy(chargingProfiles[i], fnametemp);
  7045. i = i + 1;
  7046. }
  7047. }
  7048. ChargeProfileCount = i;
  7049. }// End connectorIsNULL is TRUE
  7050. if(ChargeProfileCount == 0)
  7051. {
  7052. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7053. goto end;
  7054. }
  7055. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7056. {
  7057. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7058. goto end;
  7059. }
  7060. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7061. {
  7062. memset(str, 0, ARRAY_SIZE(str));
  7063. // clear temp file
  7064. sprintf(str,"rm -f %s",temp);
  7065. system(str);
  7066. for(int k=0; k < ChargeProfileCount; k++)
  7067. {
  7068. memset(str, 0, ARRAY_SIZE(str));
  7069. //clear file in C
  7070. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7071. system(str);
  7072. }
  7073. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7074. goto end;
  7075. }
  7076. else if(connectorIsNULL == TRUE)
  7077. {
  7078. for(int k=0; k < ChargeProfileCount; k++)
  7079. {
  7080. fptr1 = fopen(chargingProfiles[k], "r");
  7081. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7082. //Check Charging Profile Count
  7083. while(fscanf(fptr1, "%s", word) != EOF)
  7084. {
  7085. //DEBUG_INFO("word=%s\n",word);
  7086. if(strstr(word, "chargingProfileId")!= NULL)
  7087. {
  7088. //DEBUG_INFO("test chargingProfileId \n");
  7089. n_chargingProfile = n_chargingProfile + 1;
  7090. //DEBUG_INFO("chargingProfileId Found\n");
  7091. }
  7092. }
  7093. rewind(fptr1);
  7094. //search Charging Profile Element
  7095. //int i= 0;
  7096. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7097. {
  7098. json_object *tmpProfilee;
  7099. tmpProfilee = json_tokener_parse(sLineWord);
  7100. if(!is_error(tmpProfilee))
  7101. {
  7102. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7103. {
  7104. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7105. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7106. }
  7107. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7108. {
  7109. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7110. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7111. }
  7112. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7113. {
  7114. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7115. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7116. }
  7117. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7118. {
  7119. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7120. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7121. }
  7122. }
  7123. json_object_put(tmpProfilee);
  7124. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7125. {
  7126. //------- not write to fptr2-------//
  7127. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7128. //clearflag = TRUE;
  7129. }
  7130. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7131. {
  7132. //------- not write to fptr2-------//
  7133. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7134. }
  7135. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7136. {
  7137. //------- not write to fptr2-------//
  7138. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7139. }
  7140. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7141. {
  7142. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7143. }
  7144. else
  7145. {
  7146. fprintf(fptr2, sLineWord);//writing data into file
  7147. }
  7148. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7149. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7150. if(clearflag == TRUE)
  7151. {
  7152. fclose(fptr1);
  7153. fclose(fptr2);
  7154. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7155. system(str);
  7156. // clear temp file
  7157. sprintf(str,"rm -f %s",temp);
  7158. system(str);
  7159. }
  7160. else
  7161. {
  7162. fclose(fptr1);
  7163. fclose(fptr2);
  7164. memset(str, 0, ARRAY_SIZE(str));
  7165. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7166. system(str);
  7167. resultRename = rename(temp, chargingProfiles[k]);
  7168. if(resultRename == 0)
  7169. {
  7170. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7171. }
  7172. else
  7173. {
  7174. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7175. }
  7176. if(comfirmstr[0]== 0)
  7177. {
  7178. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7179. }
  7180. //Check chargingProfile is empty file
  7181. /*------ Read the file ----------------*/
  7182. fptr1=fopen(chargingProfiles[k],"r");
  7183. ch=fgetc(fptr1);
  7184. rewind(fptr1);
  7185. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7186. if(ch!=EOF)
  7187. {
  7188. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7189. {
  7190. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7191. if(sLineWord[0]=='\0')
  7192. {
  7193. isEmptyFile = TRUE;
  7194. break;
  7195. }
  7196. else
  7197. {
  7198. isEmptyFile = FALSE;
  7199. break;
  7200. }
  7201. }
  7202. }
  7203. else
  7204. isEmptyFile = TRUE;
  7205. fclose(fptr1);
  7206. if(isEmptyFile == TRUE)
  7207. {
  7208. memset(str, 0, ARRAY_SIZE(str));
  7209. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7210. system(str);
  7211. }
  7212. }
  7213. }// End of while(int k=0; k < ChargePointCount; k++)
  7214. }
  7215. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7216. {
  7217. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7218. for(int k=0; k < ChargeProfileCount; k++)
  7219. {
  7220. fptr1 = fopen(chargingProfiles[k], "r");
  7221. fptr2 = fopen(temp, "w+");
  7222. //Check Charging Profile Count
  7223. while(fscanf(fptr1, "%s", word) != EOF)
  7224. {
  7225. //DEBUG_INFO("word=%s\n",word);
  7226. if(strstr(word, "chargingProfileId")!= NULL)
  7227. {
  7228. n_chargingProfile = n_chargingProfile + 1;
  7229. }
  7230. }
  7231. rewind(fptr1);
  7232. //search Charging Profile Element
  7233. //int i= 0;
  7234. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7235. {
  7236. json_object *tmpProfilee;
  7237. tmpProfilee = json_tokener_parse(sLineWord);
  7238. if(!is_error(tmpProfilee))
  7239. {
  7240. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7241. {
  7242. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7243. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7244. }
  7245. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7246. {
  7247. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7248. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7249. }
  7250. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7251. {
  7252. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7253. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7254. }
  7255. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7256. {
  7257. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7258. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7259. }
  7260. }
  7261. json_object_put(tmpProfilee);
  7262. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7263. {
  7264. //------- not write to fptr2-------//
  7265. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7266. //clearflag = TRUE;
  7267. }
  7268. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7269. {
  7270. //------- not write to fptr2-------//
  7271. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7272. }
  7273. else if(stackLevelIsNULL == TRUE)
  7274. {
  7275. //Clear Whole File
  7276. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7277. clearflag = TRUE;
  7278. break;
  7279. }
  7280. else
  7281. {
  7282. fprintf(fptr2, sLineWord);//writing data into file
  7283. }
  7284. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7285. }
  7286. if(clearflag == TRUE)
  7287. {
  7288. fclose(fptr1);
  7289. fclose(fptr2);
  7290. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7291. system(str);
  7292. // clear temp file
  7293. sprintf(str,"rm -f %s",temp);
  7294. system(str);
  7295. }
  7296. else
  7297. {
  7298. fclose(fptr1);
  7299. fclose(fptr2);
  7300. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7301. system(str);
  7302. resultRename = rename(temp, chargingProfiles[k]);
  7303. if(resultRename == 0)
  7304. {
  7305. DEBUG_INFO("File ChargingProfile renamed successfully");
  7306. }
  7307. else
  7308. {
  7309. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7310. }
  7311. if(comfirmstr[0]== 0)
  7312. {
  7313. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7314. }
  7315. //Check chargingProfile is empty file
  7316. /*------ Read the file ----------------*/
  7317. fptr1=fopen(chargingProfiles[k],"r");
  7318. ch=fgetc(fptr1);
  7319. rewind(fptr1);
  7320. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7321. if(ch!=EOF)
  7322. {
  7323. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7324. {
  7325. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7326. if(sLineWord[0]=='\0')
  7327. {
  7328. isEmptyFile = TRUE;
  7329. break;
  7330. }
  7331. else
  7332. {
  7333. isEmptyFile = FALSE;
  7334. break;
  7335. }
  7336. }
  7337. }
  7338. else
  7339. isEmptyFile = TRUE;
  7340. fclose(fptr1);
  7341. if(isEmptyFile == TRUE)
  7342. {
  7343. memset(str, 0, ARRAY_SIZE(str));
  7344. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7345. system(str);
  7346. }
  7347. /*------- End of reading ---------------*/
  7348. }
  7349. } // while(int k=0; k < ChargeProfileCount; k++)
  7350. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7351. end:
  7352. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7353. {
  7354. if(connectorIdInt == 0)
  7355. {
  7356. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7357. {
  7358. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  7359. }
  7360. }
  7361. else
  7362. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  7363. }
  7364. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7365. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7366. return result;
  7367. }
  7368. void createFirmwareVersionByDataTransfer(void)
  7369. {
  7370. json_object *FirmwareDataTransfer = json_object_new_object();
  7371. // AC & DC model
  7372. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7373. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7374. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7375. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7376. // DC model
  7377. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7378. {
  7379. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7380. {
  7381. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7382. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7383. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7384. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7385. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7386. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7387. }
  7388. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7389. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7390. {
  7391. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7392. }
  7393. }
  7394. else
  7395. {
  7396. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7397. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7398. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7399. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7400. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7401. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7402. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7403. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7404. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7405. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7406. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7407. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7408. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7409. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7410. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7411. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7412. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7413. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7414. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7415. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7416. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7417. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7418. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7419. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7420. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7421. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7422. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7423. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7424. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7425. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7426. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7427. }
  7428. // 4G model
  7429. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7430. {
  7431. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7432. }
  7433. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7434. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7435. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7436. json_object_put(FirmwareDataTransfer);
  7437. }
  7438. int handleDataTransferRequest(char *uuid, char *payload)
  7439. {
  7440. mtrace();
  7441. json_object *response = json_object_new_object();
  7442. int result = FAIL;
  7443. char tempvendorId[255]={0};
  7444. char tempmessageId[50]={0};
  7445. char tempdata[512]={0};
  7446. char message[2048]={0};
  7447. DEBUG_INFO("handleDataTransferRequest...\n");
  7448. if((uuid != NULL) && (payload != NULL))
  7449. {
  7450. json_object *DataTransfer;
  7451. DataTransfer = json_tokener_parse(payload);
  7452. if(!is_error(DataTransfer))
  7453. {
  7454. // Required data
  7455. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7456. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7457. // Optional data
  7458. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7459. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7460. if(json_object_object_get(DataTransfer, "data") != NULL)
  7461. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7462. result = PASS;
  7463. }
  7464. json_object_put(DataTransfer);
  7465. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7466. {
  7467. // Send all moudle firmware version on EVSE
  7468. createFirmwareVersionByDataTransfer();
  7469. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7470. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  7471. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7472. json_object_put(response);
  7473. }
  7474. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7475. {
  7476. system("/usr/bin/run_tmate_restart.sh &");
  7477. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7478. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7479. json_object_put(response);
  7480. }
  7481. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7482. {
  7483. json_object *data;
  7484. data = json_tokener_parse(tempdata);
  7485. if(!is_error(data))
  7486. {
  7487. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7488. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7489. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7490. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7491. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7492. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7493. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7494. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7495. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7496. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7497. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7498. }
  7499. else
  7500. {
  7501. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7502. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7503. }
  7504. json_object_put(data);
  7505. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7506. json_object_put(response);
  7507. }
  7508. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7509. {
  7510. json_object *data;
  7511. data = json_tokener_parse(tempdata);
  7512. if(!is_error(data))
  7513. {
  7514. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7515. if(json_object_object_get(data, "idToken") != NULL)
  7516. {
  7517. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7518. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7519. }
  7520. if(json_object_object_get(data, "price") != NULL)
  7521. {
  7522. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7523. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7524. }
  7525. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7526. }
  7527. else
  7528. {
  7529. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7530. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7531. }
  7532. json_object_put(data);
  7533. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7534. json_object_put(response);
  7535. }
  7536. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7537. {
  7538. json_object *data;
  7539. data = json_tokener_parse(tempdata);
  7540. if(!is_error(data))
  7541. {
  7542. if(json_object_object_get(data, "txId") != NULL)
  7543. {
  7544. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7545. for(int idx = 0;idx<gunTotalNumber;idx++)
  7546. {
  7547. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7548. {
  7549. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7550. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7551. if(json_object_object_get(data, "description") != NULL)
  7552. {
  7553. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7554. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7555. }
  7556. }
  7557. }
  7558. }
  7559. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7560. }
  7561. else
  7562. {
  7563. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7564. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7565. }
  7566. json_object_put(data);
  7567. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7568. json_object_put(response);
  7569. }
  7570. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7571. {
  7572. json_object *data;
  7573. data = json_tokener_parse(tempdata);
  7574. if(!is_error(data))
  7575. {
  7576. if(json_object_object_get(data, "txId") != NULL)
  7577. {
  7578. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7579. for(int idx = 0;idx<gunTotalNumber;idx++)
  7580. {
  7581. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7582. {
  7583. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7584. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7585. if(json_object_object_get(data, "description") != NULL)
  7586. {
  7587. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7588. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7589. }
  7590. }
  7591. }
  7592. }
  7593. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7594. }
  7595. else
  7596. {
  7597. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7598. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7599. }
  7600. json_object_put(data);
  7601. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7602. json_object_put(response);
  7603. }
  7604. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7605. {
  7606. json_object *data;
  7607. data = json_tokener_parse(tempdata);
  7608. if(!is_error(data))
  7609. {
  7610. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7611. if(json_object_object_get(data, "Content_Type") != NULL)
  7612. {
  7613. 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))
  7614. {
  7615. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7616. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7617. {
  7618. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7619. }
  7620. }
  7621. else
  7622. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7623. }
  7624. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7625. }
  7626. else
  7627. {
  7628. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7629. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7630. }
  7631. json_object_put(data);
  7632. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7633. json_object_put(response);
  7634. }
  7635. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7636. {
  7637. json_object *data;
  7638. data = json_tokener_parse(tempdata);
  7639. if(!is_error(data))
  7640. {
  7641. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7642. if(json_object_object_get(data, "Page_Index") != NULL)
  7643. {
  7644. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7645. }
  7646. if(json_object_object_get(data, "Duration") != NULL)
  7647. {
  7648. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7649. }
  7650. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7651. }
  7652. else
  7653. {
  7654. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7655. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7656. }
  7657. json_object_put(data);
  7658. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7659. json_object_put(response);
  7660. }
  7661. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  7662. {
  7663. json_object *data;
  7664. data = json_tokener_parse(tempdata);
  7665. if(!is_error(data))
  7666. {
  7667. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7668. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  7669. {
  7670. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  7671. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  7672. else
  7673. {
  7674. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7675. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7676. }
  7677. }
  7678. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  7679. {
  7680. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  7681. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  7682. else
  7683. {
  7684. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7685. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7686. }
  7687. }
  7688. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  7689. {
  7690. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  7691. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  7692. else
  7693. {
  7694. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7695. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7696. }
  7697. }
  7698. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  7699. {
  7700. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  7701. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  7702. else
  7703. {
  7704. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7705. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7706. }
  7707. }
  7708. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  7709. {
  7710. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  7711. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  7712. else
  7713. {
  7714. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7715. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7716. }
  7717. }
  7718. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  7719. {
  7720. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  7721. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  7722. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  7723. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  7724. else
  7725. {
  7726. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7727. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7728. }
  7729. }
  7730. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  7731. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7732. }
  7733. else
  7734. {
  7735. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7736. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7737. }
  7738. json_object_put(data);
  7739. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7740. json_object_put(response);
  7741. }
  7742. else
  7743. {
  7744. // Can not find valid message id
  7745. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7746. }
  7747. }
  7748. else
  7749. {
  7750. // Payload is null
  7751. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7752. }
  7753. LWS_Send(message);
  7754. return result;
  7755. }
  7756. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7757. {
  7758. mtrace();
  7759. int result = FAIL;
  7760. int connectorIdInt, durationInt;
  7761. char chargingRateUnitStr[4]={0};
  7762. char comfirmstr[20];
  7763. int confirmPeriods = 0;
  7764. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7765. json_object *GetCompositeSchedule;
  7766. GetCompositeSchedule = json_tokener_parse(payload);
  7767. if(!is_error(GetCompositeSchedule))
  7768. {
  7769. // Required data
  7770. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7771. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7772. else
  7773. connectorIdInt = -1;
  7774. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7775. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7776. else
  7777. durationInt = 86400;
  7778. // Optional data
  7779. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7780. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7781. }
  7782. json_object_put(GetCompositeSchedule);
  7783. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7784. if((connectorIdInt == 0) ||
  7785. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7786. {
  7787. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7788. struct StructChargingProfile tmpProfile[1];
  7789. if(strstr(chargingRateUnitStr, "W") != NULL)
  7790. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7791. else
  7792. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7793. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7794. {
  7795. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7796. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7797. }
  7798. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7799. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7800. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7801. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7802. {
  7803. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7804. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7805. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7806. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7807. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7808. {
  7809. confirmPeriods = idx;
  7810. break;
  7811. }
  7812. }
  7813. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7814. {
  7815. confirmPeriods += 1;
  7816. }
  7817. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7818. }
  7819. else
  7820. {
  7821. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7822. }
  7823. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7824. return result;
  7825. }
  7826. int handleGetConfigurationRequest(char *uuid, char *payload)
  7827. {
  7828. mtrace();
  7829. int result = FAIL;
  7830. int MaxKeySupported = 0;
  7831. int n_keys = 0;
  7832. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7833. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7834. json_object *GetConfiguration;
  7835. GetConfiguration = json_tokener_parse(payload);
  7836. if(!is_error(GetConfiguration))
  7837. {
  7838. // Optional data
  7839. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7840. {
  7841. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7842. {
  7843. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7844. n_keys = idx + 1;
  7845. }
  7846. }
  7847. }
  7848. json_object_put(GetConfiguration);
  7849. UnknownKeynum = 0;
  7850. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7851. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7852. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7853. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7854. if(n_keys != 0)
  7855. {
  7856. for(int i=0;i<n_keys;i++)
  7857. {
  7858. getKeyValue(requestKey[i]);
  7859. }
  7860. }
  7861. else
  7862. {
  7863. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7864. getKeyValue("");
  7865. }
  7866. processUnkownKey();
  7867. sendGetConfigurationConfirmation(uuid);
  7868. return result;
  7869. }
  7870. static char fnamePlusPath[100]={0};
  7871. static char fnamePWithNoPath[60]={0};
  7872. void checkUploadLog(void)
  7873. {
  7874. FILE *fp;
  7875. /* Open the command for reading. */
  7876. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7877. if (fp == NULL) {
  7878. printf("Failed to run command\n" );
  7879. exit(1);
  7880. }
  7881. int ftppathlen = 0;
  7882. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7883. int i = 0;
  7884. /* Read the output a line at a time - output it. */
  7885. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7886. if(i==0)
  7887. {
  7888. ftppathlen = strlen(fnamePlusPath);
  7889. printf("%s\n", fnamePlusPath);
  7890. fnamePlusPath[ftppathlen]='\0';
  7891. break;
  7892. }
  7893. i= i+1;
  7894. }
  7895. /* close */
  7896. pclose(fp);
  7897. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7898. {
  7899. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7900. {
  7901. fnamePlusPath[k]='\0';
  7902. }
  7903. }
  7904. i=1;
  7905. //char fname[60]={0};
  7906. while(i < ftppathlen)
  7907. {
  7908. int len=ftppathlen-i;
  7909. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7910. {
  7911. printf("compare '/' all right\n");
  7912. break;
  7913. }
  7914. i=i+1;
  7915. }
  7916. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7917. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7918. fnamePWithNoPath[i+1] = '\0';
  7919. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7920. {
  7921. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7922. {
  7923. fnamePWithNoPath[j]='\0';
  7924. }
  7925. }
  7926. FILE* fp1 = fopen(fnamePlusPath, "r");
  7927. if (fp1)
  7928. {
  7929. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7930. // file exists
  7931. fclose(fp1);
  7932. }
  7933. else
  7934. {
  7935. // file doesn't exist
  7936. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7937. }
  7938. }
  7939. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7940. {
  7941. mtrace();
  7942. int result = FAIL;
  7943. time_t CurrentTime;
  7944. struct tm *tm;
  7945. pthread_t th_Status;
  7946. CurrentTime = time(NULL);
  7947. tm = localtime(&CurrentTime);
  7948. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  7949. 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);
  7950. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  7951. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7952. return result;
  7953. }
  7954. void* GetDiagnosticsProcess(void* data)
  7955. {
  7956. pthread_detach(pthread_self());
  7957. mtrace();
  7958. int retriesInt=0, retryIntervalInt=0;
  7959. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7960. 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};
  7961. int port=0;
  7962. int isSuccess = FALSE;
  7963. char ftpbuf[200]={0};
  7964. char cmdBuf[2048];
  7965. struct tm *tmNow;
  7966. time_t CurrentTime;
  7967. struct tm tmStart;
  7968. struct tm tmStop;
  7969. CurrentTime = time(NULL);
  7970. tmNow=localtime(&CurrentTime);
  7971. uint16_t targetYear, targetMonth;
  7972. json_object *GetDiagnostics;
  7973. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7974. GetDiagnostics = json_tokener_parse(data);
  7975. if(!is_error(GetDiagnostics))
  7976. {
  7977. // Required data
  7978. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7979. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7980. // Optional data
  7981. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7982. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7983. else
  7984. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7985. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7986. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7987. else
  7988. retryIntervalInt = 30;
  7989. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7990. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7991. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7992. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7993. }
  7994. json_object_put(GetDiagnostics);
  7995. // Pack log to compress file
  7996. 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) &&
  7997. (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))
  7998. {
  7999. // Pack system log
  8000. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8001. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8002. targetYear = tmStart.tm_year;
  8003. targetMonth = tmStart.tm_mon;
  8004. do
  8005. {
  8006. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8007. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8008. if(targetMonth+1>=13)
  8009. {
  8010. targetYear += 1;
  8011. targetMonth = 1;
  8012. }
  8013. else
  8014. {
  8015. targetMonth += 1;
  8016. }
  8017. }while((targetYear < (tmNow->tm_year+1900)) ||
  8018. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8019. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8020. system(cmdBuf);
  8021. // Pack charging & event log
  8022. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8023. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8024. targetYear = tmStart.tm_year;
  8025. targetMonth = tmStart.tm_mon;
  8026. do
  8027. {
  8028. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8029. if(targetMonth+1>=13)
  8030. {
  8031. targetYear += 1;
  8032. targetMonth = 1;
  8033. }
  8034. else
  8035. {
  8036. targetMonth += 1;
  8037. }
  8038. }while((targetYear < (tmNow->tm_year+1900)) ||
  8039. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8040. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8041. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8042. system(cmdBuf);
  8043. // Combine log file
  8044. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8045. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8046. }
  8047. else
  8048. {
  8049. system("exec /root/logPackTools 'log' 6");
  8050. }
  8051. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8052. system(cmdBuf);
  8053. checkUploadLog();
  8054. //****************location*******************/
  8055. if(strcmp(locationstr,"")==0)
  8056. {
  8057. DEBUG_INFO("location is <Empty>!\n");
  8058. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8059. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8060. goto end;
  8061. }
  8062. memset(protocol, 0, ARRAY_SIZE(protocol));
  8063. memset(user, 0, ARRAY_SIZE(user) );
  8064. memset(password, 0, ARRAY_SIZE(password));
  8065. memset(host, 0, ARRAY_SIZE(host));
  8066. memset(path, 0, ARRAY_SIZE(path));
  8067. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8068. memset(host1, 0, ARRAY_SIZE(host1));
  8069. memset(path1, 0, ARRAY_SIZE(path1));
  8070. /*location: ftp://user:password@host:port/path*/
  8071. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8072. if((access(fnamePlusPath,F_OK))!=-1)
  8073. {
  8074. DEBUG_INFO("fnamePlusPath exist.\n");
  8075. }
  8076. else
  8077. {
  8078. DEBUG_INFO("fnamePlusPath not exist!\n");
  8079. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8080. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8081. goto end;
  8082. }
  8083. if(strchr(locationstr,'@')==NULL)
  8084. {
  8085. sscanf(locationstr,
  8086. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8087. protocol, host, &port, path);
  8088. strcpy(user,"anonymous");
  8089. strcpy(password,"");
  8090. }
  8091. else
  8092. {
  8093. //DEBUG_INFO("pch=%s\n", pch);
  8094. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8095. protocol, user, password, host, &port, path);
  8096. }
  8097. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8098. {
  8099. DEBUG_INFO("protocol is not ftp/http ! \n");
  8100. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8101. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8102. goto end;
  8103. }
  8104. if(strncmp(locationstr,"http", 4) == 0)
  8105. {
  8106. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8107. sprintf(ftppath,"/%s", path);
  8108. do
  8109. {
  8110. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8111. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8112. sleep(3);
  8113. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8114. if(!isSuccess)
  8115. {
  8116. DEBUG_INFO("Diagnostics fail.\n");
  8117. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8118. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8119. sleep(retryIntervalInt);
  8120. }
  8121. else
  8122. {
  8123. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8124. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8125. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8126. }
  8127. retriesInt--;
  8128. }while((isSuccess == 0)&&(retriesInt >= 0));
  8129. }
  8130. else
  8131. {
  8132. sscanf(host,"%[^/]%s",host1, path1);
  8133. if(strlen(path) > 0)
  8134. sprintf(ftppath,"/%s", path);
  8135. else
  8136. sprintf(ftppath,"/%s", path1);
  8137. int ftppathlen=strlen(ftppath);
  8138. int i=1;
  8139. char filenametemp[50];
  8140. while(i < ftppathlen)
  8141. {
  8142. int len=ftppathlen-i;
  8143. if(ftppath[len]== 47) // '/' ascll code: 47
  8144. {
  8145. DEBUG_INFO("find '/' all right\n");
  8146. break;
  8147. }
  8148. i=i+1;
  8149. }
  8150. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8151. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8152. filenametemp[i+1] = 0;
  8153. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  8154. if(port == 0)
  8155. port = 21;
  8156. do
  8157. {
  8158. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8159. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8160. sleep(3);
  8161. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8162. if(!isSuccess)
  8163. {
  8164. DEBUG_INFO("Diagnostics fail.\n");
  8165. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8166. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8167. sleep(retryIntervalInt);
  8168. }
  8169. else
  8170. {
  8171. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8172. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8173. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8174. }
  8175. retriesInt--;
  8176. }while((!isSuccess)&&(retriesInt >= 0));
  8177. }
  8178. end:
  8179. system("rm -f /mnt/*");
  8180. sleep(5);
  8181. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8182. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8183. pthread_exit(NULL);
  8184. }
  8185. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8186. {
  8187. mtrace();
  8188. int result = FAIL;
  8189. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8190. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8191. {
  8192. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8193. localversion = -1;
  8194. }
  8195. else
  8196. {
  8197. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8198. OCPP_getListVerion();
  8199. }
  8200. //from db.OCPP_getListVerion
  8201. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = localversion;
  8202. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  8203. sendGetLocalListVersionConfirmation(uuid,"");
  8204. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  8205. return result;
  8206. }
  8207. int handleRemoteStartRequest(char *uuid, char *payload)
  8208. {
  8209. mtrace();
  8210. int result = FAIL;
  8211. int connectorIdInt=0;
  8212. int tempIndex = 0;
  8213. int connectorIdIsNULL, chargingProfileIsNULL;
  8214. char comfirmstr[20]={0};
  8215. char cmdBuf[512];
  8216. json_object *RemoteStartTransaction;
  8217. FILE *fp;
  8218. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8219. if(server_pending == TRUE)
  8220. {
  8221. return 0;
  8222. }
  8223. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8224. RemoteStartTransaction = json_tokener_parse(payload);
  8225. if(!is_error(RemoteStartTransaction))
  8226. {
  8227. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8228. {
  8229. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8230. if(connectorIdInt <= gunTotalNumber)
  8231. {
  8232. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8233. // Required data
  8234. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8235. // Optional data
  8236. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8237. {
  8238. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8239. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8240. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8241. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8242. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8243. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8244. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8245. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8246. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8247. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8248. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8249. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8250. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8251. {
  8252. 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")));
  8253. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8254. 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"));
  8255. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8256. 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"));
  8257. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8258. 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")));
  8259. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8260. {
  8261. 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++)
  8262. {
  8263. 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"));
  8264. 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"));
  8265. 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)
  8266. 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"));
  8267. }
  8268. }
  8269. }
  8270. }
  8271. else
  8272. chargingProfileIsNULL = TRUE;
  8273. }
  8274. }
  8275. else
  8276. connectorIdIsNULL = TRUE;
  8277. }
  8278. else
  8279. connectorIdIsNULL = TRUE;
  8280. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8281. {
  8282. DEBUG_WARN("Connector id is NULL\n.");
  8283. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8284. goto end;
  8285. }
  8286. /*
  8287. enum _SYSTEM_STATUS
  8288. {
  8289. S_BOOTING = 0,
  8290. S_IDLE, = 1
  8291. S_AUTHORIZING, = 2
  8292. S_REASSIGN_CHECK, = 3
  8293. S_REASSIGN, = 4
  8294. S_PRECHARGE, = 5
  8295. S_PREPARING_FOR_EV, = 6
  8296. S_PREPARING_FOR_EVSE, = 7
  8297. S_CHARGING, = 8
  8298. S_TERMINATING, = 9
  8299. S_COMPLETE, = 10
  8300. S_ALARM, = 11
  8301. S_FAULT = 12
  8302. }
  8303. */
  8304. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8305. {
  8306. //check Transaction active
  8307. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8308. {
  8309. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8310. {
  8311. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8312. }
  8313. else
  8314. {
  8315. tempIndex = connectorIdInt -1;
  8316. }
  8317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8318. {
  8319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8320. {
  8321. 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))
  8322. {
  8323. //Reserved
  8324. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8325. }
  8326. 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))
  8327. {
  8328. //Reserved
  8329. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8330. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8331. goto end;
  8332. }
  8333. else
  8334. {
  8335. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8336. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8337. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8338. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8339. {
  8340. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8341. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8342. goto end;
  8343. }
  8344. }//END FOR ELSE
  8345. }
  8346. }// END FOR CHAdeMO_QUANTITY
  8347. }
  8348. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8349. {
  8350. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8351. {
  8352. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8353. }
  8354. else
  8355. {
  8356. tempIndex = connectorIdInt -1;
  8357. }
  8358. for (int index = 0; index < CCS_QUANTITY; index++)
  8359. {
  8360. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8361. {
  8362. 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))
  8363. {
  8364. //Reserved
  8365. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8366. }
  8367. 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))
  8368. {
  8369. //Reserved
  8370. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8371. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8372. goto end;
  8373. }
  8374. else
  8375. {
  8376. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8377. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8378. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8379. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8380. {
  8381. DEBUG_WARN("CCS connector not allow start\n.");
  8382. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8383. goto end;
  8384. }
  8385. }// END FOR ELSE
  8386. }
  8387. }// END FOR CCS_QUANTITY
  8388. }
  8389. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8390. {
  8391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8392. {
  8393. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8394. }
  8395. else
  8396. {
  8397. tempIndex = connectorIdInt -1;
  8398. }
  8399. for (int index = 0; index < GB_QUANTITY; index++)
  8400. {
  8401. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8402. {
  8403. 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))
  8404. {
  8405. //Reserved
  8406. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8407. }
  8408. 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))
  8409. {
  8410. //Reserved
  8411. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8413. goto end;
  8414. }
  8415. else
  8416. {
  8417. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8418. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8419. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8420. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8421. {
  8422. DEBUG_WARN("GB connector not allow start\n.");
  8423. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8424. goto end;
  8425. }
  8426. }// END FOR ELSE
  8427. }
  8428. } // END FOR GB_QUANTITY
  8429. }
  8430. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8431. {
  8432. tempIndex = connectorIdInt -1;
  8433. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8434. {
  8435. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8436. {
  8437. 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))
  8438. {
  8439. //Reserved
  8440. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8441. }
  8442. 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))
  8443. {
  8444. //Reserved
  8445. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8446. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8447. goto end;
  8448. }
  8449. else
  8450. {
  8451. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8452. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8453. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8454. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8455. {
  8456. DEBUG_WARN("GB connector not allow start\n.");
  8457. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8458. goto end;
  8459. }
  8460. }// END FOR ELSE
  8461. }
  8462. } // END FOR GB_QUANTITY
  8463. }
  8464. else
  8465. {
  8466. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8467. {
  8468. tempIndex = 2;
  8469. }
  8470. else
  8471. {
  8472. tempIndex = connectorIdInt -1;
  8473. }
  8474. for (int index = 0; index < AC_QUANTITY; index++)
  8475. {
  8476. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8477. {
  8478. 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))
  8479. {
  8480. //Reserved
  8481. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8482. }
  8483. 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))
  8484. {
  8485. //Reserved
  8486. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8487. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8488. goto end;
  8489. }
  8490. else
  8491. {
  8492. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8493. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8494. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8495. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8496. {
  8497. DEBUG_WARN("AC connector not allow start\n.");
  8498. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8499. goto end;
  8500. }
  8501. }//END FOR ELSE
  8502. }
  8503. }// END FOR AC_QUANTITY
  8504. }
  8505. if(chargingProfileIsNULL == FALSE)
  8506. {
  8507. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8508. {
  8509. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8510. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8511. //memset idTag
  8512. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8513. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8514. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8515. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8516. // Save profile to file
  8517. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8518. system(cmdBuf);
  8519. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8520. fp = fopen(cmdBuf, "w");
  8521. 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));
  8522. fclose(fp);
  8523. }
  8524. else
  8525. {
  8526. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8527. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8528. }
  8529. }
  8530. else
  8531. {
  8532. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8533. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8534. //memset idTag
  8535. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8536. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8537. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8538. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8539. }
  8540. }
  8541. else
  8542. {
  8543. DEBUG_WARN("Connector id over\n.");
  8544. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8545. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8546. }
  8547. end:
  8548. json_object_put(RemoteStartTransaction);
  8549. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8550. {
  8551. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8552. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8553. }
  8554. //OCPP send RemoteStartConfirmation by first.
  8555. sendRemoteStartConfirmation(uuid, comfirmstr);
  8556. return result;
  8557. }
  8558. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8559. {
  8560. mtrace();
  8561. int result = FAIL;
  8562. int match = FALSE;
  8563. int GunNO = 0;
  8564. int tempIndex = 0;
  8565. int transactionIdInt=0;
  8566. int transactionIdIsNULL= TRUE;
  8567. char comfirmstr[20];
  8568. json_object *RemoteStopTransaction;
  8569. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8570. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8571. if(server_pending == TRUE)
  8572. {
  8573. return 0;
  8574. }
  8575. RemoteStopTransaction = json_tokener_parse(payload);
  8576. if(!is_error(RemoteStopTransaction))
  8577. {
  8578. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8579. {
  8580. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8581. transactionIdIsNULL = FALSE;
  8582. }
  8583. }
  8584. json_object_put(RemoteStopTransaction);
  8585. if(transactionIdIsNULL == FALSE)
  8586. {
  8587. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8588. {
  8589. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8590. {
  8591. //check Transaction active
  8592. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8593. {
  8594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8595. {
  8596. tempIndex = ((gun_index==2) ? 1: 0);
  8597. }
  8598. else
  8599. {
  8600. tempIndex = gun_index;
  8601. }
  8602. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8603. {
  8604. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8605. {
  8606. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8607. {
  8608. match = TRUE;
  8609. GunNO = gun_index;
  8610. }
  8611. }
  8612. }// END FOR CHAdeMO_QUANTITY
  8613. }
  8614. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8615. {
  8616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8617. {
  8618. tempIndex = ((gun_index==2) ? 1: 0);
  8619. }
  8620. else
  8621. {
  8622. tempIndex = gun_index;
  8623. }
  8624. for (int index = 0; index < CCS_QUANTITY; index++)
  8625. {
  8626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8627. {
  8628. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8629. {
  8630. match = TRUE;
  8631. GunNO = gun_index;
  8632. }
  8633. }
  8634. }// END FOR CCS_QUANTITY
  8635. }
  8636. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8637. {
  8638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8639. {
  8640. tempIndex = ((gun_index==2) ? 1: 0);
  8641. }
  8642. else
  8643. {
  8644. tempIndex = gun_index;
  8645. }
  8646. for (int index = 0; index < GB_QUANTITY; index++)
  8647. {
  8648. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8649. {
  8650. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8651. {
  8652. match = TRUE;
  8653. GunNO = gun_index;
  8654. }
  8655. }
  8656. }// END FOR GB_QUANTITY
  8657. }
  8658. else if(gunType[gun_index] == GUN_TYPE_DO)
  8659. {
  8660. tempIndex = gun_index;
  8661. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8662. {
  8663. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8664. {
  8665. 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
  8666. {
  8667. match = TRUE;
  8668. GunNO = gun_index;
  8669. }
  8670. }
  8671. }// END FOR GB_QUANTITY
  8672. }
  8673. else
  8674. {
  8675. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8676. {
  8677. tempIndex = 2;
  8678. }
  8679. else
  8680. {
  8681. tempIndex = gun_index;
  8682. }
  8683. for (int index = 0; index < AC_QUANTITY; index++)
  8684. {
  8685. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8686. {
  8687. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8688. {
  8689. match = TRUE;
  8690. GunNO = gun_index;
  8691. }
  8692. }
  8693. }// END FOR CHAdeMO_QUANTITY
  8694. } // END FOR AC ELSE
  8695. }// CHECK IF ResponseTransactionId == transactionIdInt
  8696. }//END FOR
  8697. if( match == TRUE)
  8698. {
  8699. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8700. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8701. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8702. }
  8703. else
  8704. {
  8705. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8706. }
  8707. }
  8708. else
  8709. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8710. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8711. return result;
  8712. }
  8713. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8714. {
  8715. mtrace();
  8716. int result = FAIL;
  8717. int connectorIdInt=0, reservationIdInt=0;
  8718. int tempIndex = 0;
  8719. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8720. char comfirmstr[20]={0};
  8721. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8722. int c = 0;
  8723. char *loc;
  8724. //char *ptr;
  8725. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8726. strcpy(sstrtemp, stringtrimspace(payload));
  8727. //***(1)connectorId ****/
  8728. c=0;
  8729. loc = strstr(sstrtemp, "connectorId");
  8730. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8731. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8732. {
  8733. sstr[c] = loc[strlen("connectorId")+2+c];
  8734. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8735. c++;
  8736. }
  8737. sstr[c] = '\0';
  8738. connectorIdInt = atoi(sstr);
  8739. //***(2)expiryDate ****/
  8740. loc = strstr(sstrtemp, "expiryDate");
  8741. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8742. c = 0;
  8743. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8744. {
  8745. sstr[c] = loc[3+strlen("expiryDate")+c];
  8746. c++;
  8747. }
  8748. sstr[c] = '\0';
  8749. strcpy(expiryDatestr, sstr);
  8750. //***(3)idTag ****/
  8751. loc = strstr(sstrtemp, "idTag");
  8752. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8753. c = 0;
  8754. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8755. {
  8756. sstr[c] = loc[3+strlen("idTag")+c];
  8757. c++;
  8758. }
  8759. sstr[c] = '\0';
  8760. strcpy(idTagstr, sstr);
  8761. //***(4)parentIdTag ****/
  8762. loc = strstr(sstrtemp, "parentIdTag");
  8763. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8764. c = 0;
  8765. if(loc == NULL)
  8766. {
  8767. strcpy(parentIdTagstr, "");
  8768. }
  8769. else
  8770. {
  8771. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8772. {
  8773. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8774. c++;
  8775. }
  8776. sstr[c] = '\0';
  8777. strcpy(parentIdTagstr, sstr);
  8778. }
  8779. //***(5)reservationId ****/
  8780. c=0;
  8781. loc = strstr(sstrtemp, "reservationId");
  8782. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8783. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8784. {
  8785. sstr[c] = loc[strlen("reservationId")+2+c];
  8786. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8787. c++;
  8788. }
  8789. sstr[c] = '\0';
  8790. reservationIdInt = atoi(sstr);
  8791. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8792. /*
  8793. enum SYSTEM_STATUS
  8794. {
  8795. SYS_MODE_BOOTING = 0,
  8796. SYS_MODE_IDLE = 1,
  8797. SYS_MODE_AUTHORIZING = 2,
  8798. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8799. SYS_MODE_REASSIGN = 4,
  8800. SYS_MODE_PREPARING = 5,
  8801. SYS_MODE_PREPARE_FOR_EV = 6,
  8802. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8803. SYS_MODE_CHARGING = 8,
  8804. SYS_MODE_TERMINATING = 9,
  8805. SYS_MODE_COMPLETE = 10,
  8806. SYS_MODE_ALARM = 11,
  8807. SYS_MODE_FAULT = 12,
  8808. SYS_MODE_RESERVATION = 13,
  8809. SYS_MODE_BOOKING = 14,
  8810. SYS_MODE_MAINTAIN = 15,
  8811. SYS_MODE_DEBUG = 16,
  8812. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8813. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8814. SYS_MODE_UPDATE = 19
  8815. };
  8816. */
  8817. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8818. {
  8819. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8820. goto end;
  8821. }
  8822. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8823. {
  8824. //check Transaction active
  8825. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8826. {
  8827. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8828. {
  8829. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8830. }
  8831. else
  8832. {
  8833. tempIndex = connectorIdInt -1;
  8834. }
  8835. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8836. {
  8837. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8838. {
  8839. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8840. {
  8841. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8842. {
  8843. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8844. {
  8845. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8846. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8847. }
  8848. 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'))
  8849. {
  8850. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8851. }
  8852. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8853. {
  8854. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8855. }
  8856. else
  8857. {
  8858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8859. }
  8860. }
  8861. 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
  8862. {
  8863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8864. }
  8865. }
  8866. else
  8867. {
  8868. //replace reservation
  8869. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8871. }
  8872. }
  8873. } // END FOR CHAdeMO_QUANTITY
  8874. }
  8875. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8876. {
  8877. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8878. {
  8879. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8880. }
  8881. else
  8882. {
  8883. tempIndex = connectorIdInt -1;
  8884. }
  8885. for (int index = 0; index < CCS_QUANTITY; index++)
  8886. {
  8887. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8888. {
  8889. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8890. {
  8891. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8892. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8893. {
  8894. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8895. {
  8896. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8897. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8898. }
  8899. 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'))
  8900. {
  8901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8902. }
  8903. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8904. {
  8905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8906. }
  8907. else
  8908. {
  8909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8910. }
  8911. }
  8912. 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
  8913. {
  8914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8915. }
  8916. }
  8917. else
  8918. {
  8919. //replace reservation
  8920. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8922. }
  8923. }
  8924. } // END FOR CCS_QUANTITY
  8925. }
  8926. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8927. {
  8928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8929. {
  8930. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8931. }
  8932. else
  8933. {
  8934. tempIndex = connectorIdInt -1;
  8935. }
  8936. for (int index = 0; index < GB_QUANTITY; index++)
  8937. {
  8938. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8939. {
  8940. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8941. {
  8942. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8943. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8944. {
  8945. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8946. {
  8947. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8948. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8949. }
  8950. 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'))
  8951. {
  8952. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8953. }
  8954. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8955. {
  8956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8957. }
  8958. else
  8959. {
  8960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8961. }
  8962. }
  8963. 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
  8964. {
  8965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8966. }
  8967. }
  8968. else
  8969. {
  8970. //replace reservation
  8971. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8973. }
  8974. }
  8975. }// END FOR GB_QUANTITY
  8976. }
  8977. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8978. {
  8979. tempIndex = connectorIdInt -1;
  8980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8981. {
  8982. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8983. {
  8984. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8985. {
  8986. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8987. 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
  8988. {
  8989. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8990. {
  8991. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8992. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8993. }
  8994. 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'))
  8995. {
  8996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8997. }
  8998. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8999. {
  9000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9001. }
  9002. else
  9003. {
  9004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9005. }
  9006. }
  9007. 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
  9008. {
  9009. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9010. }
  9011. }
  9012. else
  9013. {
  9014. //replace reservation
  9015. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9016. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9017. }
  9018. }
  9019. }// END FOR GB_QUANTITY
  9020. }
  9021. else
  9022. {
  9023. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9024. {
  9025. tempIndex = 2;
  9026. }
  9027. else
  9028. {
  9029. tempIndex = (connectorIdInt -1);
  9030. }
  9031. for (int index = 0; index < AC_QUANTITY; index++)
  9032. {
  9033. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9034. {
  9035. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9036. {
  9037. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9038. {
  9039. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9040. {
  9041. 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))
  9042. {
  9043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9044. }
  9045. else
  9046. {
  9047. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9048. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9049. }
  9050. }
  9051. 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'))
  9052. {
  9053. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9054. }
  9055. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9056. {
  9057. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9058. }
  9059. else
  9060. {
  9061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9062. }
  9063. }
  9064. 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
  9065. {
  9066. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9067. }
  9068. }
  9069. else
  9070. {
  9071. //replace reservation
  9072. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9073. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9074. }
  9075. }
  9076. } // END FOR AC_QUANTITY
  9077. }
  9078. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9079. }
  9080. else if(connectorIdInt == 0)
  9081. {
  9082. //check Transaction active
  9083. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9084. {
  9085. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9086. {
  9087. 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'))
  9088. {
  9089. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9090. goto end;
  9091. }
  9092. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9093. {
  9094. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9095. goto end;
  9096. }
  9097. 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
  9098. {
  9099. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9100. goto end;
  9101. }
  9102. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9103. {
  9104. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9105. goto end;
  9106. }
  9107. }
  9108. }// END FOR CHAdeMO_QUANTITY
  9109. for (int index = 0; index < CCS_QUANTITY; index++)
  9110. {
  9111. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9112. {
  9113. 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'))
  9114. {
  9115. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9116. goto end;
  9117. }
  9118. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9119. {
  9120. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9121. goto end;
  9122. }
  9123. 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
  9124. {
  9125. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9126. goto end;
  9127. }
  9128. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9129. {
  9130. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9131. goto end;
  9132. }
  9133. }
  9134. } // END FOR CCS_QUANTITY
  9135. for (int index = 0; index < GB_QUANTITY; index++)
  9136. {
  9137. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9138. {
  9139. 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'))
  9140. {
  9141. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9142. goto end;
  9143. }
  9144. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9145. {
  9146. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9147. goto end;
  9148. }
  9149. 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
  9150. {
  9151. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9152. goto end;
  9153. }
  9154. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9155. {
  9156. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9157. goto end;
  9158. }
  9159. }
  9160. } // END FOR GB_QUANTITY
  9161. for (int index = 0; index < AC_QUANTITY; index++)
  9162. {
  9163. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9164. {
  9165. 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'))
  9166. {
  9167. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9168. goto end;
  9169. }
  9170. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9171. {
  9172. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9173. goto end;
  9174. }
  9175. 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
  9176. {
  9177. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9178. goto end;
  9179. }
  9180. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9181. {
  9182. 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))
  9183. {
  9184. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9185. goto end;
  9186. }
  9187. }
  9188. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9189. {
  9190. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9191. goto end;
  9192. }
  9193. }
  9194. }// END FOR AC_QUANTITY
  9195. //The connectorId is 0
  9196. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  9197. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9198. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9199. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  9200. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9201. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  9202. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9203. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  9204. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  9205. result = TRUE;
  9206. return result;
  9207. }
  9208. else
  9209. {
  9210. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9211. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9212. }
  9213. if(strcmp(comfirmstr,"Accepted") == 0)
  9214. {
  9215. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9216. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9217. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9218. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9219. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9220. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  9221. result = TRUE;
  9222. return result;
  9223. }
  9224. end:
  9225. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9226. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9227. return result;
  9228. }
  9229. int handleResetRequest(char *uuid, char *payload)
  9230. {
  9231. mtrace();
  9232. int result = FAIL;
  9233. char sstr[10]={0},sstrtemp[30]={ 0 };
  9234. char typestr[10]={0};
  9235. char comfirmstr[20]={0};
  9236. int c = 0;
  9237. char *loc;
  9238. DEBUG_INFO("handleResetRequest...\n");
  9239. strcpy(sstrtemp, stringtrimspace(payload));
  9240. loc = strstr(sstrtemp, "type");
  9241. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9242. c = 0;
  9243. while (loc[3+strlen("type")+c] != '\"')
  9244. {
  9245. sstr[c] = loc[3+strlen("type")+c];
  9246. c++;
  9247. }
  9248. sstr[c] = '\0';
  9249. strcpy(typestr,sstr);
  9250. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  9251. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9252. {
  9253. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  9254. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  9255. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9256. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9257. }
  9258. else
  9259. {
  9260. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9261. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9262. result = PASS;
  9263. }
  9264. sendResetConfirmation(uuid, comfirmstr);
  9265. return result;
  9266. }
  9267. int handleSendLocalListRequest(char *uuid, char *payload)
  9268. {
  9269. mtrace();
  9270. int result = FAIL;
  9271. int listVersionInt;
  9272. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  9273. char listsearch[]="listVersion";
  9274. char updateTypesearch[]="updateType";
  9275. char localAuthorizationListsearch[]="localAuthorizationList";
  9276. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  9277. char CardList[500][160]={0};
  9278. char updateTypestr[15]={0};
  9279. char idTagstr[20]={0};
  9280. char parentIdTag[20]={0};
  9281. char expiryDate[30]={0};
  9282. char idTagstatus[16]={0};
  9283. int c = 0;
  9284. int i = 0;
  9285. char *delim1 = "}";
  9286. char * pch;
  9287. char *loc;
  9288. //char *ptr;
  9289. char comfirmstr[20];
  9290. //int n_localAuthorizations = 0;
  9291. int checkState_Faulted = FALSE;
  9292. DEBUG_INFO("handleSendLocalListRequest...\n");
  9293. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9294. {
  9295. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9296. goto end;
  9297. }
  9298. //check Charge Point state
  9299. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9300. {
  9301. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9302. {
  9303. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9304. }
  9305. }
  9306. for (int index = 0; index < CCS_QUANTITY; index++)
  9307. {
  9308. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9309. {
  9310. checkState_Faulted = TRUE; //OCPP Status
  9311. }
  9312. }
  9313. for (int index = 0; index < GB_QUANTITY; index++)
  9314. {
  9315. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9316. {
  9317. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9318. }
  9319. }
  9320. //check Charge Point state
  9321. for (int index = 0; index < AC_QUANTITY; index++)
  9322. {
  9323. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9324. {
  9325. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9326. }
  9327. }
  9328. if(checkState_Faulted == TRUE)
  9329. {
  9330. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9331. goto end;
  9332. }
  9333. //Filter payload space
  9334. strcpy(sstrtemp, stringtrimspace(payload));
  9335. //listVersion
  9336. c = 0;
  9337. loc = strstr(sstrtemp, listsearch);
  9338. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  9339. {
  9340. sstr[c] = loc[strlen("listVersion")+2+c];
  9341. c++;
  9342. }
  9343. sstr[c] = '\0';
  9344. listVersionInt = atoi(sstr);
  9345. ShmOCPP16DataPH->SendLocalList.ListVersion = listVersionInt;
  9346. //updateType
  9347. loc = strstr(sstrtemp, updateTypesearch);
  9348. c = 0;
  9349. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  9350. {
  9351. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  9352. c++;
  9353. }
  9354. sstr[c] = '\0';
  9355. strcpy(updateTypestr, sstr);
  9356. sprintf((char *)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", updateTypestr);
  9357. //localAuthorizationList
  9358. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9359. loc = strstr(sstrtemp, localAuthorizationListsearch);
  9360. if(loc != NULL) // localAuthorizationList is not NULL
  9361. {
  9362. //Check UpdateType
  9363. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9364. {
  9365. //Local list full update
  9366. printf("Local list full update.\n");
  9367. OCPP_getListVerion();
  9368. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9369. {
  9370. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9371. goto end;
  9372. }
  9373. OCPP_cleanLocalList();
  9374. }
  9375. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9376. {
  9377. //Local list different update
  9378. printf("Local list different update.\n");
  9379. OCPP_getListVerion();
  9380. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  9381. {
  9382. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9383. goto end;
  9384. }
  9385. }
  9386. else
  9387. {
  9388. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9389. goto end;
  9390. }
  9391. c = 0;
  9392. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  9393. {
  9394. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  9395. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9396. c++;
  9397. }
  9398. sstr[c] = '\0';
  9399. //DEBUG_INFO("sstr=%s\n", sstr);
  9400. //parsing strings to words
  9401. i = 0;
  9402. pch = strtok(sstr,delim1);
  9403. while (pch != NULL)
  9404. {
  9405. strcpy(CardList[i], pch);
  9406. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  9407. pch = strtok (NULL, delim1);
  9408. i = i + 1;
  9409. }
  9410. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  9411. //local Authorizations List Numbers
  9412. //n_localAuthorizations = i;
  9413. ShmOCPP16DataPH->SendLocalList.ListVersion = listVersionInt;
  9414. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9415. c= 0;
  9416. while(c < i) // i is CardList Number
  9417. {
  9418. //Search "IdToken"
  9419. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9420. loc = strstr(CardList[c], "idTag");
  9421. int j = 0;
  9422. while (loc[3+strlen("idTag")+j] != '\"')
  9423. {
  9424. sstr[j] = loc[3+strlen("idTag")+j];
  9425. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9426. j++;
  9427. }
  9428. sstr[j] = '\0';
  9429. strcpy(idTagstr, sstr);
  9430. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  9431. //Search "expiryDate"
  9432. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9433. loc = strstr(CardList[c], "expiryDate");
  9434. j = 0;
  9435. if(loc != NULL)
  9436. {
  9437. while (loc[3+strlen("expiryDate")+j] != '\"')
  9438. {
  9439. sstr[j] = loc[3+strlen("expiryDate")+j];
  9440. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9441. j++;
  9442. }
  9443. sstr[j] = '\0';
  9444. strcpy(expiryDate, sstr);
  9445. }
  9446. else
  9447. {
  9448. strcpy(expiryDate, "");
  9449. }
  9450. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  9451. //Search "parentIdTag"
  9452. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9453. loc = strstr(CardList[c], "parentIdTag");
  9454. j = 0;
  9455. if(loc != NULL)
  9456. {
  9457. while (loc[3+strlen("parentIdTag")+j] != '\"')
  9458. {
  9459. sstr[j] = loc[3+strlen("parentIdTag")+j];
  9460. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9461. j++;
  9462. }
  9463. sstr[j] = '\0';
  9464. strcpy(parentIdTag, sstr);
  9465. }
  9466. else
  9467. {
  9468. strcpy(parentIdTag, "");
  9469. }
  9470. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  9471. //Search "status"
  9472. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9473. loc = strstr(CardList[c], "status");
  9474. j = 0;
  9475. while (loc[3+strlen("status")+j] != '\"')
  9476. {
  9477. sstr[j] = loc[3+strlen("status")+j];
  9478. //printf("i=%d sstr=%c\n",c, sstr[j]);
  9479. j++;
  9480. }
  9481. sstr[j] = '\0';
  9482. strcpy(idTagstatus, sstr);
  9483. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  9484. OCPP_getIdTagFromLocalList(idTagstr);
  9485. //OCPP_getIdTagFromLocalList("test"); For Test
  9486. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  9487. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  9488. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9489. {
  9490. //Local list full update
  9491. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9492. // update list
  9493. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9494. //DEBUG_INFO("Local list full update. 1\n");
  9495. //OCPP_get_TableAuthlocalAllData();
  9496. //DEBUG_INFO("Local list full update. 2\n");
  9497. }
  9498. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9499. {
  9500. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  9501. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  9502. }
  9503. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  9504. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  9505. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  9506. strcpy((char *)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  9507. c++;
  9508. }
  9509. }
  9510. else
  9511. {
  9512. //Check UpdateType
  9513. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  9514. {
  9515. //Local list full update
  9516. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9517. OCPP_cleanLocalList();
  9518. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9519. goto end;
  9520. }
  9521. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  9522. {
  9523. //Local list different update
  9524. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9525. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9526. goto end;
  9527. }
  9528. }
  9529. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9530. end:
  9531. sendSendLocalListConfirmation(uuid, comfirmstr);
  9532. //ShmOCPP16DataPH->MsMsg.bits.SendLocalListConf = 1;
  9533. return result;
  9534. }
  9535. #define MAX 200
  9536. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9537. {
  9538. mtrace();
  9539. int result = FAIL;
  9540. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9541. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9542. char chargingProfilePurposeStr[30]={0};
  9543. char chargingProfileKindStr[16]={0};
  9544. char recurrencyKindStr[10]={0};
  9545. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9546. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9547. int chargingSchedulePeriodCount = 0;
  9548. char comfirmstr[20]={0};
  9549. int meet= FALSE;
  9550. FILE *fptr1;
  9551. char filename[MAX]={0};
  9552. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  9553. char rmFileCmd[50]={0};
  9554. char tempchargingProfilePurposeStr[30]={0};
  9555. char word[1600]={0};
  9556. int n_chargingProfile = 0;
  9557. json_object *SetChargingProfile;
  9558. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9559. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9560. SetChargingProfile = json_tokener_parse(payload);
  9561. if(!is_error(SetChargingProfile))
  9562. {
  9563. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9564. {
  9565. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9566. if(connectorIdInt == 0)
  9567. {
  9568. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9569. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9570. }
  9571. else
  9572. {
  9573. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9574. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9575. }
  9576. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9577. }
  9578. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9579. {
  9580. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9581. {
  9582. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9583. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9584. {
  9585. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9586. }
  9587. else
  9588. {
  9589. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9590. }
  9591. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9592. }
  9593. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9594. {
  9595. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9596. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9597. {
  9598. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9599. }
  9600. else
  9601. {
  9602. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9603. }
  9604. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9605. }
  9606. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9607. {
  9608. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9609. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9610. {
  9611. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9612. }
  9613. else
  9614. {
  9615. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9616. }
  9617. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9618. }
  9619. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9620. {
  9621. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9622. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9623. {
  9624. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9625. }
  9626. else
  9627. {
  9628. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9629. }
  9630. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9631. }
  9632. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9633. {
  9634. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9635. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9636. {
  9637. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9638. }
  9639. else
  9640. {
  9641. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9642. }
  9643. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9644. }
  9645. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9646. {
  9647. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9648. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9649. {
  9650. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9651. }
  9652. else
  9653. {
  9654. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9655. }
  9656. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9657. }
  9658. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9659. {
  9660. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9661. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9662. {
  9663. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9664. }
  9665. else
  9666. {
  9667. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9668. }
  9669. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9670. }
  9671. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9672. {
  9673. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9674. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9675. {
  9676. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9677. }
  9678. else
  9679. {
  9680. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9681. }
  9682. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9683. }
  9684. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9685. {
  9686. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9687. {
  9688. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9689. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9690. {
  9691. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9692. }
  9693. else
  9694. {
  9695. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9696. }
  9697. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9698. }
  9699. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9700. {
  9701. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9702. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9703. {
  9704. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9705. }
  9706. else
  9707. {
  9708. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9709. }
  9710. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9711. }
  9712. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9713. {
  9714. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9715. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9716. {
  9717. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9718. }
  9719. else
  9720. {
  9721. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9722. }
  9723. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9724. }
  9725. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9726. {
  9727. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9728. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9729. {
  9730. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9731. }
  9732. else
  9733. {
  9734. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9735. }
  9736. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9737. }
  9738. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9739. {
  9740. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9741. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9742. if(chargingSchedulePeriodCount <= 10)
  9743. {
  9744. 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++)
  9745. {
  9746. 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)
  9747. {
  9748. startPeriodInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  9749. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9750. {
  9751. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9752. }
  9753. else
  9754. {
  9755. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9756. }
  9757. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9758. }
  9759. 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)
  9760. {
  9761. limitflaot[idxPeriod] = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  9762. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9763. {
  9764. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9765. }
  9766. else
  9767. {
  9768. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9769. }
  9770. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9771. }
  9772. 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)
  9773. {
  9774. numberPhasesInt[idxPeriod] = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  9775. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9776. {
  9777. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9778. }
  9779. else
  9780. {
  9781. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9782. }
  9783. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9784. }
  9785. }
  9786. }
  9787. }
  9788. }
  9789. }
  9790. }
  9791. json_object_put(SetChargingProfile);
  9792. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9793. {
  9794. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9795. goto end;
  9796. }
  9797. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9798. {
  9799. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9800. if(connectorIdInt != 0)
  9801. {
  9802. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9803. goto end;
  9804. }
  9805. strcpy(filename, ChargePointMaxProfile_JSON );
  9806. fptr1 = fopen(filename, "r");
  9807. if (!fptr1)
  9808. {
  9809. //file not exist
  9810. DEBUG_INFO("Unable to open the input file!!\n");
  9811. fptr1 = fopen(filename, "w+");
  9812. }
  9813. else
  9814. {
  9815. //Check Charging Profile Count
  9816. while(fscanf(fptr1, "%s", word) != EOF)
  9817. {
  9818. //DEBUG_INFO("word=%s\n",word);
  9819. if(strstr(word, "chargingProfileId")!= NULL)
  9820. {
  9821. //DEBUG_INFO("test chargingProfileId \n");
  9822. n_chargingProfile = n_chargingProfile + 1;
  9823. //DEBUG_INFO("chargingProfileId Found\n");
  9824. }
  9825. }
  9826. }
  9827. fclose(fptr1);
  9828. }
  9829. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9830. {
  9831. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9832. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9833. {
  9834. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9835. goto end;
  9836. }
  9837. memset(filename, 0, ARRAY_SIZE(filename));
  9838. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  9839. fptr1 = fopen(filename, "r");
  9840. if (!fptr1)
  9841. {
  9842. //file not exist
  9843. //DEBUG_INFO("Unable to open the input file!!\n");
  9844. fptr1 = fopen(filename, "w+");
  9845. }
  9846. else
  9847. {
  9848. //Check Charging Profile Count
  9849. while(fscanf(fptr1, "%s", word) != EOF)
  9850. {
  9851. //DEBUG_INFO("word=%s\n",word);
  9852. if(strstr(word, "chargingProfileId")!= NULL)
  9853. {
  9854. //DEBUG_INFO("test chargingProfileId \n");
  9855. n_chargingProfile = n_chargingProfile + 1;
  9856. //DEBUG_INFO("chargingProfileId Found\n");
  9857. }
  9858. }
  9859. }
  9860. fclose(fptr1);
  9861. }
  9862. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9863. {
  9864. //printf("set chargingProfile 1-4\n");
  9865. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9866. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9867. if(connectorIdInt == 0)
  9868. {
  9869. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9870. goto end;
  9871. }
  9872. int tempIndex = 0;
  9873. //check Transaction active
  9874. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9875. {
  9876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9877. {
  9878. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9879. }
  9880. else
  9881. {
  9882. tempIndex = connectorIdInt -1;
  9883. }
  9884. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9885. {
  9886. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9887. {
  9888. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9889. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9890. {
  9891. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9892. {
  9893. meet = TRUE;
  9894. break;
  9895. }
  9896. }
  9897. }
  9898. }
  9899. }
  9900. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9901. {
  9902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9903. {
  9904. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9905. }
  9906. else
  9907. {
  9908. tempIndex = connectorIdInt -1;
  9909. }
  9910. for (int index = 0; index < CCS_QUANTITY; index++)
  9911. {
  9912. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9913. {
  9914. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9915. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9916. {
  9917. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9918. {
  9919. meet = TRUE;
  9920. break;
  9921. }
  9922. }
  9923. }
  9924. }
  9925. }
  9926. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9927. {
  9928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9929. {
  9930. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9931. }
  9932. else
  9933. {
  9934. tempIndex = connectorIdInt -1;
  9935. }
  9936. for (int index = 0; index < GB_QUANTITY; index++)
  9937. {
  9938. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9939. {
  9940. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9941. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9942. {
  9943. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9944. {
  9945. meet = TRUE;
  9946. break;
  9947. }
  9948. }
  9949. }
  9950. }
  9951. }
  9952. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9953. {
  9954. tempIndex = connectorIdInt -1;
  9955. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9956. {
  9957. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9958. {
  9959. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9960. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9961. {
  9962. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9963. {
  9964. meet = TRUE;
  9965. break;
  9966. }
  9967. }
  9968. }
  9969. }
  9970. }
  9971. else
  9972. {
  9973. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9974. {
  9975. tempIndex = 2;
  9976. }
  9977. else
  9978. {
  9979. tempIndex = (connectorIdInt -1);
  9980. }
  9981. for (int index = 0; index < AC_QUANTITY; index++)
  9982. {
  9983. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9984. {
  9985. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9986. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9987. {
  9988. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9989. {
  9990. meet = TRUE;
  9991. break;
  9992. }
  9993. }
  9994. }
  9995. }
  9996. }
  9997. //check Transaction active
  9998. if(meet == FALSE)
  9999. {
  10000. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10001. goto end;
  10002. }
  10003. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  10004. {
  10005. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10006. goto end;
  10007. }
  10008. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  10009. fptr1 = fopen(filename, "r");
  10010. if (!fptr1)
  10011. {
  10012. //file not exist
  10013. DEBUG_INFO("Unable to open the input file!!\n");
  10014. fptr1 = fopen(filename, "w+");
  10015. }
  10016. else
  10017. {
  10018. //Check Charging Profile Count
  10019. while(fscanf(fptr1, "%s", word) != EOF)
  10020. {
  10021. //DEBUG_INFO("word=%s\n",word);
  10022. if(strstr(word, "chargingProfileId")!= NULL)
  10023. {
  10024. //DEBUG_INFO("test chargingProfileId \n");
  10025. n_chargingProfile = n_chargingProfile + 1;
  10026. //DEBUG_INFO("chargingProfileId Found\n");
  10027. }
  10028. }
  10029. }
  10030. fclose(fptr1);
  10031. }
  10032. // Check ChargeProfileMaxStackLevel
  10033. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  10034. {
  10035. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10036. goto end;
  10037. }
  10038. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10039. {
  10040. int i = 0;
  10041. char fnametemp[200]={0};
  10042. n_chargingProfile = 0;
  10043. //Check ChargePointMaxProfile.json exit
  10044. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  10045. {
  10046. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  10047. //Check Charging Profile Count
  10048. while(fscanf(fptr1, "%s", word) != EOF)
  10049. {
  10050. //DEBUG_INFO("word=%s\n",word);
  10051. if(strstr(word, "chargingProfileId")!= NULL)
  10052. {
  10053. //DEBUG_INFO("test chargingProfileId \n");
  10054. n_chargingProfile = n_chargingProfile + 1;
  10055. i = i + 1;
  10056. //DEBUG_INFO("chargingProfileId Found\n");
  10057. }
  10058. memset(word, 0, ARRAY_SIZE(word));
  10059. }
  10060. fclose(fptr1);
  10061. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  10062. }
  10063. //Check TxDefaultProfile_0.json exit
  10064. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  10065. {
  10066. i = 0;
  10067. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  10068. //Check Charging Profile Count
  10069. while(fscanf(fptr1, "%s", word) != EOF)
  10070. {
  10071. //DEBUG_INFO("word=%s\n",word);
  10072. if(strstr(word, "chargingProfileId")!= NULL)
  10073. {
  10074. //DEBUG_INFO("test chargingProfileId \n");
  10075. n_chargingProfile = n_chargingProfile + 1;
  10076. i = i + 1;
  10077. //DEBUG_INFO("chargingProfileId Found\n");
  10078. }
  10079. memset(word, 0, ARRAY_SIZE(word));
  10080. }
  10081. fclose(fptr1);
  10082. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  10083. }
  10084. //Check TxDefaultProfile_%d.json
  10085. for(int j=1; j <= gunTotalNumber; j++)
  10086. {
  10087. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10088. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  10089. if((access(fnametemp,F_OK))!=-1)
  10090. {
  10091. i = 0;
  10092. fptr1 = fopen(fnametemp, "r");
  10093. //Check Charging Profile Count
  10094. while(fscanf(fptr1, "%s", word) != EOF)
  10095. {
  10096. //DEBUG_INFO("word=%s\n",word);
  10097. if(strstr(word, "chargingProfileId")!= NULL)
  10098. {
  10099. //DEBUG_INFO("test chargingProfileId \n");
  10100. n_chargingProfile = n_chargingProfile + 1;
  10101. i = i + 1;
  10102. //DEBUG_INFO("chargingProfileId Found\n");
  10103. }
  10104. memset(word, 0, ARRAY_SIZE(word));
  10105. }
  10106. fclose(fptr1);
  10107. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10108. }
  10109. }
  10110. //Check TxProfile_%d.json
  10111. for(int j=1; j <= gunTotalNumber; j++)
  10112. {
  10113. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10114. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10115. if((access(fnametemp,F_OK))!=-1)
  10116. {
  10117. i = 0;
  10118. fptr1 = fopen(fnametemp, "r");
  10119. //Check Charging Profile Count
  10120. while(fscanf(fptr1, "%s", word) != EOF)
  10121. {
  10122. //DEBUG_INFO("word=%s\n",word);
  10123. if(strstr(word, "chargingProfileId")!= NULL)
  10124. {
  10125. //DEBUG_INFO("test chargingProfileId \n");
  10126. n_chargingProfile = n_chargingProfile + 1;
  10127. i = i + 1;
  10128. //DEBUG_INFO("chargingProfileId Found\n");
  10129. }
  10130. memset(word, 0, ARRAY_SIZE(word));
  10131. }
  10132. fclose(fptr1);
  10133. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10134. }
  10135. }
  10136. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10137. {
  10138. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10139. goto end;
  10140. }
  10141. }
  10142. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10143. //**********************************Write to File********************************************************/
  10144. FILE *infile;
  10145. FILE *outfile;
  10146. infile = fopen (filename, "r");
  10147. outfile = fopen (tempfile, "w");
  10148. int d =0;
  10149. d = fgetc(infile);
  10150. rewind(infile);
  10151. if(d == EOF)
  10152. {
  10153. // Profile is empty
  10154. fprintf(outfile,"%s\n",payload);
  10155. fclose(infile);
  10156. fclose(outfile);
  10157. sprintf(rmFileCmd,"rm -f %s",filename);
  10158. system(rmFileCmd);
  10159. rename(tempfile, filename);
  10160. }
  10161. else
  10162. {
  10163. // Profile is not empty
  10164. char buf[2048]={0};
  10165. int ChargingProfileAdded = FALSE;
  10166. while (fgets(buf, sizeof(buf), infile) != NULL)
  10167. {
  10168. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10169. json_object *tmpChargingProfile;
  10170. tmpChargingProfile = json_tokener_parse(buf);
  10171. if(!is_error(SetChargingProfile))
  10172. {
  10173. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10174. {
  10175. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10176. }
  10177. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10178. {
  10179. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10180. {
  10181. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10182. }
  10183. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10184. {
  10185. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10186. }
  10187. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10188. {
  10189. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10190. }
  10191. }
  10192. }
  10193. json_object_put(tmpChargingProfile);
  10194. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10195. {
  10196. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10197. {
  10198. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10199. if(ChargingProfileAdded == FALSE)
  10200. {
  10201. fprintf(outfile,"%s\n",payload);
  10202. ChargingProfileAdded = TRUE;
  10203. }
  10204. }
  10205. else
  10206. {
  10207. if(tempstackLevelInt < stackLevelInt)
  10208. {
  10209. if(ChargingProfileAdded == FALSE)
  10210. {
  10211. fprintf(outfile,"%s\n",buf);
  10212. fprintf(outfile,"%s\n",payload);
  10213. ChargingProfileAdded = TRUE;
  10214. }
  10215. else
  10216. {
  10217. fprintf(outfile,"%s\n",buf);
  10218. }
  10219. }
  10220. else
  10221. {
  10222. if(ChargingProfileAdded == FALSE)
  10223. {
  10224. fprintf(outfile,"%s\n",buf);
  10225. fprintf(outfile,"%s\n",payload);
  10226. ChargingProfileAdded = TRUE;
  10227. }
  10228. else
  10229. {
  10230. fprintf(outfile,"%s\n",buf);
  10231. }
  10232. }
  10233. }
  10234. }
  10235. else
  10236. {
  10237. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10238. {
  10239. if(ChargingProfileAdded == FALSE)
  10240. {
  10241. fprintf(outfile,"%s\n",buf);
  10242. fprintf(outfile,"%s\n",payload);
  10243. ChargingProfileAdded = TRUE;
  10244. }
  10245. else
  10246. {
  10247. fprintf(outfile,"%s\n",buf);
  10248. }
  10249. }
  10250. else if(tempstackLevelInt < stackLevelInt)
  10251. {
  10252. if(ChargingProfileAdded == FALSE)
  10253. {
  10254. fprintf(outfile,"%s\n",buf);
  10255. fprintf(outfile,"%s\n",payload);
  10256. ChargingProfileAdded = TRUE;
  10257. }
  10258. else
  10259. {
  10260. fprintf(outfile,"%s\n",buf);
  10261. }
  10262. }
  10263. else
  10264. {
  10265. if(ChargingProfileAdded == FALSE)
  10266. {
  10267. fprintf(outfile,"%s\n",buf);
  10268. fprintf(outfile,"%s\n",payload);
  10269. ChargingProfileAdded = TRUE;
  10270. }
  10271. else
  10272. {
  10273. fprintf(outfile,"%s\n",buf);
  10274. }
  10275. }
  10276. }
  10277. } // end of while loop
  10278. fclose(infile);
  10279. fclose(outfile);
  10280. sprintf(rmFileCmd,"rm -f %s",filename);
  10281. system(rmFileCmd);
  10282. rename(tempfile, filename);
  10283. }
  10284. sleep(1);
  10285. result = TRUE;
  10286. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10287. end:
  10288. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10289. {
  10290. if(connectorIdInt == 0)
  10291. {
  10292. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10293. {
  10294. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10295. }
  10296. }
  10297. else
  10298. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  10299. }
  10300. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10301. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10302. return result;
  10303. }
  10304. int handleTriggerMessageRequest(char *uuid, char *payload)
  10305. {
  10306. mtrace();
  10307. int result = FAIL;
  10308. int connectorIdIsNULL = FALSE;
  10309. int connectorIdInt =0;
  10310. char sstr[40]={0},sstrtemp[100]={ 0 };
  10311. char requestedMessagestr[40]={0};
  10312. char comfirmstr[20]={0};
  10313. int c = 0;
  10314. char *loc;
  10315. DEBUG_INFO("handleTriggerMessageRequest\n");
  10316. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10317. strcpy(sstrtemp, stringtrimspace(payload));
  10318. c = 0;
  10319. loc = strstr(sstrtemp, "requestedMessage");
  10320. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10321. {
  10322. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10323. c++;
  10324. }
  10325. sstr[c] = '\0';
  10326. strcpy(requestedMessagestr, sstr);
  10327. c = 0;
  10328. loc = strstr(sstrtemp, "connectorId");
  10329. if(loc == NULL)
  10330. {
  10331. connectorIdIsNULL = TRUE;
  10332. }
  10333. else
  10334. {
  10335. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10336. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10337. {
  10338. sstr[c] = loc[strlen("connectorId")+2+c];
  10339. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10340. c++;
  10341. }
  10342. sstr[c] = '\0';
  10343. connectorIdInt = atoi(sstr);
  10344. }
  10345. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10346. {
  10347. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10348. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10349. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10350. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10351. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10352. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10353. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10354. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10355. {
  10356. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10357. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10358. return TRUE;
  10359. }
  10360. else
  10361. {
  10362. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10363. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10364. }
  10365. }
  10366. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10367. {
  10368. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10369. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10370. return TRUE;
  10371. }
  10372. //==========================
  10373. // Trigger message
  10374. //==========================
  10375. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10376. {
  10377. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10378. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10379. {
  10380. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10381. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10382. }
  10383. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10384. }
  10385. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10386. {
  10387. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  10388. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10389. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10390. }
  10391. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10392. {
  10393. //sendBootNotificationRequest();
  10394. server_sign = FALSE;
  10395. }
  10396. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10397. {
  10398. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10399. }
  10400. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10401. {
  10402. if(connectorIdIsNULL == FALSE)
  10403. {
  10404. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10405. {
  10406. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10407. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10408. }
  10409. }
  10410. else
  10411. {
  10412. for(int idx=0;idx< gunTotalNumber;idx++)
  10413. {
  10414. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10415. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10416. }
  10417. }
  10418. }
  10419. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10420. {
  10421. if(connectorIdIsNULL == FALSE)
  10422. {
  10423. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10424. {
  10425. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10426. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  10427. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10428. }
  10429. }
  10430. else
  10431. {
  10432. for(int idx=0;idx< gunTotalNumber;idx++)
  10433. {
  10434. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  10435. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10436. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10437. }
  10438. }
  10439. }
  10440. return result;
  10441. }
  10442. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10443. {
  10444. mtrace();
  10445. int result = FAIL;
  10446. int connectorIdInt =0;
  10447. char comfirmstr[20]={0};
  10448. int tempIndex = 0;
  10449. json_object *UnlockConnector;
  10450. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10451. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10452. UnlockConnector = json_tokener_parse(payload);
  10453. if(!is_error(UnlockConnector))
  10454. {
  10455. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10456. {
  10457. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10458. }
  10459. }
  10460. json_object_put(UnlockConnector);
  10461. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10462. if(gunTotalNumber == 0)
  10463. {
  10464. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10465. goto end;
  10466. }
  10467. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10468. {
  10469. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10470. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10471. goto end;
  10472. }
  10473. else
  10474. {
  10475. //check Transaction active
  10476. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10477. {
  10478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10479. {
  10480. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10481. }
  10482. else
  10483. {
  10484. tempIndex = connectorIdInt -1;
  10485. }
  10486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10487. {
  10488. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10489. {
  10490. //stop Transaction
  10491. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10492. }
  10493. }
  10494. }
  10495. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10496. {
  10497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10498. {
  10499. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10500. }
  10501. else
  10502. {
  10503. tempIndex = connectorIdInt -1;
  10504. }
  10505. for (int index = 0; index < CCS_QUANTITY; index++)
  10506. {
  10507. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10508. {
  10509. //stop Transaction
  10510. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10511. }
  10512. }
  10513. }
  10514. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10515. {
  10516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10517. {
  10518. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10519. }
  10520. else
  10521. {
  10522. tempIndex = connectorIdInt -1;
  10523. }
  10524. for (int index = 0; index < GB_QUANTITY; index++)
  10525. {
  10526. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10527. {
  10528. //stop Transaction
  10529. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10530. }
  10531. }
  10532. }
  10533. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10534. {
  10535. tempIndex = connectorIdInt -1;
  10536. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10537. {
  10538. 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)))
  10539. {
  10540. //stop Transaction
  10541. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10542. }
  10543. }
  10544. }
  10545. else
  10546. {
  10547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10548. {
  10549. tempIndex = 2;
  10550. }
  10551. else
  10552. {
  10553. tempIndex = connectorIdInt-1;
  10554. }
  10555. for (int index = 0; index < AC_QUANTITY; index++)
  10556. {
  10557. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10558. {
  10559. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10560. }
  10561. }
  10562. }
  10563. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10564. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  10565. result = TRUE;
  10566. return result;
  10567. }
  10568. end:
  10569. //json_object_put(obj); --- remove temporally
  10570. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10571. return result;
  10572. }
  10573. static char UpdateFirmwarepayloadData[300]={0};
  10574. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10575. {
  10576. mtrace();
  10577. int result = FAIL;
  10578. pthread_t t;
  10579. sendUpdateFirmwareConfirmation(uuid);
  10580. memset(UpdateFirmwarepayloadData, 0, 300);
  10581. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10582. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10583. ////pthread_join(t, NULL); //
  10584. //pthread_detach(t);
  10585. //sendUpdateFirmwareConfirmation(uuid);
  10586. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  10587. return result;
  10588. }
  10589. void *UpdateFirmwareProcess(void *data)
  10590. {
  10591. pthread_detach(pthread_self());
  10592. mtrace();
  10593. int retriesInt =0, retryIntervalInt=0;
  10594. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10595. int port=0;
  10596. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10597. int isSuccess = 0;
  10598. char ftpbuf[512];
  10599. char temp[100];
  10600. char * pch;
  10601. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10602. json_object *UpdateFirmware;
  10603. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10604. if(!is_error(UpdateFirmware))
  10605. {
  10606. // Required data
  10607. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10608. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10609. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10610. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10611. // Optional data
  10612. if(json_object_object_get(UpdateFirmware, "retries"))
  10613. {
  10614. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10615. }
  10616. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10617. {
  10618. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10619. }
  10620. }
  10621. json_object_put(UpdateFirmware);
  10622. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10623. memset(path, 0, ARRAY_SIZE(path));
  10624. // Wait retrieveData
  10625. if(strlen(retrieveDatestr) > 10)
  10626. {
  10627. do
  10628. {
  10629. sleep(1);
  10630. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10631. }
  10632. // Ready to download
  10633. system("rm -f /mnt/*");
  10634. if(strncmp(locationstr,"http", 4) == 0)
  10635. {
  10636. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10637. sprintf(ftppath,"/%s", path);
  10638. DEBUG_INFO("locationstr: %s\n", locationstr);
  10639. DEBUG_INFO("protocol: %s\n",protocol);
  10640. DEBUG_INFO("host: %s\n",host);
  10641. DEBUG_INFO("path: %s\n",path);
  10642. DEBUG_INFO("ftppath: %s\n",ftppath);
  10643. int ftppathlen=strlen(ftppath);
  10644. int i=1;
  10645. char filenametemp[50];
  10646. while(i < ftppathlen)
  10647. {
  10648. int len=ftppathlen-i;
  10649. if(ftppath[len]== 47) // '/' ascll code: 47
  10650. {
  10651. DEBUG_INFO("compare '/' all right\n");
  10652. break;
  10653. }
  10654. i=i+1;
  10655. }
  10656. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10657. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10658. filenametemp[i+1] = 0;
  10659. do
  10660. {
  10661. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10662. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10663. sleep(1);
  10664. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10665. if(!isSuccess)
  10666. {
  10667. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10668. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10669. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10670. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10671. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10672. }
  10673. else
  10674. {
  10675. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10676. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10677. }
  10678. retriesInt--;
  10679. }while((isSuccess == 0)&&(retriesInt >= 0));
  10680. }
  10681. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10682. {
  10683. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10684. memset(temp, 0, ARRAY_SIZE(temp));
  10685. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10686. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10687. int ftppathlen=strlen(ftpbuf);
  10688. int i=1;
  10689. char filenametemp[50];
  10690. while(i < ftppathlen)
  10691. {
  10692. int len=ftppathlen-i;
  10693. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10694. {
  10695. DEBUG_INFO(" compare '/' all right\n");
  10696. break;
  10697. }
  10698. i=i+1;
  10699. }
  10700. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10701. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10702. filenametemp[i+1] = 0;
  10703. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10704. pch=strchr(temp,'@');
  10705. if(pch==NULL)
  10706. {
  10707. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10708. protocol, host, &port, path);
  10709. strcpy(user,"anonymous");
  10710. strcpy(password,"");
  10711. }
  10712. else
  10713. {
  10714. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10715. protocol, user, password, host, &port, path);
  10716. }
  10717. sscanf(host,"%[^/]%s",host1, path1);
  10718. sprintf(ftppath,"%s", path1);
  10719. //DEBUG_INFO("protocol =%s\n",protocol);
  10720. //DEBUG_INFO("user =%s\n",user);
  10721. //DEBUG_INFO("password =%s\n",password);
  10722. //DEBUG_INFO("host1 =%s\n",host1);
  10723. //DEBUG_INFO("port =%d\n",port);
  10724. //DEBUG_INFO("path1 =%s\n",path1);
  10725. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10726. //ftpFile(host, user, password, port, ftppath, fname);
  10727. //download firmware pthred
  10728. if(port == 0)
  10729. {
  10730. port = 21;
  10731. }
  10732. do
  10733. {
  10734. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10735. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10736. sleep(1);
  10737. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10738. if(!isSuccess)
  10739. {
  10740. //BulldogUtil.sleepMs(interval*1000);
  10741. DEBUG_INFO("Update firmware request and download file fail.\n");
  10742. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10743. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10744. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10745. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10746. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10747. }
  10748. else
  10749. {
  10750. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10751. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10752. }
  10753. retriesInt--;
  10754. }while((!isSuccess)&&(retriesInt >= 0));
  10755. }
  10756. else
  10757. {
  10758. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10759. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10760. sleep(1);
  10761. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10762. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10763. }
  10764. // OCPPPH only, must announce CSU upgrade firmware
  10765. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  10766. pthread_exit(NULL);
  10767. }
  10768. int handleCertificateSignedRequest(char *uuid, char *payload)
  10769. {
  10770. mtrace();
  10771. int result = PASS;
  10772. json_object *CertificateSigned;
  10773. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10774. CertificateSigned = json_tokener_parse(payload);
  10775. if(!is_error(CertificateSigned))
  10776. {
  10777. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10778. }
  10779. json_object_put(CertificateSigned);
  10780. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  10781. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  10782. fclose(fp);
  10783. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10784. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  10785. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  10786. sendCertificateSignedConfirmation(uuid);
  10787. return result;
  10788. }
  10789. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10790. {
  10791. mtrace();
  10792. int result = PASS;
  10793. json_object *DeleteCertificate;
  10794. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10795. DeleteCertificate = json_tokener_parse(payload);
  10796. if(!is_error(DeleteCertificate))
  10797. {
  10798. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10799. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10800. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10801. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10802. }
  10803. json_object_put(DeleteCertificate);
  10804. /*
  10805. * TODO: Delete certificateSigned process
  10806. */
  10807. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  10808. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  10809. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  10810. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  10811. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  10812. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  10813. sendDeleteCertificateConfirmation(uuid);
  10814. return result;
  10815. }
  10816. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10817. {
  10818. mtrace();
  10819. int result = PASS;
  10820. json_object *ExtendedTriggerMessage;
  10821. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10822. ExtendedTriggerMessage = json_tokener_parse(payload);
  10823. if(!is_error(ExtendedTriggerMessage))
  10824. {
  10825. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10826. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10827. {
  10828. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10829. }
  10830. else
  10831. {
  10832. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  10833. }
  10834. }
  10835. json_object_put(ExtendedTriggerMessage);
  10836. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  10837. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  10838. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10839. {
  10840. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10841. }
  10842. else
  10843. {
  10844. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10845. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10846. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10847. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10848. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10849. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10850. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10851. {
  10852. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10853. }
  10854. else
  10855. {
  10856. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10857. }
  10858. }
  10859. sendExtendedTriggerMessageConfirmation(uuid);
  10860. //==========================
  10861. // Trigger message
  10862. //==========================
  10863. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10864. {
  10865. //sendBootNotificationRequest();
  10866. server_sign = FALSE;
  10867. }
  10868. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10869. {
  10870. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  10871. }
  10872. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10873. {
  10874. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10875. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10876. {
  10877. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10878. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10879. }
  10880. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10881. }
  10882. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10883. {
  10884. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10885. }
  10886. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10887. {
  10888. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10889. {
  10890. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10891. }
  10892. else
  10893. {
  10894. for(int idx=0;idx< gunTotalNumber;idx++)
  10895. {
  10896. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10897. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10898. }
  10899. }
  10900. }
  10901. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10902. {
  10903. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  10904. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  10905. {
  10906. 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\" &");
  10907. }
  10908. }
  10909. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10910. {
  10911. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10912. {
  10913. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10914. }
  10915. else
  10916. {
  10917. for(int idx=0;idx< gunTotalNumber;idx++)
  10918. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10919. }
  10920. }
  10921. return result;
  10922. }
  10923. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10924. {
  10925. mtrace();
  10926. int result = PASS;
  10927. json_object *GetInstalledCertificateIds;
  10928. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10929. GetInstalledCertificateIds = json_tokener_parse(payload);
  10930. if(!is_error(GetInstalledCertificateIds))
  10931. {
  10932. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10933. }
  10934. json_object_put(GetInstalledCertificateIds);
  10935. /*
  10936. * TODO: Return installed certificate process
  10937. */
  10938. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10939. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  10940. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10941. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  10942. sendGetInstalledCertificateIdsConfirmation(uuid);
  10943. return result;
  10944. }
  10945. int handleGetLogRequest(char *uuid, char *payload)
  10946. {
  10947. mtrace();
  10948. int result = PASS;
  10949. json_object *GetLog;
  10950. DEBUG_INFO("handleGetLogRequest...\n");
  10951. GetLog = json_tokener_parse(payload);
  10952. if(!is_error(GetLog))
  10953. {
  10954. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10955. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10956. if(json_object_object_get(GetLog, "retries") != NULL)
  10957. {
  10958. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10959. }
  10960. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10961. {
  10962. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10963. }
  10964. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10965. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10966. {
  10967. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10968. }
  10969. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10970. {
  10971. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10972. }
  10973. }
  10974. json_object_put(GetLog);
  10975. /*
  10976. * TODO: Upload log process
  10977. */
  10978. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  10979. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  10980. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  10981. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  10982. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  10983. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  10984. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  10985. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  10986. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  10987. sendGetLogConfirmation(uuid);
  10988. return result;
  10989. }
  10990. int handleInstallCertificateRequest(char *uuid, char *payload)
  10991. {
  10992. mtrace();
  10993. int result = PASS;
  10994. json_object *InstallCertificate;
  10995. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10996. InstallCertificate = json_tokener_parse(payload);
  10997. if(!is_error(InstallCertificate))
  10998. {
  10999. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11000. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11001. /*
  11002. * TODO: Install certificate process
  11003. */
  11004. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  11005. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  11006. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  11007. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  11008. sendInstallCertificateConfirmation(uuid);
  11009. }
  11010. json_object_put(InstallCertificate);
  11011. return result;
  11012. }
  11013. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  11014. {
  11015. mtrace();
  11016. int result = PASS;
  11017. json_object *SignedUpdateFirmware;
  11018. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  11019. SignedUpdateFirmware = json_tokener_parse(payload);
  11020. if(!is_error(SignedUpdateFirmware))
  11021. {
  11022. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  11023. {
  11024. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  11025. }
  11026. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  11027. {
  11028. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  11029. }
  11030. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  11031. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  11032. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  11033. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  11034. {
  11035. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  11036. }
  11037. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  11038. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  11039. }
  11040. json_object_put(SignedUpdateFirmware);
  11041. /*
  11042. * TODO: Upgrade firmware process
  11043. */
  11044. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  11045. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  11046. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  11047. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  11048. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  11049. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  11050. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  11051. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  11052. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  11053. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  11054. sendInstallCertificateConfirmation(uuid);
  11055. return result;
  11056. }
  11057. int handleUnknownRequest(char *uuid, char *payload)
  11058. {
  11059. mtrace();
  11060. int result = PASS;
  11061. DEBUG_INFO("handleUnknownRequest...\n");
  11062. sendUnknownConfirmation(uuid);
  11063. result = PASS;
  11064. return result;
  11065. }
  11066. //==========================================
  11067. // Handle server response routine
  11068. //==========================================
  11069. void handleAuthorizeResponse(char *payload, int gun_index)
  11070. {
  11071. mtrace();
  11072. char expiryDatestr[30]={0};
  11073. char parentIdTagstr[20]={0};
  11074. char statusstr[20]={0};
  11075. int expiryDateISNULL=FALSE;
  11076. int parentIdTagISNULL=FALSE;
  11077. DEBUG_INFO("handleAuthorizeResponse...\n");
  11078. json_object *Authorize;
  11079. Authorize = json_tokener_parse(payload);
  11080. if(!is_error(Authorize))
  11081. {
  11082. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  11083. {
  11084. // Required data
  11085. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  11086. // Optional data
  11087. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  11088. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  11089. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  11090. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11091. }
  11092. }
  11093. json_object_put(Authorize);
  11094. if(expiryDateISNULL == FALSE)
  11095. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11096. if(parentIdTagISNULL == FALSE)
  11097. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11098. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11099. //Update idTag information to authorization cache if supproted
  11100. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11101. {
  11102. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11103. }
  11104. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11105. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11106. authorizeRetryTimes = 0;
  11107. }
  11108. void handleBootNotificationResponse(char *payload, int gun_index)
  11109. {
  11110. mtrace();
  11111. char statusStr[12]={0};
  11112. char currentTimeStr[30]={0};
  11113. int intervalInt = 0;
  11114. DEBUG_INFO("handleBootNotificationResponse...\n");
  11115. json_object *BootNotification;
  11116. BootNotification = json_tokener_parse(payload);
  11117. if(!is_error(BootNotification))
  11118. {
  11119. // Required data
  11120. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11121. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11122. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11123. }
  11124. json_object_put(BootNotification);
  11125. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11126. BootNotificationInterval = intervalInt;
  11127. HeartBeatWaitTime = intervalInt;
  11128. //write back to ShmOCPP16DataPH->BootNotification
  11129. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11130. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11131. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11132. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11133. {
  11134. server_sign = TRUE;
  11135. server_pending =FALSE;
  11136. }
  11137. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11138. {
  11139. server_pending = TRUE;
  11140. }
  11141. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11142. srand(time(NULL));
  11143. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11144. SetOcppConnStatus(TRUE);
  11145. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11146. }
  11147. void handleDataTransferResponse(char *payload, int gun_index)
  11148. {
  11149. char sstr[160]={0};//sstr[200]={ 0 };
  11150. int c = 0;
  11151. char *loc;
  11152. DEBUG_INFO("handleDataTransferResponse ...\n");
  11153. loc = strstr(payload, "status");
  11154. printf("loc=%s\n",loc);
  11155. c = 0;
  11156. while (loc[3+strlen("status")+c] != '\"')
  11157. {
  11158. sstr[c] = loc[3+strlen("status")+c];
  11159. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11160. c++;
  11161. }
  11162. sstr[c] = '\0';
  11163. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11164. }
  11165. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11166. {
  11167. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11168. //struct json_object *obj;
  11169. // obj = json_tokener_parse(payload);
  11170. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11171. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11172. //No fields are defined.
  11173. }
  11174. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11175. {
  11176. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11177. //struct json_object *obj;
  11178. // obj = json_tokener_parse(payload);
  11179. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11180. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11181. //No fields are defined.
  11182. }
  11183. void handleHeartbeatResponse(char *payload, int gun_index)
  11184. {
  11185. mtrace();
  11186. DEBUG_INFO("handleHeartbeatResponse...\n");
  11187. json_object *Heartbeat;
  11188. Heartbeat = json_tokener_parse(payload);
  11189. if(!is_error(Heartbeat))
  11190. {
  11191. // Required data
  11192. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11193. }
  11194. json_object_put(Heartbeat);
  11195. if(FirstHeartBeat == 0)
  11196. {
  11197. FirstHeartBeat = 1;
  11198. DEBUG_INFO("FirstHeartBeat \n");
  11199. }
  11200. HeartBeatWithNOResponse = 0;
  11201. clientTime.Heartbeat=time((time_t*)NULL);
  11202. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11203. }
  11204. void handleMeterValuesResponse(char *payload, int gun_index)
  11205. {
  11206. mtrace();
  11207. DEBUG_INFO("handleMeterValuesResponse...\n");
  11208. }
  11209. void handleStartTransactionResponse(char *payload, int gun_index)
  11210. {
  11211. mtrace();
  11212. //int transactionIdInt = 0;
  11213. FILE *outfile;
  11214. char data[100]={0};
  11215. DEBUG_INFO("handleStartTransactionResponse...\n");
  11216. json_object *StartTransaction;
  11217. StartTransaction = json_tokener_parse(payload);
  11218. if(!is_error(StartTransaction))
  11219. {
  11220. // Required data
  11221. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11222. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11223. // Optional data
  11224. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11225. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11226. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11227. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11228. }
  11229. json_object_put(StartTransaction);
  11230. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11231. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11232. //-----------Start : write to the Queue TransactionId file -----------------//
  11233. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11234. {}
  11235. else
  11236. {
  11237. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11238. if(log == NULL)
  11239. {
  11240. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11241. return ;
  11242. }
  11243. else
  11244. {
  11245. fclose(log);
  11246. }
  11247. }
  11248. // open file for writing
  11249. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11250. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11251. {
  11252. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11253. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11254. fputs(data, outfile);
  11255. fclose (outfile);
  11256. }
  11257. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11258. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11259. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11260. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11261. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11262. }
  11263. void handleStatusNotificationResponse(char *payload, int gun_index)
  11264. {
  11265. mtrace();
  11266. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11267. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11268. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11269. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11270. }
  11271. void handleStopTransactionnResponse(char *payload, int gun_index)
  11272. {
  11273. mtrace();
  11274. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11275. json_object *StopTransaction;
  11276. StopTransaction = json_tokener_parse(payload);
  11277. if(!is_error(StopTransaction))
  11278. {
  11279. // Optional data
  11280. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11281. {
  11282. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11283. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11284. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11285. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11286. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11287. }
  11288. }
  11289. json_object_put(StopTransaction);
  11290. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11291. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11292. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11293. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11294. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11295. }
  11296. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11297. {
  11298. mtrace();
  11299. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11300. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11301. }
  11302. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11303. {
  11304. mtrace();
  11305. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11306. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11307. }
  11308. void handleSignCertificateResponse(char *payload, int gun_index)
  11309. {
  11310. mtrace();
  11311. DEBUG_INFO("handleSignCertificateResponse...\n");
  11312. json_object *SignCertificate;
  11313. SignCertificate = json_tokener_parse(payload);
  11314. if(!is_error(SignCertificate))
  11315. {
  11316. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11317. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11318. }
  11319. json_object_put(SignCertificate);
  11320. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11321. }
  11322. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11323. {
  11324. mtrace();
  11325. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11326. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11327. }
  11328. //==========================================
  11329. // Handle Error routine
  11330. //==========================================
  11331. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11332. {
  11333. mtrace();
  11334. #ifdef SystemLogMessage
  11335. DEBUG_INFO("errorCode: %s\n", errorCode);
  11336. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11337. DEBUG_INFO("errorDetails: %s\n", payload);
  11338. #endif
  11339. }
  11340. //===============================================
  11341. // Common routine
  11342. //===============================================
  11343. int initialConfigurationTable(void)
  11344. {
  11345. //clock_t start_t, end_t, total_t;
  11346. FILE *fp;
  11347. FILE *outfile;
  11348. char str[512]={0};
  11349. char sstr[256]={0};
  11350. int c = 0;
  11351. char *loc;
  11352. int confVersion = 3;
  11353. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11354. //start_t = clock();
  11355. //printf("Starting of the program, start_t = %ld\n", start_t);
  11356. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11357. // Check configuration file size is correct
  11358. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  11359. {
  11360. struct stat st;
  11361. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  11362. if(st.st_size < 3100)
  11363. {
  11364. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  11365. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11366. }
  11367. }
  11368. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  11369. {
  11370. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11371. if(outfile == NULL)
  11372. {
  11373. DEBUG_INFO("Error opening file\n");
  11374. return FALSE;
  11375. }
  11376. /*Core Profile*/
  11377. //AllowOfflineTxForUnknownId
  11378. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11379. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11380. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11381. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11382. //AuthorizationCacheEnabled
  11383. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11385. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11387. //AuthorizeRemoteTxRequests
  11388. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11390. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11391. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11392. //BlinkRepeat
  11393. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11394. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11395. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11397. //ClockAlignedDataInterval
  11398. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11399. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11400. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11401. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11402. //ConnectionTimeOut
  11403. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11404. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11405. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11406. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11407. //GetConfigurationMaxKeys
  11408. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11409. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11410. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11411. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11412. // HeartbeatInterval
  11413. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11414. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11415. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11416. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11417. // LightIntensity
  11418. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11419. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11420. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11422. // LocalAuthorizeOffline
  11423. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11424. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11425. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11426. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11427. // LocalPreAuthorize
  11428. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11429. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11430. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11432. // MaxEnergyOnInvalidId
  11433. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11434. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11435. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11437. // MeterValuesAlignedData
  11438. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11439. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11441. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11442. else
  11443. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11444. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11445. // MeterValuesAlignedDataMaxLength
  11446. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11447. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11448. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11449. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11450. else
  11451. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11453. // MeterValuesSampledData
  11454. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11455. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11457. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11458. else
  11459. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11461. // MeterValuesSampledDataMaxLength
  11462. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11463. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11465. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11466. else
  11467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11468. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11469. // MeterValueSampleInterval
  11470. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11471. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11474. // MinimumStatusDuration
  11475. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11476. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11477. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11478. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11480. // NumberOfConnectors
  11481. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11482. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11483. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11484. {
  11485. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11486. }
  11487. else
  11488. {
  11489. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11490. }
  11491. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11492. // ResetRetries
  11493. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11495. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11496. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11497. // ConnectorPhaseRotation
  11498. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11499. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11500. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11502. // ConnectorPhaseRotationMaxLength
  11503. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11504. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11505. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11506. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11507. // StopTransactionOnEVSideDisconnect
  11508. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11509. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11510. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11511. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11512. // StopTransactionOnInvalidId
  11513. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11514. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11515. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11517. // StopTxnAlignedData
  11518. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11519. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11520. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11522. // StopTxnAlignedDataMaxLength
  11523. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11524. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11525. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11527. // StopTxnSampledData
  11528. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11529. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11530. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11531. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11532. else
  11533. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11534. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11535. // StopTxnSampledDataMaxLength
  11536. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11537. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11538. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11539. {
  11540. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11541. }
  11542. else
  11543. {
  11544. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11545. }
  11546. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11547. // SupportedFeatureProfiles
  11548. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11549. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11550. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11552. // SupportedFeatureProfilesMaxLength
  11553. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11555. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11556. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11557. // TransactionMessageAttempts
  11558. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11560. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11561. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11563. // TransactionMessageRetryInterval
  11564. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11565. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11566. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11567. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11569. // UnlockConnectorOnEVSideDisconnect
  11570. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11571. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11572. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11574. // WebSocketPingInterval
  11575. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11576. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11577. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11579. // QueueOffLineStartTransactionMessage
  11580. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11581. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11582. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11584. // AuthorizationKey
  11585. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11586. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11587. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  11588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11589. // SecurityProfile
  11590. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11591. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11592. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11594. // DefaultPrice
  11595. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11596. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11597. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11599. // CustomDisplayCostAndPrice
  11600. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11601. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11602. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11603. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11604. // CustomIdleFeeAfterStop
  11605. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11606. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11607. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11608. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11609. // Configuration Version
  11610. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11611. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11612. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11613. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11614. //* Local Auth List Management Profile*/
  11615. #if 0
  11616. //For OCTT Test Case
  11617. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11618. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11619. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11620. #endif
  11621. #if 1
  11622. //LocalAuthListEnabled
  11623. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11624. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11625. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11627. #endif
  11628. //LocalAuthListMaxLength
  11629. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11630. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11631. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11632. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11633. //SendLocalListMaxLength
  11634. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11635. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11636. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11638. //ReserveConnectorZeroSupported
  11639. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11640. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11641. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11643. //* Smart Charging Profile */
  11644. //ChargeProfileMaxStackLevel
  11645. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11646. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11647. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11648. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11649. // ChargingScheduleAllowedChargingRateUnit
  11650. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11651. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11652. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11654. // ChargingScheduleMaxPeriods
  11655. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11656. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11657. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11659. // ConnectorSwitch3to1PhaseSupported
  11660. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11661. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11662. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11664. // MaxChargingProfilesInstalled
  11665. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11666. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11667. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11669. fclose(outfile);
  11670. }
  11671. else
  11672. {
  11673. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  11674. char keystr[60]={0};
  11675. char readonlystr[10]={0};
  11676. char valuestr[256]={0};
  11677. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  11678. if(fp == NULL) {
  11679. DEBUG_INFO("Error opening file");
  11680. return FALSE;
  11681. }
  11682. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11683. {
  11684. //DEBUG_INFO("Get Configuration \n");
  11685. if(strlen(str) > 0)
  11686. {
  11687. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11688. //*************************key*********************************/
  11689. if(strstr(str, "key") != NULL)
  11690. {
  11691. loc = strstr(str, "key");
  11692. c = 0;
  11693. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11694. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11695. {
  11696. sstr[c] = loc[strlen("key")+3+c];
  11697. c++;
  11698. }
  11699. sstr[c] = '\0';
  11700. strcpy(keystr,sstr);
  11701. }
  11702. //*************************readonly*********************************/
  11703. if(strstr(str, "readonly") != NULL)
  11704. {
  11705. loc = strstr(str, "readonly");
  11706. c = 0;
  11707. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11708. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11709. {
  11710. sstr[c] = loc[strlen("readonly")+2+c];
  11711. c++;
  11712. }
  11713. sstr[c] = '\0';
  11714. strcpy(readonlystr,sstr);
  11715. }
  11716. //*************************value*********************************/
  11717. if(strstr(str, "value") != NULL)
  11718. {
  11719. loc = strstr(str, "value");
  11720. c = 0;
  11721. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11722. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11723. {
  11724. sstr[c] = loc[strlen("value")+3+c];
  11725. c++;
  11726. }
  11727. sstr[c] = '\0';
  11728. strcpy(valuestr,sstr);
  11729. }
  11730. // DEBUG_INFO("keystr=%s\n",keystr);
  11731. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11732. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11733. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11734. {
  11735. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11736. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11737. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11738. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11739. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11740. }
  11741. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11742. {
  11743. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11744. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11745. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11746. }
  11747. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11748. {
  11749. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11751. }
  11752. if(strcmp(keystr, "BlinkRepeat") == 0)
  11753. {
  11754. //Charger.BlinkRepeat = Integer.parseInt(value);
  11755. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11756. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11757. }
  11758. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11759. {
  11760. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11761. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11762. }
  11763. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11764. {
  11765. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11766. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11767. }
  11768. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11769. {
  11770. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11772. }
  11773. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11774. {
  11775. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11776. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11777. HeartBeatWaitTime = atoi(valuestr);
  11778. }
  11779. if(strcmp(keystr, "LightIntensity") == 0)
  11780. {
  11781. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11782. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11783. }
  11784. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11785. {
  11786. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11787. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11788. }
  11789. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11790. {
  11791. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11792. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11793. }
  11794. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11795. {
  11796. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11797. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11798. }
  11799. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11800. {
  11801. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11802. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11803. }
  11804. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11805. {
  11806. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11807. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11808. }
  11809. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11810. {
  11811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11812. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11813. }
  11814. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11815. {
  11816. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11817. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11818. }
  11819. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11820. {
  11821. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11822. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11823. }
  11824. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11825. {
  11826. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11827. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11828. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11829. }
  11830. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11831. {
  11832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11833. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11834. }
  11835. if(strcmp(keystr, "ResetRetries") == 0)
  11836. {
  11837. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11838. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11839. }
  11840. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11841. {
  11842. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11843. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11844. }
  11845. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11846. {
  11847. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11848. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11849. }
  11850. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11851. {
  11852. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11853. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11854. }
  11855. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11856. {
  11857. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11858. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11859. }
  11860. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11861. {
  11862. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11863. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11864. }
  11865. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11866. {
  11867. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11868. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11869. }
  11870. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11871. {
  11872. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11873. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11874. }
  11875. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11876. {
  11877. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11878. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11879. }
  11880. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11881. {
  11882. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11883. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11884. }
  11885. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11886. {
  11887. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11888. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11889. }
  11890. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11891. {
  11892. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11893. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11894. TransactionMessageAttemptsValue = atoi(valuestr);
  11895. }
  11896. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11897. {
  11898. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11900. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11901. }
  11902. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11903. {
  11904. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11905. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11906. }
  11907. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11908. {
  11909. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11910. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11911. }
  11912. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11913. {
  11914. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11915. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11916. }
  11917. if(strcmp(keystr, "AuthorizationKey") == 0)
  11918. {
  11919. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11920. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11921. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11922. }
  11923. if(strcmp(keystr, "SecurityProfile") == 0)
  11924. {
  11925. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11926. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11927. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11928. }
  11929. if(strcmp(keystr, "DefaultPrice") == 0)
  11930. {
  11931. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11932. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11933. }
  11934. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11935. {
  11936. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11937. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11938. }
  11939. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11940. {
  11941. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11942. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11943. }
  11944. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11945. {
  11946. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11947. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11948. }
  11949. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11950. {
  11951. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11952. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11953. }
  11954. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11955. {
  11956. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11957. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11958. }
  11959. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11960. {
  11961. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11962. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11963. }
  11964. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11965. {
  11966. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11967. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11968. }
  11969. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11970. {
  11971. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11972. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11973. }
  11974. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11975. {
  11976. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11977. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11978. }
  11979. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11980. {
  11981. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11982. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11983. }
  11984. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11985. {
  11986. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11987. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11988. }
  11989. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11990. {
  11991. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11992. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11993. }
  11994. }
  11995. }
  11996. fclose(fp);
  11997. }
  11998. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11999. {
  12000. return PASS;
  12001. }
  12002. else
  12003. {
  12004. return FAIL;
  12005. }
  12006. }
  12007. void StoreConfigurationTable(void)
  12008. {
  12009. FILE *outfile;
  12010. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  12011. if(outfile == NULL)
  12012. {
  12013. DEBUG_INFO("Error opening file");
  12014. return ;
  12015. }
  12016. /*Core Profile*/
  12017. //AllowOfflineTxForUnknownId
  12018. /*
  12019. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  12020. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  12021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  12022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  12023. */
  12024. //DEBUG_INFO("data=%s\n",data);
  12025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  12026. //AuthorizationCacheEnabled
  12027. /*
  12028. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  12029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  12030. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  12031. */
  12032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  12033. //AuthorizeRemoteTxRequests
  12034. /*
  12035. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  12036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  12037. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  12038. */
  12039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  12040. //BlinkRepeat
  12041. /*
  12042. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  12043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  12044. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  12045. */
  12046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  12047. //ClockAlignedDataInterval
  12048. /*
  12049. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  12050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  12051. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  12052. */
  12053. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  12054. //ConnectionTimeOut
  12055. /*
  12056. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  12057. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  12058. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  12059. */
  12060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  12061. //GetConfigurationMaxKeys
  12062. /*
  12063. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  12064. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  12065. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  12066. */
  12067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  12068. // HeartbeatInterval
  12069. /*
  12070. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  12071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  12072. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  12073. */
  12074. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  12075. // LightIntensity
  12076. /*
  12077. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  12078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  12079. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  12080. */
  12081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  12082. // LocalAuthorizeOffline
  12083. /*
  12084. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  12085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  12086. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  12087. */
  12088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12089. // LocalPreAuthorize
  12090. /*
  12091. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  12092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12093. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12094. */
  12095. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12096. // MaxEnergyOnInvalidId
  12097. /*
  12098. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12100. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12101. */
  12102. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12104. // MeterValuesAlignedData
  12105. /*
  12106. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12107. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12108. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12109. */
  12110. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12111. // MeterValuesAlignedDataMaxLength
  12112. /*
  12113. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12114. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12115. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12116. */
  12117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12118. // MeterValuesSampledData
  12119. /*
  12120. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12121. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12122. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12123. */
  12124. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12125. // MeterValuesSampledDataMaxLength
  12126. /*
  12127. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12128. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12129. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12130. */
  12131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12132. // MeterValueSampleInterval
  12133. /*
  12134. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12135. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12136. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12137. */
  12138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12139. // MinimumStatusDuration
  12140. /*
  12141. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12142. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12143. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12144. */
  12145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12146. // NumberOfConnectors
  12147. /*
  12148. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12149. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12151. {
  12152. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12153. }
  12154. else
  12155. {
  12156. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12157. }
  12158. */
  12159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12160. // ResetRetries
  12161. /*
  12162. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12163. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12164. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12165. */
  12166. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12167. // ConnectorPhaseRotation
  12168. /*
  12169. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12170. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12171. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12172. */
  12173. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12174. // ConnectorPhaseRotationMaxLength
  12175. /*
  12176. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12177. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12178. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12179. */
  12180. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12181. // StopTransactionOnEVSideDisconnect
  12182. /*
  12183. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12184. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12185. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12186. */
  12187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12188. // StopTransactionOnInvalidId
  12189. /*
  12190. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12191. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12192. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12193. */
  12194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12195. // StopTxnAlignedData
  12196. /*
  12197. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12198. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12199. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12200. */
  12201. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12202. // StopTxnAlignedDataMaxLength
  12203. /*
  12204. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12205. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12206. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12207. */
  12208. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12209. // StopTxnSampledData
  12210. /*
  12211. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12212. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12213. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12214. */
  12215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12216. // StopTxnSampledDataMaxLength
  12217. /*
  12218. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12219. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12220. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12221. */
  12222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12223. // SupportedFeatureProfiles
  12224. /*
  12225. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12227. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12228. */
  12229. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12230. // SupportedFeatureProfilesMaxLength
  12231. /*
  12232. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12233. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12234. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12235. */
  12236. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12237. // TransactionMessageAttempts
  12238. /*
  12239. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12241. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12242. */
  12243. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12244. // TransactionMessageRetryInterval
  12245. /*
  12246. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12248. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12249. */
  12250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12251. // UnlockConnectorOnEVSideDisconnect
  12252. /*
  12253. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12256. */
  12257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12258. // WebSocketPingInterval
  12259. /*
  12260. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12263. */
  12264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12265. // QueueOffLineStartTransactionMessage
  12266. /*
  12267. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12270. */
  12271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12272. // AuthorizationKey
  12273. /*
  12274. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12277. */
  12278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12279. // SecurityProfile
  12280. /*
  12281. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12282. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12284. */
  12285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12286. // DefaultPrice
  12287. /*
  12288. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12289. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12290. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12291. */
  12292. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12293. // CustomDisplayCostAndPrice
  12294. /*
  12295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12298. */
  12299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12300. // CustomIdleFeeAfterStop
  12301. /*
  12302. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12303. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12304. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12305. */
  12306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12307. // ConfigurationVersion
  12308. /*
  12309. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12310. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12312. */
  12313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12314. //* Local Auth List Management Profile*/
  12315. //LocalAuthListEnabled
  12316. /*
  12317. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12318. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12319. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12320. */
  12321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12322. //LocalAuthListMaxLength
  12323. /*
  12324. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12325. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12327. */
  12328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12329. //SendLocalListMaxLength
  12330. /*
  12331. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12333. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12334. */
  12335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12336. //ReserveConnectorZeroSupported
  12337. /*
  12338. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12339. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12340. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12341. */
  12342. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12343. //* Smart Charging Profile */
  12344. //ChargeProfileMaxStackLevel
  12345. /*
  12346. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12347. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12349. */
  12350. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12351. // ChargingScheduleAllowedChargingRateUnit
  12352. /*
  12353. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12355. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12356. */
  12357. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12358. // ChargingScheduleMaxPeriods
  12359. /*
  12360. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12361. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12363. */
  12364. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12365. // ConnectorSwitch3to1PhaseSupported
  12366. /*
  12367. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12368. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12369. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12370. */
  12371. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12372. // MaxChargingProfilesInstalled
  12373. /*
  12374. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12375. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12376. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12377. */
  12378. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12379. fclose(outfile);
  12380. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12381. }
  12382. void getKeyValue(char *keyReq)
  12383. {
  12384. int isEmpty = FALSE;
  12385. int isKnowKey = FALSE;
  12386. DEBUG_INFO("keyReq = %s\n", keyReq);
  12387. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12388. isEmpty = TRUE;
  12389. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12390. {
  12391. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12393. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12394. {
  12395. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12396. }
  12397. else
  12398. {
  12399. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12400. }
  12401. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12402. isKnowKey = TRUE;
  12403. }
  12404. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12405. {
  12406. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12408. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12409. {
  12410. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12411. }
  12412. else
  12413. {
  12414. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12415. }
  12416. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12417. isKnowKey = TRUE;
  12418. }
  12419. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12420. {
  12421. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12423. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12424. {
  12425. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12426. }
  12427. else
  12428. {
  12429. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12430. }
  12431. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12432. isKnowKey = TRUE;
  12433. }
  12434. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12435. {
  12436. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12438. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12439. {
  12440. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12441. }
  12442. else
  12443. {
  12444. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12445. }
  12446. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12447. isKnowKey = TRUE;
  12448. }
  12449. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12450. {
  12451. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12453. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12454. {
  12455. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12456. }
  12457. else
  12458. {
  12459. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12460. }
  12461. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12462. isKnowKey = TRUE;
  12463. }
  12464. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12465. {
  12466. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12468. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12469. {
  12470. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12471. }
  12472. else
  12473. {
  12474. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12475. }
  12476. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12477. isKnowKey = TRUE;
  12478. }
  12479. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12480. {
  12481. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12483. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12484. {
  12485. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12486. }
  12487. else
  12488. {
  12489. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12490. }
  12491. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12492. isKnowKey = TRUE;
  12493. }
  12494. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12495. {
  12496. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12498. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12499. {
  12500. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12501. }
  12502. else
  12503. {
  12504. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12505. }
  12506. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12507. isKnowKey = TRUE;
  12508. }
  12509. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12510. {
  12511. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12513. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12514. {
  12515. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12516. }
  12517. else
  12518. {
  12519. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12520. }
  12521. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12522. isKnowKey = TRUE;
  12523. }
  12524. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12525. {
  12526. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12528. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12529. {
  12530. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12531. }
  12532. else
  12533. {
  12534. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12535. }
  12536. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12537. isKnowKey = TRUE;
  12538. }
  12539. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12540. {
  12541. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12543. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12544. {
  12545. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12546. }
  12547. else
  12548. {
  12549. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12550. }
  12551. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12552. isKnowKey = TRUE;
  12553. }
  12554. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12555. {
  12556. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12558. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12559. {
  12560. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12561. }
  12562. else
  12563. {
  12564. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12565. }
  12566. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12567. isKnowKey = TRUE;
  12568. }
  12569. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12570. {
  12571. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12573. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12574. {
  12575. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12576. }
  12577. else
  12578. {
  12579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12580. }
  12581. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12582. isKnowKey = TRUE;
  12583. }
  12584. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12585. {
  12586. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12587. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12588. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12589. {
  12590. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12591. }
  12592. else
  12593. {
  12594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12595. }
  12596. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12597. isKnowKey = TRUE;
  12598. }
  12599. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12600. {
  12601. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12602. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12603. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12604. {
  12605. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12606. }
  12607. else
  12608. {
  12609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12610. }
  12611. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12612. isKnowKey = TRUE;
  12613. }
  12614. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12615. {
  12616. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12617. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12618. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12619. {
  12620. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12621. }
  12622. else
  12623. {
  12624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12625. }
  12626. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12627. isKnowKey = TRUE;
  12628. }
  12629. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12630. {
  12631. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12632. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12633. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12634. {
  12635. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12636. }
  12637. else
  12638. {
  12639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12640. }
  12641. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12642. isKnowKey = TRUE;
  12643. }
  12644. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12645. {
  12646. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12647. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12648. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12649. {
  12650. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12651. }
  12652. else
  12653. {
  12654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12655. }
  12656. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  12657. isKnowKey = TRUE;
  12658. }
  12659. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12660. {
  12661. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12662. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12663. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12664. {
  12665. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12666. }
  12667. else
  12668. {
  12669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12670. }
  12671. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12672. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12673. isKnowKey = TRUE;
  12674. }
  12675. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12676. {
  12677. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12679. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12680. {
  12681. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12682. }
  12683. else
  12684. {
  12685. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12686. }
  12687. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12688. isKnowKey = TRUE;
  12689. }
  12690. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12691. {
  12692. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12694. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12695. {
  12696. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12697. }
  12698. else
  12699. {
  12700. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12701. }
  12702. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12703. isKnowKey = TRUE;
  12704. }
  12705. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12706. {
  12707. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12709. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12710. {
  12711. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12712. }
  12713. else
  12714. {
  12715. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12716. }
  12717. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12718. isKnowKey = TRUE;
  12719. }
  12720. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12721. {
  12722. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12724. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12725. {
  12726. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12727. }
  12728. else
  12729. {
  12730. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12731. }
  12732. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12733. isKnowKey = TRUE;
  12734. }
  12735. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12736. {
  12737. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12739. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12740. {
  12741. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12742. }
  12743. else
  12744. {
  12745. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12746. }
  12747. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12748. isKnowKey = TRUE;
  12749. }
  12750. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12751. {
  12752. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12754. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12755. {
  12756. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12757. }
  12758. else
  12759. {
  12760. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12761. }
  12762. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12763. isKnowKey = TRUE;
  12764. }
  12765. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12766. {
  12767. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12769. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12770. {
  12771. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12772. }
  12773. else
  12774. {
  12775. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12776. }
  12777. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12778. isKnowKey = TRUE;
  12779. }
  12780. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12781. {
  12782. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12784. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12785. {
  12786. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12787. }
  12788. else
  12789. {
  12790. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12791. }
  12792. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12793. isKnowKey = TRUE;
  12794. }
  12795. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12796. {
  12797. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12799. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12800. {
  12801. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12802. }
  12803. else
  12804. {
  12805. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12806. }
  12807. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12808. isKnowKey = TRUE;
  12809. }
  12810. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12811. {
  12812. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12814. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12815. {
  12816. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12817. }
  12818. else
  12819. {
  12820. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12821. }
  12822. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12823. isKnowKey = TRUE;
  12824. }
  12825. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12826. {
  12827. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12828. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12829. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12830. {
  12831. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12832. }
  12833. else
  12834. {
  12835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12836. }
  12837. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12838. isKnowKey = TRUE;
  12839. }
  12840. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12841. {
  12842. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12843. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12844. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12845. {
  12846. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12847. }
  12848. else
  12849. {
  12850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12851. }
  12852. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12853. isKnowKey = TRUE;
  12854. }
  12855. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12856. {
  12857. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12858. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12859. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12860. {
  12861. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12862. }
  12863. else
  12864. {
  12865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12866. }
  12867. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12868. isKnowKey = TRUE;
  12869. }
  12870. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12871. {
  12872. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12873. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12874. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12875. {
  12876. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12877. }
  12878. else
  12879. {
  12880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12881. }
  12882. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12883. isKnowKey = TRUE;
  12884. }
  12885. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12886. {
  12887. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12888. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12889. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12890. {
  12891. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12892. }
  12893. else
  12894. {
  12895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12896. }
  12897. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12898. isKnowKey = TRUE;
  12899. }
  12900. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12901. {
  12902. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12903. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12904. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12905. {
  12906. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12907. }
  12908. else
  12909. {
  12910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12911. }
  12912. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12913. isKnowKey = TRUE;
  12914. }
  12915. /*
  12916. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12917. {
  12918. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12919. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12920. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12921. {
  12922. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12923. }
  12924. else
  12925. {
  12926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12927. }
  12928. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12929. isKnowKey = TRUE;
  12930. }*/
  12931. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12932. {
  12933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12934. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12935. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12936. {
  12937. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12938. }
  12939. else
  12940. {
  12941. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12942. }
  12943. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12944. isKnowKey = TRUE;
  12945. }
  12946. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12947. {
  12948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12949. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12950. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12951. {
  12952. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12953. }
  12954. else
  12955. {
  12956. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12957. }
  12958. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12959. isKnowKey = TRUE;
  12960. }
  12961. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12962. {
  12963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12964. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12965. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12966. {
  12967. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12968. }
  12969. else
  12970. {
  12971. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12972. }
  12973. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12974. isKnowKey = TRUE;
  12975. }
  12976. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12977. {
  12978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12979. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12980. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12981. {
  12982. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12983. }
  12984. else
  12985. {
  12986. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12987. }
  12988. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12989. isKnowKey = TRUE;
  12990. }
  12991. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12992. {
  12993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12994. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12995. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12996. {
  12997. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12998. }
  12999. else
  13000. {
  13001. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  13002. }
  13003. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  13004. isKnowKey = TRUE;
  13005. }
  13006. #if 1
  13007. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  13008. {
  13009. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  13010. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  13011. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13012. {
  13013. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  13014. }
  13015. else
  13016. {
  13017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  13018. }
  13019. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  13020. isKnowKey = TRUE;
  13021. }
  13022. #endif
  13023. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  13024. {
  13025. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  13026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  13027. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13028. {
  13029. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13030. }
  13031. else
  13032. {
  13033. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13034. }
  13035. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  13036. isKnowKey = TRUE;
  13037. }
  13038. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  13039. {
  13040. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  13041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  13042. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13043. {
  13044. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  13045. }
  13046. else
  13047. {
  13048. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  13049. }
  13050. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  13051. isKnowKey = TRUE;
  13052. }
  13053. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  13054. {
  13055. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  13056. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  13057. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13058. {
  13059. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  13060. }
  13061. else
  13062. {
  13063. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  13064. }
  13065. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  13066. isKnowKey = TRUE;
  13067. }
  13068. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  13069. {
  13070. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  13071. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  13072. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13073. {
  13074. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  13075. }
  13076. else
  13077. {
  13078. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  13079. }
  13080. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  13081. isKnowKey = TRUE;
  13082. }
  13083. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  13084. {
  13085. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  13086. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  13087. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  13088. {
  13089. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  13090. }
  13091. else
  13092. {
  13093. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13094. }
  13095. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13096. isKnowKey = TRUE;
  13097. }
  13098. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13099. {
  13100. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13101. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13102. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13103. {
  13104. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13105. }
  13106. else
  13107. {
  13108. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13109. }
  13110. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13111. isKnowKey = TRUE;
  13112. }
  13113. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13114. {
  13115. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13116. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13117. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13118. {
  13119. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13120. }
  13121. else
  13122. {
  13123. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13124. }
  13125. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13126. isKnowKey = TRUE;
  13127. }
  13128. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13129. {
  13130. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13131. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13132. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13133. {
  13134. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13135. }
  13136. else
  13137. {
  13138. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13139. }
  13140. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13141. isKnowKey = TRUE;
  13142. }
  13143. //=========================================================
  13144. if(!isEmpty && !isKnowKey)
  13145. {
  13146. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13147. strcpy(unknownkey[UnknownKeynum], keyReq);
  13148. UnknownKeynum = UnknownKeynum + 1;
  13149. }
  13150. }
  13151. void processUnkownKey(void)
  13152. {
  13153. DEBUG_INFO("processUnkownKey...\n");
  13154. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13155. for(int index=0; index < UnknownKeynum; index++)
  13156. {
  13157. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13158. {
  13159. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13160. }
  13161. }
  13162. }
  13163. int setKeyValue(char *key, char *value)
  13164. {
  13165. int isSuccess = NotSupported;
  13166. int check_ascii=0;
  13167. char str[256]={0};
  13168. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13169. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13170. {
  13171. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13172. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13173. {
  13174. strcpy(str, (const char*)value);
  13175. for(int i = 0; str[i]; i++){
  13176. str[i] = tolower(str[i]);
  13177. }
  13178. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13179. isSuccess = ConfigurationStatus_Accepted;
  13180. }
  13181. else
  13182. {
  13183. isSuccess = ConfigurationStatus_Rejected;
  13184. }
  13185. }
  13186. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13187. {
  13188. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13189. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13190. {
  13191. strcpy(str, (const char*)value);
  13192. for(int i = 0; str[i]; i++){
  13193. str[i] = tolower(str[i]);
  13194. }
  13195. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13196. isSuccess = ConfigurationStatus_Accepted;
  13197. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13198. }
  13199. else
  13200. {
  13201. isSuccess = ConfigurationStatus_Rejected;
  13202. }
  13203. }
  13204. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13205. {
  13206. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13207. {
  13208. strcpy(str, (const char*)value);
  13209. for(int i = 0; str[i]; i++)
  13210. {
  13211. str[i] = tolower(str[i]);
  13212. }
  13213. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13214. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13215. isSuccess = ConfigurationStatus_Accepted;
  13216. }
  13217. else
  13218. {
  13219. isSuccess = ConfigurationStatus_Rejected;
  13220. }
  13221. }
  13222. if(strcmp(key, "BlinkRepeat") == 0)
  13223. {
  13224. //Charger.BlinkRepeat = Integer.parseInt(value);
  13225. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13226. {
  13227. check_ascii = value[0];
  13228. if( (check_ascii < 48) || (check_ascii > 57) )
  13229. {
  13230. isSuccess = ConfigurationStatus_Rejected;
  13231. }
  13232. else
  13233. {
  13234. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13235. isSuccess = ConfigurationStatus_Accepted;
  13236. }
  13237. }
  13238. else
  13239. {
  13240. isSuccess = ConfigurationStatus_Rejected;
  13241. }
  13242. }
  13243. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13244. {
  13245. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13246. {
  13247. check_ascii = value[0];
  13248. if( (check_ascii < 48) || (check_ascii > 57) )
  13249. {
  13250. isSuccess = ConfigurationStatus_Rejected;
  13251. }
  13252. else
  13253. {
  13254. if((atoi(value) == 0) || (atoi(value) >= 10))
  13255. {
  13256. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13257. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13258. isSuccess = ConfigurationStatus_Accepted;
  13259. }
  13260. else
  13261. isSuccess = ConfigurationStatus_Rejected;
  13262. }
  13263. }
  13264. else
  13265. {
  13266. isSuccess = ConfigurationStatus_Rejected;
  13267. }
  13268. }
  13269. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13270. {
  13271. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13272. {
  13273. check_ascii = value[0];
  13274. if( (check_ascii < 48) || (check_ascii > 57) )
  13275. {
  13276. isSuccess = ConfigurationStatus_Rejected;
  13277. }
  13278. else
  13279. {
  13280. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13281. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13282. isSuccess = ConfigurationStatus_Accepted;
  13283. }
  13284. }
  13285. else
  13286. {
  13287. isSuccess = ConfigurationStatus_Rejected;
  13288. }
  13289. }
  13290. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13291. {
  13292. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13293. {
  13294. check_ascii = value[0];
  13295. if( (check_ascii < 48) || (check_ascii > 57) )
  13296. {
  13297. isSuccess = ConfigurationStatus_Rejected;
  13298. }
  13299. else
  13300. {
  13301. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13302. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13303. isSuccess = ConfigurationStatus_Accepted;
  13304. }
  13305. }
  13306. else
  13307. {
  13308. isSuccess = ConfigurationStatus_Rejected;
  13309. }
  13310. }
  13311. if(strcmp(key, "HeartbeatInterval") == 0)
  13312. {
  13313. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13314. {
  13315. check_ascii = value[0];
  13316. if( (check_ascii < 48) || (check_ascii > 57) )
  13317. {
  13318. isSuccess = ConfigurationStatus_Rejected;
  13319. }
  13320. else
  13321. {
  13322. if((atoi(value) == 0) || (atoi(value) >= 10))
  13323. {
  13324. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13325. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13326. HeartBeatWaitTime = atoi(value);
  13327. isSuccess = ConfigurationStatus_Accepted;
  13328. }
  13329. else
  13330. {
  13331. isSuccess = ConfigurationStatus_Rejected;
  13332. }
  13333. }
  13334. }
  13335. else
  13336. {
  13337. isSuccess = ConfigurationStatus_Rejected;
  13338. }
  13339. }
  13340. if(strcmp(key, "LightIntensity") == 0)
  13341. {
  13342. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13343. {
  13344. check_ascii = value[0];
  13345. if( (check_ascii < 48) || (check_ascii > 57) )
  13346. {
  13347. isSuccess = ConfigurationStatus_Rejected;
  13348. }
  13349. else
  13350. {
  13351. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13352. isSuccess = ConfigurationStatus_Accepted;
  13353. }
  13354. }
  13355. else
  13356. {
  13357. isSuccess = ConfigurationStatus_Rejected;
  13358. }
  13359. }
  13360. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13361. {
  13362. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13363. {
  13364. strcpy(str, (const char*)value);
  13365. for(int i = 0; str[i]; i++)
  13366. {
  13367. str[i] = tolower(str[i]);
  13368. }
  13369. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13370. isSuccess = ConfigurationStatus_Accepted;
  13371. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13372. }
  13373. else
  13374. {
  13375. isSuccess = ConfigurationStatus_Rejected;
  13376. }
  13377. }
  13378. if(strcmp(key, "LocalPreAuthorize") == 0)
  13379. {
  13380. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13381. {
  13382. strcpy(str, (const char*)value);
  13383. for(int i = 0; str[i]; i++)
  13384. {
  13385. str[i] = tolower(str[i]);
  13386. }
  13387. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13388. isSuccess = ConfigurationStatus_Accepted;
  13389. }
  13390. else
  13391. {
  13392. isSuccess = ConfigurationStatus_Rejected;
  13393. }
  13394. }
  13395. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13396. {
  13397. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13398. {
  13399. check_ascii = value[0];
  13400. if( (check_ascii < 48) || (check_ascii > 57) )
  13401. {
  13402. isSuccess = ConfigurationStatus_Rejected;
  13403. }
  13404. else
  13405. {
  13406. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13407. isSuccess = ConfigurationStatus_Accepted;
  13408. }
  13409. }
  13410. else
  13411. {
  13412. isSuccess = ConfigurationStatus_Rejected;
  13413. }
  13414. }
  13415. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13416. {
  13417. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13418. {
  13419. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13420. isSuccess = ConfigurationStatus_Accepted;
  13421. }
  13422. else
  13423. {
  13424. isSuccess = ConfigurationStatus_Rejected;
  13425. }
  13426. }
  13427. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13428. {
  13429. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13430. {
  13431. check_ascii = value[0];
  13432. if( (check_ascii < 48) || (check_ascii > 57) )
  13433. {
  13434. isSuccess = ConfigurationStatus_Rejected;
  13435. }
  13436. else
  13437. {
  13438. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13439. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13440. isSuccess = ConfigurationStatus_Accepted;
  13441. }
  13442. }
  13443. else
  13444. {
  13445. isSuccess = ConfigurationStatus_Rejected;
  13446. }
  13447. }
  13448. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13449. {
  13450. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13451. {
  13452. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13453. isSuccess = ConfigurationStatus_Accepted;
  13454. }
  13455. else
  13456. {
  13457. isSuccess = ConfigurationStatus_Rejected;
  13458. }
  13459. }
  13460. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13461. {
  13462. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13463. {
  13464. check_ascii = value[0];
  13465. if( (check_ascii < 48) || (check_ascii > 57) )
  13466. {
  13467. isSuccess = ConfigurationStatus_Rejected;
  13468. }
  13469. else
  13470. {
  13471. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13472. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13473. isSuccess = ConfigurationStatus_Accepted;
  13474. }
  13475. }
  13476. else
  13477. {
  13478. isSuccess = ConfigurationStatus_Rejected;
  13479. }
  13480. }
  13481. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13482. {
  13483. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13484. {
  13485. check_ascii = value[0];
  13486. if( (check_ascii < 48) || (check_ascii > 57) )
  13487. {
  13488. isSuccess = ConfigurationStatus_Rejected;
  13489. }
  13490. else
  13491. {
  13492. if((atoi(value) == 0) || (atoi(value) >= 10))
  13493. {
  13494. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13495. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13496. isSuccess = ConfigurationStatus_Accepted;
  13497. }
  13498. else
  13499. {
  13500. isSuccess = ConfigurationStatus_Rejected;
  13501. }
  13502. }
  13503. }
  13504. else
  13505. {
  13506. isSuccess = ConfigurationStatus_Rejected;
  13507. }
  13508. }
  13509. if(strcmp(key, "MinimumStatusDuration") == 0)
  13510. {
  13511. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13512. {
  13513. check_ascii = value[0];
  13514. if( (check_ascii < 48) || (check_ascii > 57) )
  13515. {
  13516. isSuccess = ConfigurationStatus_Rejected;
  13517. }
  13518. else
  13519. {
  13520. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13521. {
  13522. isSuccess = ConfigurationStatus_Rejected;
  13523. }
  13524. else
  13525. {
  13526. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13527. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13528. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13529. isSuccess = ConfigurationStatus_Accepted;
  13530. }
  13531. }
  13532. }
  13533. else
  13534. {
  13535. isSuccess = ConfigurationStatus_Rejected;
  13536. }
  13537. }
  13538. if(strcmp(key, "NumberOfConnectors") == 0)
  13539. {
  13540. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13541. {
  13542. check_ascii = value[0];
  13543. if( (check_ascii < 48) || (check_ascii > 57) )
  13544. {
  13545. isSuccess = ConfigurationStatus_Rejected;
  13546. }
  13547. else
  13548. {
  13549. //Charger.ResetRetries = Integer.parseInt(value);
  13550. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13551. isSuccess = ConfigurationStatus_Accepted;
  13552. }
  13553. }
  13554. else
  13555. {
  13556. isSuccess = ConfigurationStatus_Rejected;
  13557. }
  13558. }
  13559. if(strcmp(key, "ResetRetries") == 0)
  13560. {
  13561. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13562. {
  13563. check_ascii = value[0];
  13564. if( (check_ascii < 48) || (check_ascii > 57) )
  13565. {
  13566. isSuccess = ConfigurationStatus_Rejected;
  13567. }
  13568. else
  13569. {
  13570. //Charger.ResetRetries = Integer.parseInt(value);
  13571. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13572. isSuccess = ConfigurationStatus_Accepted;
  13573. }
  13574. }
  13575. else
  13576. {
  13577. isSuccess = ConfigurationStatus_Rejected;
  13578. }
  13579. }
  13580. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13581. {
  13582. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13583. {
  13584. strcpy(str, (const char*)value);
  13585. for(int i = 0; str[i]; i++)
  13586. {
  13587. str[i] = tolower(str[i]);
  13588. }
  13589. if(strcmp(str, "notapplicable")== 0)
  13590. {
  13591. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13592. isSuccess = ConfigurationStatus_Accepted;
  13593. }
  13594. else if(strcmp(str, "unknown")== 0)
  13595. {
  13596. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13597. isSuccess = ConfigurationStatus_Accepted;
  13598. }
  13599. else if(strcmp(str, "rst")== 0)
  13600. {
  13601. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13602. isSuccess = ConfigurationStatus_Accepted;
  13603. }
  13604. else if(strcmp(str, "rts")== 0)
  13605. {
  13606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13607. isSuccess = ConfigurationStatus_Accepted;
  13608. }
  13609. else if(strcmp(str, "srt")== 0)
  13610. {
  13611. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13612. isSuccess = ConfigurationStatus_Accepted;
  13613. }
  13614. else if(strcmp(str, "str")== 0)
  13615. {
  13616. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13617. isSuccess = ConfigurationStatus_Accepted;
  13618. }
  13619. else if(strcmp(str, "trs")== 0)
  13620. {
  13621. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13622. isSuccess = ConfigurationStatus_Accepted;
  13623. }
  13624. else if(strcmp(str, "tsr")== 0)
  13625. {
  13626. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13627. isSuccess = ConfigurationStatus_Accepted;
  13628. }
  13629. else
  13630. {
  13631. isSuccess = ConfigurationStatus_Rejected;
  13632. }
  13633. }
  13634. else
  13635. {
  13636. isSuccess = ConfigurationStatus_Rejected;
  13637. }
  13638. }
  13639. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13640. {
  13641. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13642. {
  13643. check_ascii = value[0];
  13644. if( (check_ascii < 48) || (check_ascii > 57) )
  13645. {
  13646. isSuccess = ConfigurationStatus_Rejected;
  13647. }
  13648. else
  13649. {
  13650. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13651. isSuccess = ConfigurationStatus_Accepted;
  13652. }
  13653. }
  13654. else
  13655. {
  13656. isSuccess = ConfigurationStatus_Rejected;
  13657. }
  13658. }
  13659. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13660. {
  13661. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13662. {
  13663. strcpy(str, (const char*)value);
  13664. for(int i = 0; str[i]; i++)
  13665. {
  13666. str[i] = tolower(str[i]);
  13667. }
  13668. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13669. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13670. isSuccess = ConfigurationStatus_Accepted;
  13671. }
  13672. else
  13673. {
  13674. isSuccess = ConfigurationStatus_Rejected;
  13675. }
  13676. }
  13677. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13678. {
  13679. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13680. {
  13681. strcpy(str, (const char*)value);
  13682. for(int i = 0; str[i]; i++)
  13683. {
  13684. str[i] = tolower(str[i]);
  13685. }
  13686. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13687. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13688. isSuccess = ConfigurationStatus_Accepted;
  13689. }
  13690. else
  13691. {
  13692. isSuccess = ConfigurationStatus_Rejected;
  13693. }
  13694. }
  13695. if(strcmp(key, "StopTxnAlignedData") == 0)
  13696. {
  13697. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13698. {
  13699. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13700. isSuccess = ConfigurationStatus_Accepted;
  13701. }
  13702. else
  13703. {
  13704. isSuccess = ConfigurationStatus_Rejected;
  13705. }
  13706. }
  13707. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13708. {
  13709. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13710. {
  13711. check_ascii = value[0];
  13712. if( (check_ascii < 48) || (check_ascii > 57) )
  13713. {
  13714. isSuccess = ConfigurationStatus_Rejected;
  13715. }
  13716. else
  13717. {
  13718. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13719. isSuccess = ConfigurationStatus_Accepted;
  13720. }
  13721. }
  13722. else
  13723. {
  13724. isSuccess = ConfigurationStatus_Rejected;
  13725. }
  13726. }
  13727. if(strcmp(key, "StopTxnSampledData") == 0)
  13728. {
  13729. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13730. {
  13731. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13732. isSuccess = ConfigurationStatus_Accepted;
  13733. }
  13734. else
  13735. {
  13736. isSuccess = ConfigurationStatus_Rejected;
  13737. }
  13738. }
  13739. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13740. {
  13741. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13742. {
  13743. check_ascii = value[0];
  13744. if( (check_ascii < 48) || (check_ascii > 57) )
  13745. {
  13746. isSuccess = ConfigurationStatus_Rejected;
  13747. }
  13748. else
  13749. {
  13750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13751. isSuccess = ConfigurationStatus_Accepted;
  13752. }
  13753. }
  13754. else
  13755. {
  13756. isSuccess = ConfigurationStatus_Rejected;
  13757. }
  13758. }
  13759. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13760. {
  13761. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13762. {
  13763. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13764. isSuccess = ConfigurationStatus_Accepted;
  13765. }
  13766. else
  13767. {
  13768. isSuccess = ConfigurationStatus_Rejected;
  13769. }
  13770. }
  13771. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13772. {
  13773. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13774. {
  13775. check_ascii = value[0];
  13776. if( (check_ascii < 48) || (check_ascii > 57) )
  13777. {
  13778. isSuccess = ConfigurationStatus_Rejected;
  13779. }
  13780. else
  13781. {
  13782. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13783. isSuccess = ConfigurationStatus_Accepted;
  13784. }
  13785. }
  13786. else
  13787. {
  13788. isSuccess = ConfigurationStatus_Rejected;
  13789. }
  13790. }
  13791. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13792. {
  13793. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13794. {
  13795. check_ascii = value[0];
  13796. if( (check_ascii < 48) || (check_ascii > 57) )
  13797. {
  13798. isSuccess = ConfigurationStatus_Rejected;
  13799. }
  13800. else
  13801. {
  13802. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13804. TransactionMessageAttemptsValue = atoi(value);
  13805. isSuccess = ConfigurationStatus_Accepted;
  13806. }
  13807. }
  13808. else
  13809. {
  13810. isSuccess = ConfigurationStatus_Rejected;
  13811. }
  13812. }
  13813. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13814. {
  13815. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13816. {
  13817. check_ascii = value[0];
  13818. if( (check_ascii < 48) || (check_ascii > 57) )
  13819. {
  13820. isSuccess = ConfigurationStatus_Rejected;
  13821. }
  13822. else
  13823. {
  13824. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13825. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13826. TransactionMessageRetryIntervalValue = atoi(value);
  13827. isSuccess = ConfigurationStatus_Accepted;
  13828. }
  13829. }
  13830. else
  13831. {
  13832. isSuccess = ConfigurationStatus_Rejected;
  13833. }
  13834. }
  13835. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13836. {
  13837. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13838. {
  13839. strcpy(str, (const char*)value);
  13840. for(int i = 0; str[i]; i++)
  13841. {
  13842. str[i] = tolower(str[i]);
  13843. }
  13844. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13845. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13846. isSuccess = ConfigurationStatus_Accepted;
  13847. }
  13848. else
  13849. {
  13850. isSuccess = ConfigurationStatus_Rejected;
  13851. }
  13852. }
  13853. if(strcmp(key, "WebSocketPingInterval") == 0)
  13854. {
  13855. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13856. {
  13857. check_ascii = value[0];
  13858. if( (check_ascii < 48) || (check_ascii > 57) )
  13859. {
  13860. isSuccess = ConfigurationStatus_Rejected;
  13861. }
  13862. else
  13863. {
  13864. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13865. isSuccess = ConfigurationStatus_Accepted;
  13866. }
  13867. }
  13868. else
  13869. {
  13870. isSuccess = ConfigurationStatus_Rejected;
  13871. }
  13872. }
  13873. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13874. {
  13875. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13876. {
  13877. strcpy(str, (const char*)value);
  13878. for(int i = 0; str[i]; i++)
  13879. {
  13880. str[i] = tolower(str[i]);
  13881. }
  13882. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13883. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13884. isSuccess = ConfigurationStatus_Accepted;
  13885. }
  13886. else
  13887. {
  13888. isSuccess = ConfigurationStatus_Rejected;
  13889. }
  13890. }
  13891. if(strcmp(key, "AuthorizationKey") == 0)
  13892. {
  13893. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13894. {
  13895. strcpy(str, (const char*)value);
  13896. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13897. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13898. isSuccess = ConfigurationStatus_Accepted;
  13899. }
  13900. else
  13901. {
  13902. isSuccess = ConfigurationStatus_Rejected;
  13903. }
  13904. }
  13905. if(strcmp(key, "SecurityProfile") == 0)
  13906. {
  13907. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13908. {
  13909. check_ascii = value[0];
  13910. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13911. {
  13912. isSuccess = ConfigurationStatus_Rejected;
  13913. }
  13914. else if(check_ascii == 0x33)
  13915. {
  13916. isSuccess = NotSupported;
  13917. }
  13918. else
  13919. {
  13920. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13921. {
  13922. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13923. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13924. isSuccess = ConfigurationStatus_Accepted;
  13925. }
  13926. else
  13927. isSuccess = ConfigurationStatus_Rejected;
  13928. }
  13929. }
  13930. else
  13931. {
  13932. isSuccess = ConfigurationStatus_Rejected;
  13933. }
  13934. }
  13935. if(strcmp(key, "DefaultPrice") == 0)
  13936. {
  13937. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13938. {
  13939. strcpy(str, (const char*)value);
  13940. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13941. isSuccess = ConfigurationStatus_Accepted;
  13942. }
  13943. else
  13944. {
  13945. isSuccess = ConfigurationStatus_Rejected;
  13946. }
  13947. }
  13948. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13949. {
  13950. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13951. {
  13952. strcpy(str, (const char*)value);
  13953. for(int i = 0; str[i]; i++)
  13954. {
  13955. str[i] = tolower(str[i]);
  13956. }
  13957. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13959. isSuccess = ConfigurationStatus_Accepted;
  13960. }
  13961. else
  13962. {
  13963. isSuccess = ConfigurationStatus_Rejected;
  13964. }
  13965. }
  13966. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13967. {
  13968. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  13969. {
  13970. strcpy(str, (const char*)value);
  13971. for(int i = 0; str[i]; i++)
  13972. {
  13973. str[i] = tolower(str[i]);
  13974. }
  13975. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13976. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13977. isSuccess = ConfigurationStatus_Accepted;
  13978. }
  13979. else
  13980. {
  13981. isSuccess = ConfigurationStatus_Rejected;
  13982. }
  13983. }
  13984. #if 0
  13985. //For OCPP Test Case
  13986. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13987. {
  13988. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13989. {
  13990. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13991. isSuccess = ConfigurationStatus_Accepted;
  13992. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13993. }
  13994. else
  13995. {
  13996. isSuccess = ConfigurationStatus_Rejected;
  13997. }
  13998. }
  13999. #endif
  14000. #if 1
  14001. if(strcmp(key, "LocalAuthListEnabled") == 0)
  14002. {
  14003. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  14004. {
  14005. strcpy(str, (const char*)value);
  14006. for(int i = 0; str[i]; i++)
  14007. {
  14008. str[i] = tolower(str[i]);
  14009. }
  14010. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14011. isSuccess = ConfigurationStatus_Accepted;
  14012. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  14013. }
  14014. else
  14015. {
  14016. isSuccess = ConfigurationStatus_Rejected;
  14017. }
  14018. }
  14019. #endif
  14020. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  14021. {
  14022. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  14023. {
  14024. check_ascii = value[0];
  14025. if( (check_ascii < 48) || (check_ascii > 57) )
  14026. {
  14027. isSuccess = ConfigurationStatus_Rejected;
  14028. }
  14029. else
  14030. {
  14031. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  14032. isSuccess = ConfigurationStatus_Accepted;
  14033. }
  14034. }
  14035. else
  14036. {
  14037. isSuccess = ConfigurationStatus_Rejected;
  14038. }
  14039. }
  14040. if(strcmp(key, "SendLocalListMaxLength") == 0)
  14041. {
  14042. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  14043. {
  14044. check_ascii = value[0];
  14045. if( (check_ascii < 48) || (check_ascii > 57) )
  14046. {
  14047. isSuccess = ConfigurationStatus_Rejected;
  14048. }
  14049. else
  14050. {
  14051. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  14052. isSuccess = ConfigurationStatus_Accepted;
  14053. }
  14054. }
  14055. else
  14056. {
  14057. isSuccess = ConfigurationStatus_Rejected;
  14058. }
  14059. }
  14060. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  14061. {
  14062. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  14063. {
  14064. strcpy(str, (const char*)value);
  14065. for(int i = 0; str[i]; i++)
  14066. {
  14067. str[i] = tolower(str[i]);
  14068. }
  14069. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14070. isSuccess = ConfigurationStatus_Accepted;
  14071. }
  14072. else
  14073. {
  14074. isSuccess = ConfigurationStatus_Rejected;
  14075. }
  14076. }
  14077. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  14078. {
  14079. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  14080. {
  14081. check_ascii = value[0];
  14082. if( (check_ascii < 48) || (check_ascii > 57) )
  14083. {
  14084. isSuccess = ConfigurationStatus_Rejected;
  14085. }
  14086. else
  14087. {
  14088. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  14089. isSuccess = ConfigurationStatus_Accepted;
  14090. }
  14091. }
  14092. else
  14093. {
  14094. isSuccess = ConfigurationStatus_Rejected;
  14095. }
  14096. }
  14097. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14098. {
  14099. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14100. {
  14101. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14102. isSuccess = ConfigurationStatus_Accepted;
  14103. }
  14104. else
  14105. {
  14106. isSuccess = ConfigurationStatus_Rejected;
  14107. }
  14108. }
  14109. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14110. {
  14111. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14112. {
  14113. check_ascii = value[0];
  14114. if( (check_ascii < 48) || (check_ascii > 57) )
  14115. {
  14116. isSuccess = ConfigurationStatus_Rejected;
  14117. }
  14118. else
  14119. {
  14120. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14121. isSuccess = ConfigurationStatus_Accepted;
  14122. }
  14123. }
  14124. else
  14125. {
  14126. isSuccess = ConfigurationStatus_Rejected;
  14127. }
  14128. }
  14129. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14130. {
  14131. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14132. {
  14133. strcpy(str, (const char*)value);
  14134. for(int i = 0; str[i]; i++)
  14135. {
  14136. str[i] = tolower(str[i]);
  14137. }
  14138. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14139. isSuccess = ConfigurationStatus_Accepted;
  14140. }
  14141. else
  14142. {
  14143. isSuccess = ConfigurationStatus_Rejected;
  14144. }
  14145. }
  14146. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14147. {
  14148. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14149. {
  14150. check_ascii = value[0];
  14151. if( (check_ascii < 48) || (check_ascii > 57) )
  14152. {
  14153. isSuccess = ConfigurationStatus_Rejected;
  14154. }
  14155. else
  14156. {
  14157. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14158. isSuccess = ConfigurationStatus_Accepted;
  14159. }
  14160. }
  14161. else
  14162. {
  14163. isSuccess = ConfigurationStatus_Rejected;
  14164. }
  14165. }
  14166. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14167. return isSuccess;
  14168. }
  14169. int TransactionMessageAttemptsGet(void)
  14170. {
  14171. return TransactionMessageAttemptsValue;
  14172. }
  14173. int FirstHeartBeatResponse(void)
  14174. {
  14175. return FirstHeartBeat;
  14176. }
  14177. int TransactionMessageRetryIntervalGet(void)
  14178. {
  14179. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14180. }
  14181. int ReadHttpStatus(int sock)
  14182. {
  14183. //char c;
  14184. char buff[1024]="",*ptr=buff+1;
  14185. int bytes_received, status;
  14186. DEBUG_INFO("Begin Response ..\n");
  14187. while((bytes_received = recv(sock, ptr, 1, 0))){
  14188. if(bytes_received==-1){
  14189. perror("ReadHttpStatus");
  14190. exit(1);
  14191. }
  14192. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14193. ptr++;
  14194. }
  14195. *ptr=0;
  14196. ptr=buff+1;
  14197. sscanf(ptr,"%*s %d ", &status);
  14198. DEBUG_INFO("%s\n",ptr);
  14199. DEBUG_INFO("status=%d\n",status);
  14200. DEBUG_INFO("End Response ..\n");
  14201. return (bytes_received>0)?status:0;
  14202. }
  14203. //the only filed that it parsed is 'Content-Length'
  14204. int ParseHeader(int sock)
  14205. {
  14206. //char c;
  14207. char buff[1024]="",*ptr=buff+4;
  14208. int bytes_received;
  14209. DEBUG_INFO("Begin HEADER ..\n");
  14210. while((bytes_received = recv(sock, ptr, 1, 0))){
  14211. if(bytes_received==-1){
  14212. perror("Parse Header");
  14213. exit(1);
  14214. }
  14215. if(
  14216. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14217. (ptr[-1]=='\r') && (*ptr=='\n' )
  14218. ) break;
  14219. ptr++;
  14220. }
  14221. *ptr=0;
  14222. ptr=buff+4;
  14223. //printf("%s",ptr);
  14224. if(bytes_received){
  14225. ptr=strstr(ptr,"Content-Length:");
  14226. if(ptr){
  14227. sscanf(ptr,"%*s %d",&bytes_received);
  14228. }else
  14229. bytes_received=-1; //unknown size
  14230. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14231. }
  14232. DEBUG_INFO("End HEADER ..\n");
  14233. return bytes_received ;
  14234. }
  14235. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14236. {
  14237. int result = TRUE;
  14238. char rmFileCmd[100]={0};
  14239. char FilePath[100]={0};
  14240. char ftpbuf[200];
  14241. int systemresult;
  14242. //DEBUG_INFO("filename=%s\n",filename);
  14243. //DEBUG_INFO("url=%s\n",url);
  14244. sprintf(FilePath,"/mnt/%s",filename);
  14245. system("ping 8.8.8.8 &");
  14246. if((access(FilePath,F_OK))!=-1)
  14247. {
  14248. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14249. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14250. system(rmFileCmd);
  14251. }
  14252. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14253. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14254. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14255. systemresult = system(ftpbuf);
  14256. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14257. if(systemresult != 0)
  14258. {
  14259. DEBUG_INFO("http DownLoad error!\n");
  14260. result = FALSE;
  14261. }
  14262. system("pkill ping");
  14263. return result;
  14264. }
  14265. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14266. {
  14267. int result = TRUE;
  14268. char rmFileCmd[100]={0};
  14269. char FilePath[100]={0};
  14270. char ftpbuf[200];
  14271. int systemresult;
  14272. //char temp[100];
  14273. sprintf(FilePath,"/mnt/%s",filename);
  14274. system("ping 8.8.8.8 &");
  14275. if((access(FilePath,F_OK))!=-1)
  14276. {
  14277. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14278. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14279. system(rmFileCmd);
  14280. }
  14281. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14282. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14283. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14284. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14285. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14286. systemresult = system(ftpbuf);
  14287. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14288. if(systemresult != 0)
  14289. {
  14290. printf("wget error!\n");
  14291. result = FALSE;
  14292. }
  14293. system("pkill ping");
  14294. return result;
  14295. }
  14296. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14297. {
  14298. char rmFileCmd[100]={0};
  14299. char FilePath[100]={0};
  14300. char buf[512];
  14301. int systemresult = 0;
  14302. //DEBUG_INFO("filename=%s\n",filename);
  14303. //DEBUG_INFO("url=%s\n",url);
  14304. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14305. if((access(FilePath,F_OK))!=-1)
  14306. {
  14307. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14308. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14309. system(rmFileCmd);
  14310. }
  14311. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14312. if(fp == NULL)
  14313. {
  14314. DEBUG_INFO("log is NULL\n");
  14315. return FALSE;
  14316. }
  14317. else
  14318. {
  14319. fprintf(fp, "%s\n", url);
  14320. fprintf(fp, "%s\n", filename);
  14321. fclose(fp);
  14322. }
  14323. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14324. if(phpFP == NULL)
  14325. {
  14326. DEBUG_INFO("PHP upload fail.\n");
  14327. return FALSE;
  14328. }
  14329. else
  14330. {
  14331. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14332. {
  14333. if(strstr(buf, "result") != NULL)
  14334. {
  14335. sscanf(buf, "result: %d", &systemresult);
  14336. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14337. }
  14338. }
  14339. pclose(phpFP);
  14340. }
  14341. if(systemresult != 1)
  14342. {
  14343. DEBUG_INFO("HTTP upload error!\n");
  14344. return FALSE;
  14345. }
  14346. return TRUE;
  14347. }
  14348. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14349. {
  14350. struct hostent* server;
  14351. char *IPbuffer;
  14352. char ftpbuf[200];
  14353. int systemresult;
  14354. // To retrieve host information
  14355. server = gethostbyname(location);
  14356. // To convert an Internet network
  14357. // address into ASCII string
  14358. IPbuffer = inet_ntoa(*((struct in_addr*)
  14359. server->h_addr_list[0]));
  14360. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14361. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14362. /* format : ftpput -u username -p passwd IP target source*/
  14363. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14364. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14365. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14366. systemresult = system(ftpbuf);
  14367. DEBUG_INFO("systemresult=%d\n",systemresult);
  14368. if(systemresult != 0)
  14369. {
  14370. DEBUG_INFO("ftpput error!\n");
  14371. return FALSE;
  14372. }
  14373. return TRUE;
  14374. }
  14375. int GetOcppServerURL()
  14376. {
  14377. int result = FALSE;
  14378. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14379. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14380. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14381. struct yuarel url;
  14382. char urlStr[512];
  14383. // OCPPPH only
  14384. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  14385. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14386. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  14387. {
  14388. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  14389. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14390. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14391. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  14392. if(yuarel_parse(&url, urlStr) != -1)
  14393. {
  14394. sprintf(OcppProtocol, "%s", url.scheme);
  14395. sprintf(OcppHost, "%s", url.host);
  14396. if(url.path == NULL)
  14397. OcppTempPath[0] = '\0';
  14398. else
  14399. sprintf(OcppTempPath, "%s", url.path);
  14400. if(url.port == 0)
  14401. {
  14402. if(strcmp(OcppProtocol, "wss") == 0)
  14403. OcppPort = 443;
  14404. else
  14405. OcppPort = 80;
  14406. }
  14407. else
  14408. OcppPort = url.port;
  14409. result = TRUE;
  14410. }
  14411. }
  14412. else
  14413. {
  14414. strcpy(OcppHost,"");
  14415. }
  14416. return result;
  14417. }
  14418. int GetOcppPath()
  14419. {
  14420. int result = FALSE;
  14421. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  14422. {
  14423. if(OcppTempPath == NULL)
  14424. {
  14425. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  14426. }
  14427. else
  14428. {
  14429. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  14430. }
  14431. result = TRUE;
  14432. goto End;
  14433. }
  14434. else
  14435. {
  14436. strcpy(OcppPath,"");
  14437. }
  14438. End:
  14439. return result;
  14440. }
  14441. int GetOcppPort()
  14442. {
  14443. return OcppPort;
  14444. }
  14445. int GetOcppConnStatus(void)
  14446. {
  14447. return ShmOCPP16DataPH->OcppConnStatus;
  14448. }
  14449. void SetOcppConnStatus(uint8_t status)
  14450. {
  14451. ShmOCPP16DataPH->OcppConnStatus = status;
  14452. }
  14453. int GetHeartBeatWithNOResponse(void)
  14454. {
  14455. return HeartBeatWithNOResponse;
  14456. }
  14457. void SetHeartBeatWithNOResponse(void)
  14458. {
  14459. HeartBeatWithNOResponse = 0;
  14460. }
  14461. void GetStartTransactionIdTag(int gun_index)
  14462. {
  14463. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14464. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14465. }
  14466. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14467. {
  14468. char ch;
  14469. FILE *fptr1;
  14470. int temptransactionId;
  14471. char str[100]={0};
  14472. temptransactionId = 0;
  14473. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14474. {
  14475. DEBUG_INFO("IdTag is empty.\n");
  14476. return temptransactionId;
  14477. }
  14478. /*------ Read the file ----------------*/
  14479. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  14480. if (!fptr1)
  14481. {
  14482. DEBUG_INFO("QueueTransactionId file open error.\n");
  14483. //printf(" File not found or unable to open the input file!!\n");
  14484. return temptransactionId;
  14485. }
  14486. ch=fgetc(fptr1);
  14487. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  14488. rewind(fptr1);
  14489. if(ch!=EOF)
  14490. {
  14491. // printf("%c",ch);
  14492. while (fgets(str, 100, fptr1) != NULL)
  14493. {
  14494. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14495. if(str[0]=='\0')
  14496. {
  14497. break;
  14498. }
  14499. char *revbuf[8] = {0}; // Variable store string split
  14500. int num = 0;// Quantity after string split
  14501. DEBUG_INFO("Transaction queue data= %s\n", str);
  14502. splitstring(str,",",revbuf,&num); // String split
  14503. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14504. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14505. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14506. DEBUG_INFO("------------------------------\n");
  14507. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14508. {
  14509. if(isStopTransaction)
  14510. {
  14511. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14512. {
  14513. temptransactionId = atoi(revbuf[2]);
  14514. //break;
  14515. }
  14516. }
  14517. else
  14518. {
  14519. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14520. {
  14521. temptransactionId = atoi(revbuf[2]);
  14522. //break;
  14523. }
  14524. }
  14525. }
  14526. }
  14527. }
  14528. else
  14529. DEBUG_INFO("EOF\n");
  14530. fclose(fptr1);
  14531. /*------- End of reading ---------------*/
  14532. return temptransactionId;
  14533. }
  14534. void SetTransactionIdZero(int transactionId)
  14535. {
  14536. char ch;
  14537. FILE *fptr1, *fptr2;
  14538. int temptransactionId = 0;
  14539. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  14540. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  14541. if (!fptr1)
  14542. {
  14543. //printf(" File not found or unable to open the input file!!\n");
  14544. return ;
  14545. }
  14546. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14547. if (!fptr2)
  14548. {
  14549. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14550. fclose(fptr1);
  14551. return ;
  14552. }
  14553. ch=fgetc(fptr1);
  14554. rewind(fptr1);
  14555. if(ch!=EOF)
  14556. {
  14557. // copy all contents to the temporary file except the specific line
  14558. while (fgets(str, 100, fptr1) != NULL)
  14559. {
  14560. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14561. if(str[0]=='\0')
  14562. {
  14563. break;
  14564. }
  14565. char *revbuf[8] = {0};
  14566. int num = 0;
  14567. strcpy(strtemp, str);
  14568. splitstring(str,",",revbuf,&num);
  14569. if(revbuf[2][0] != '\0')
  14570. {
  14571. temptransactionId = atoi(revbuf[2]);
  14572. if(transactionId != temptransactionId)
  14573. {
  14574. fprintf(fptr2, "%s\n", strtemp);
  14575. }
  14576. }
  14577. }
  14578. }
  14579. fclose(fptr1);
  14580. fclose(fptr2);
  14581. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  14582. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  14583. /*------ Read the file ----------------*/
  14584. }
  14585. int InternetDisconnect(void)
  14586. {
  14587. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14588. }
  14589. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14590. void storeTempStopTransaction(int gun_index)
  14591. {
  14592. char guid[37]={0};
  14593. int tempIndex = 0;
  14594. char TempStopTransaction[256];
  14595. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  14596. DEBUG_INFO("storeTempStopTransaction...\n");
  14597. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14598. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  14599. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14600. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14601. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14602. {
  14603. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14604. {
  14605. tempIndex = ((gun_index==2) ? 1: 0);
  14606. }
  14607. else
  14608. {
  14609. tempIndex = gun_index;
  14610. }
  14611. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14612. {
  14613. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14614. {
  14615. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14616. }
  14617. }// END OF CHAdeMO_QUANTITY
  14618. }
  14619. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14620. {
  14621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14622. {
  14623. tempIndex = ((gun_index==2) ? 1: 0);
  14624. }
  14625. else
  14626. {
  14627. tempIndex = gun_index;
  14628. }
  14629. for (int index = 0; index < CCS_QUANTITY; index++)
  14630. {
  14631. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14632. {
  14633. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14634. }
  14635. }// END OF CCS_QUANTITY
  14636. }
  14637. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14638. {
  14639. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14640. {
  14641. tempIndex = ((gun_index==2) ? 1: 0);
  14642. }
  14643. else
  14644. {
  14645. tempIndex = gun_index;
  14646. }
  14647. for (int index = 0; index < GB_QUANTITY; index++)
  14648. {
  14649. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14650. {
  14651. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14652. }
  14653. }// END OF GB_QUANTITY
  14654. }
  14655. else if(gunType[gun_index] == GUN_TYPE_DO)
  14656. {
  14657. tempIndex = gun_index;
  14658. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14659. {
  14660. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14661. {
  14662. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14663. }
  14664. }
  14665. }
  14666. else
  14667. {
  14668. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14669. {
  14670. tempIndex = 2;
  14671. }
  14672. else
  14673. {
  14674. tempIndex = gun_index;
  14675. }
  14676. for (int index = 0; index < AC_QUANTITY; index++)
  14677. {
  14678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14679. {
  14680. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14681. }
  14682. }// END OF AC_QUANTITY
  14683. }
  14684. //Stop Transaction Time
  14685. struct timeval tmnow;
  14686. struct tm *tm;
  14687. char buf[28];//, usec_buf[6];
  14688. gettimeofday(&tmnow, NULL);
  14689. time_t t;
  14690. t = time(NULL);
  14691. /*UTC time and date*/
  14692. tm = gmtime(&t);
  14693. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14694. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  14695. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  14696. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14697. random_uuid(guid);
  14698. /***********************************transactionData******************************************************/
  14699. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14700. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14701. //=================================
  14702. //1. Transaction_Begin
  14703. //=================================
  14704. //============================== Energy.Active.Import.Interval ===========================================
  14705. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14706. {
  14707. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14708. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14709. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14710. 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*/]);
  14711. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14712. 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))
  14713. {
  14714. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14715. }
  14716. else
  14717. {
  14718. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14719. }
  14720. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14721. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14722. }
  14723. //=================================
  14724. //2. Transaction_End
  14725. //=================================
  14726. //2.1====================================== Current.Import L1 ==============================================
  14727. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14728. {
  14729. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14730. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14731. {
  14732. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14733. {
  14734. tempIndex = ((gun_index==2) ? 1: 0);
  14735. }
  14736. else
  14737. {
  14738. tempIndex = gun_index;
  14739. }
  14740. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14741. {
  14742. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14743. {
  14744. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14745. }
  14746. }// End of for CHAdeMO_QUANTITY
  14747. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14748. }
  14749. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14750. {
  14751. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14752. {
  14753. tempIndex = ((gun_index==2) ? 1: 0);
  14754. }
  14755. else
  14756. {
  14757. tempIndex = gun_index;
  14758. }
  14759. for (int index = 0; index < CCS_QUANTITY; index++)
  14760. {
  14761. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14762. {
  14763. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14764. }
  14765. }// End of for CCS_QUANTITY
  14766. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14767. }
  14768. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14769. {
  14770. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14771. {
  14772. tempIndex = ((gun_index==2) ? 1: 0);
  14773. }
  14774. else
  14775. {
  14776. tempIndex = gun_index;
  14777. }
  14778. for (int index = 0; index < GB_QUANTITY; index++)
  14779. {
  14780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14781. {
  14782. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14783. }
  14784. }// End of for GB_QUANTITY
  14785. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14786. }
  14787. else if(gunType[gun_index] == GUN_TYPE_DO)
  14788. {
  14789. tempIndex = gun_index;
  14790. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14791. {
  14792. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14793. {
  14794. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14795. }
  14796. }
  14797. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14798. }
  14799. else
  14800. {
  14801. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14802. {
  14803. tempIndex = 2;
  14804. }
  14805. else
  14806. {
  14807. tempIndex = gun_index;
  14808. }
  14809. for (int index = 0; index < AC_QUANTITY; index++)
  14810. {
  14811. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14812. {
  14813. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14814. }
  14815. }// End of for AC_QUANTITY
  14816. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14817. }
  14818. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14819. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14820. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14821. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14822. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14823. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14824. }
  14825. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14826. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14827. {
  14828. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14829. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14830. {
  14831. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14832. {
  14833. tempIndex = ((gun_index==2) ? 1: 0);
  14834. }
  14835. else
  14836. {
  14837. tempIndex = gun_index;
  14838. }
  14839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14840. {
  14841. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14842. {
  14843. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14844. }
  14845. }// END OF CHAdeMO_QUANTITY
  14846. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14847. }
  14848. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14849. {
  14850. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14851. {
  14852. tempIndex = ((gun_index==2) ? 1: 0);
  14853. }
  14854. else
  14855. {
  14856. tempIndex = gun_index;
  14857. }
  14858. for (int index = 0; index < CCS_QUANTITY; index++)
  14859. {
  14860. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14861. {
  14862. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14863. }
  14864. }// END OF CCS_QUANTITY
  14865. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14866. }
  14867. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14868. {
  14869. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14870. {
  14871. tempIndex = ((gun_index==2) ? 1: 0);
  14872. }
  14873. else
  14874. {
  14875. tempIndex = gun_index;
  14876. }
  14877. for (int index = 0; index < GB_QUANTITY; index++)
  14878. {
  14879. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14880. {
  14881. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14882. }
  14883. }// END OF GB_QUANTITY
  14884. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14885. }
  14886. else if(gunType[gun_index] == GUN_TYPE_DO)
  14887. {
  14888. tempIndex = gun_index;
  14889. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14890. {
  14891. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14892. {
  14893. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14894. }
  14895. }
  14896. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14897. }
  14898. else
  14899. {
  14900. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14901. {
  14902. tempIndex = 2;
  14903. }
  14904. else
  14905. {
  14906. tempIndex = gun_index;
  14907. }
  14908. for (int index = 0; index < AC_QUANTITY; index++)
  14909. {
  14910. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14911. {
  14912. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14913. }
  14914. }// END OF AC_QUANTITY
  14915. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14916. }
  14917. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14918. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14919. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14920. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14922. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14923. }
  14924. //2.3====================================== Power.Active.Import =========================================
  14925. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14926. {
  14927. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14928. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14929. {
  14930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14931. {
  14932. tempIndex = ((gun_index==2) ? 1: 0);
  14933. }
  14934. else
  14935. {
  14936. tempIndex = gun_index;
  14937. }
  14938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14939. {
  14940. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14941. {
  14942. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14943. }
  14944. } // End for CHAdeMO_QUANTITY
  14945. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14946. }
  14947. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14948. {
  14949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14950. {
  14951. tempIndex = ((gun_index==2) ? 1: 0);
  14952. }
  14953. else
  14954. {
  14955. tempIndex = gun_index;
  14956. }
  14957. for (int index = 0; index < CCS_QUANTITY; index++)
  14958. {
  14959. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14960. {
  14961. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14962. }
  14963. } // END for CCS_QUANTITY
  14964. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14965. }
  14966. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14967. {
  14968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14969. {
  14970. tempIndex = ((gun_index==2) ? 1: 0);
  14971. }
  14972. else
  14973. {
  14974. tempIndex = gun_index;
  14975. }
  14976. for (int index = 0; index < GB_QUANTITY; index++)
  14977. {
  14978. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14979. {
  14980. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14981. }
  14982. }// END for GB_QUANTITY
  14983. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14984. }
  14985. else if(gunType[gun_index] == GUN_TYPE_DO)
  14986. {
  14987. tempIndex = gun_index;
  14988. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14989. {
  14990. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14991. {
  14992. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14993. }
  14994. }
  14995. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14996. }
  14997. else
  14998. {
  14999. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15000. {
  15001. tempIndex = 2;
  15002. }
  15003. else
  15004. {
  15005. tempIndex = gun_index;
  15006. }
  15007. for (int index = 0; index < AC_QUANTITY; index++)
  15008. {
  15009. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15010. {
  15011. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15012. }
  15013. } // END for AC_QUANTITY
  15014. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15015. }
  15016. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15017. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15018. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15019. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15020. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15021. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15022. }
  15023. //2.4====================================== Voltage L1 ====================================================
  15024. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15025. {
  15026. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15027. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15028. {
  15029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15030. {
  15031. tempIndex = ((gun_index==2) ? 1: 0);
  15032. }
  15033. else
  15034. {
  15035. tempIndex = gun_index;
  15036. }
  15037. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15038. {
  15039. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15040. {
  15041. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15042. }
  15043. } // END OF FOR CHAdeMO_QUANTITY
  15044. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15045. }
  15046. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15047. {
  15048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15049. {
  15050. tempIndex = ((gun_index==2) ? 1: 0);
  15051. }
  15052. else
  15053. {
  15054. tempIndex = gun_index;
  15055. }
  15056. for (int index = 0; index < CCS_QUANTITY; index++)
  15057. {
  15058. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15059. {
  15060. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15061. }
  15062. } // END OF FOR CCS_QUANTITY
  15063. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15064. }
  15065. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15066. {
  15067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15068. {
  15069. tempIndex = ((gun_index==2) ? 1: 0);
  15070. }
  15071. else
  15072. {
  15073. tempIndex = gun_index;
  15074. }
  15075. for (int index = 0; index < GB_QUANTITY; index++)
  15076. {
  15077. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15078. {
  15079. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15080. }
  15081. } // END OF FOR GB_QUANTITY
  15082. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15083. }
  15084. else if(gunType[gun_index] == GUN_TYPE_DO)
  15085. {
  15086. tempIndex = gun_index;
  15087. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15088. {
  15089. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15090. {
  15091. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15092. }
  15093. }
  15094. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15095. }
  15096. else
  15097. {
  15098. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15099. {
  15100. tempIndex = 2;
  15101. }
  15102. else
  15103. {
  15104. tempIndex = gun_index;
  15105. }
  15106. for (int index = 0; index < AC_QUANTITY; index++)
  15107. {
  15108. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15109. {
  15110. 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
  15111. }
  15112. } // END OF FOR AC_QUANTITY
  15113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15114. }
  15115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15118. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15121. }
  15122. //2.5============================================== End SoC =========================================================
  15123. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15124. {
  15125. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15126. 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))
  15127. {
  15128. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15129. {
  15130. tempIndex = ((gun_index==2) ? 1: 0);
  15131. }
  15132. else
  15133. {
  15134. tempIndex = gun_index;
  15135. }
  15136. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15137. {
  15138. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15139. {
  15140. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15141. {
  15142. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15143. }
  15144. }
  15145. }
  15146. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15147. {
  15148. for (int index = 0; index < CCS_QUANTITY; index++)
  15149. {
  15150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15151. {
  15152. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15153. }
  15154. }
  15155. }
  15156. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15157. {
  15158. for (int index = 0; index < GB_QUANTITY; index++)
  15159. {
  15160. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15161. {
  15162. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15163. }
  15164. }
  15165. }
  15166. else if(gunType[gun_index] == GUN_TYPE_DO)
  15167. {
  15168. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15169. {
  15170. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15171. {
  15172. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15173. }
  15174. }
  15175. }
  15176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15177. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15178. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15179. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15180. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15181. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15182. } // END FOR DC CASE
  15183. }
  15184. //2.6====================================== Current.Import L2 ==============================================
  15185. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15186. {
  15187. // AC 3 phase L2 current
  15188. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15189. {
  15190. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15191. {
  15192. tempIndex = 2;
  15193. }
  15194. else
  15195. {
  15196. tempIndex = gun_index;
  15197. }
  15198. for (int index = 0; index < AC_QUANTITY; index++)
  15199. {
  15200. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15201. {
  15202. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15203. }
  15204. }// End of for AC_QUANTITY
  15205. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15206. }
  15207. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15208. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15209. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15210. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15211. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15212. }
  15213. //2.7====================================== Current.Import L3 ==============================================
  15214. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15215. {
  15216. // AC 3 phase L3 current
  15217. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15218. {
  15219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15220. {
  15221. tempIndex = 2;
  15222. }
  15223. else
  15224. {
  15225. tempIndex = gun_index;
  15226. }
  15227. for (int index = 0; index < AC_QUANTITY; index++)
  15228. {
  15229. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15230. {
  15231. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15232. }
  15233. }// End of for AC_QUANTITY
  15234. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15235. }
  15236. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15237. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15238. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15239. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15240. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15241. }
  15242. //2.9====================================== Voltage L2 ====================================================
  15243. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15244. {
  15245. // AC 3 phase L2 volatge
  15246. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15247. {
  15248. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15249. {
  15250. tempIndex = 2;
  15251. }
  15252. else
  15253. {
  15254. tempIndex = gun_index;
  15255. }
  15256. for (int index = 0; index < AC_QUANTITY; index++)
  15257. {
  15258. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15259. {
  15260. 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
  15261. }
  15262. } // END OF FOR AC_QUANTITY
  15263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15264. }
  15265. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15267. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15268. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15269. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15270. }
  15271. //2.10====================================== Voltage L3 ====================================================
  15272. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15273. {
  15274. // AC 3 phase L3 volatge
  15275. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15276. {
  15277. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15278. {
  15279. tempIndex = 2;
  15280. }
  15281. else
  15282. {
  15283. tempIndex = gun_index;
  15284. }
  15285. for (int index = 0; index < AC_QUANTITY; index++)
  15286. {
  15287. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15288. {
  15289. 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
  15290. }
  15291. } // END OF FOR AC_QUANTITY
  15292. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15293. }
  15294. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15295. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15296. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15297. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15298. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15299. }
  15300. //====================== Start SoC ================================
  15301. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15302. {
  15303. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15304. 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))
  15305. {
  15306. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15307. {
  15308. tempIndex = ((gun_index==2) ? 1: 0);
  15309. }
  15310. else
  15311. {
  15312. tempIndex = gun_index;
  15313. }
  15314. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15315. {
  15316. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15317. {
  15318. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15319. {
  15320. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15321. }
  15322. }
  15323. }
  15324. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15325. {
  15326. for (int index = 0; index < CCS_QUANTITY; index++)
  15327. {
  15328. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15329. {
  15330. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15331. }
  15332. }
  15333. }
  15334. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15335. {
  15336. for (int index = 0; index < GB_QUANTITY; index++)
  15337. {
  15338. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15339. {
  15340. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15341. }
  15342. }
  15343. }
  15344. else if(gunType[gun_index] == GUN_TYPE_DO)
  15345. {
  15346. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15347. {
  15348. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15349. {
  15350. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15351. }
  15352. }
  15353. }
  15354. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15355. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15356. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15357. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15358. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15359. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15360. } // END FOR DC CASE
  15361. }
  15362. //======================================== Message create ==============================================
  15363. json_object *StopTransaction = json_object_new_object();
  15364. json_object *transactionDatas = json_object_new_array();
  15365. json_object *sampledValues = json_object_new_array();
  15366. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  15367. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  15368. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  15369. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  15370. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  15371. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15372. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  15373. {
  15374. json_object *transactionData = json_object_new_object();
  15375. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15376. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15377. {
  15378. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15379. {
  15380. json_object *sampledValue = json_object_new_object();
  15381. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15382. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15383. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15384. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15385. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15386. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15387. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15388. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15389. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15390. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15391. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15392. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15393. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15394. json_object_array_add(sampledValues, sampledValue);
  15395. }
  15396. }
  15397. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15398. json_object_array_add(transactionDatas, transactionData);
  15399. }
  15400. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15401. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15402. ,MESSAGE_TYPE_CALL
  15403. ,guid
  15404. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15405. json_object_put(StopTransaction);
  15406. // Check File "TempStopTransaction" Exist
  15407. if((access(TempStopTransaction,F_OK))!=-1)
  15408. {
  15409. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15410. fclose(fopen(TempStopTransaction, "w"));
  15411. }
  15412. else
  15413. {
  15414. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15415. FILE *log = fopen(TempStopTransaction, "w+");
  15416. if(log == NULL)
  15417. {
  15418. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15419. return ;
  15420. }
  15421. else
  15422. {
  15423. fclose(log);
  15424. }
  15425. }
  15426. //Add TempStopTransaction | Update TempStopTransaction
  15427. // open file for writing
  15428. FILE *outfile;
  15429. outfile = fopen (TempStopTransaction, "a");
  15430. //DEBUG_INFO("data = %s\n", queuedata);
  15431. fputs(queuedata, outfile);
  15432. fputs("\n", outfile);
  15433. fclose (outfile);
  15434. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15435. }
  15436. void checkTempStopTransaction(int gun_index)
  15437. {
  15438. FILE *fptr1;
  15439. char ch;
  15440. char str[QUEUE_MESSAGE_LENGTH]={0};
  15441. char guid[37]={0};
  15442. char tempdata[65]={0};
  15443. char connectorStr[2]={0};
  15444. char TempStopTransaction[256];
  15445. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15446. fptr1 = fopen(TempStopTransaction, "r");
  15447. //TempStopTransaction格式: 槍號,StopTransaction封包
  15448. if (!fptr1)
  15449. {
  15450. //printf(" File not found or unable to open the input file!!\n");
  15451. return ;
  15452. }
  15453. ch=fgetc(fptr1);
  15454. //printf(" Now the content of the file %s is : \n",fname);
  15455. rewind(fptr1);
  15456. if(ch!=EOF)
  15457. {
  15458. // copy all contents to the temporary file except the specific line
  15459. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15460. {
  15461. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15462. if(str[0]=='\0')
  15463. {
  15464. break;
  15465. }
  15466. //TempStopTransaction格式: 槍號,StopTransaction封包
  15467. strncpy(connectorStr, str, 1);
  15468. if(atoi(connectorStr) != (gun_index+1))
  15469. {
  15470. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15471. fclose(fptr1);
  15472. return ;
  15473. }
  15474. //random_uuid(guid);
  15475. strncpy(guid, str+6, 36); //copy guid
  15476. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15477. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15478. {
  15479. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15480. }
  15481. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15482. OCPP_insert_transaction_msg(NO, str);
  15483. memset(str,0,ARRAY_SIZE(str));
  15484. }
  15485. }
  15486. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15487. fclose(fptr1);
  15488. remove(TempStopTransaction); // remove the original file
  15489. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15490. }
  15491. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15492. {
  15493. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15494. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15495. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15496. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15497. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15498. }
  15499. int GetWebSocketPingInterval(void)
  15500. {
  15501. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15502. }
  15503. int GetServerSign(void)
  15504. {
  15505. return server_sign;
  15506. }
  15507. uint8_t GetOcppSecurityProfile()
  15508. {
  15509. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15510. }
  15511. void GetOcppChargerBoxId(uint8_t *data)
  15512. {
  15513. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  15514. }
  15515. void GetOcppSecurityPassword(uint8_t *data)
  15516. {
  15517. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15518. }
  15519. void SetOcppVersion(uint8_t *version)
  15520. {
  15521. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15522. DEBUG_INFO("ocpp version: %s\n", version);
  15523. if(strstr((char*)version, "ocpp1.6") != NULL)
  15524. {
  15525. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15526. }
  15527. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15528. {
  15529. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15530. system("pkill OcppBackend");
  15531. }
  15532. }
  15533. void SetServerSign(int value)
  15534. {
  15535. server_sign = value;
  15536. }
  15537. int GetBootNotificationInterval(void)
  15538. {
  15539. return BootNotificationInterval;
  15540. }
  15541. int GetInternetConn(void)
  15542. {
  15543. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15544. }
  15545. int GetBackendConnectionTimeout(void)
  15546. {
  15547. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15548. }
  15549. int isConnectorInitMode(int gun_index)
  15550. {
  15551. int tempIndex = 0;
  15552. int result = TRUE;
  15553. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15554. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15555. {
  15556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15557. {
  15558. tempIndex = ((gun_index==2) ? 1: 0);
  15559. }
  15560. else
  15561. {
  15562. tempIndex = gun_index;
  15563. }
  15564. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15565. {
  15566. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15567. {
  15568. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15569. } //end of the same index
  15570. }//end of for CHAdeMO_QUANTITY
  15571. }
  15572. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15573. {
  15574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15575. {
  15576. tempIndex = ((gun_index==2) ? 1: 0);
  15577. }
  15578. else
  15579. {
  15580. tempIndex = gun_index;
  15581. }
  15582. for (int index = 0; index < CCS_QUANTITY; index++)
  15583. {
  15584. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15585. {
  15586. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15587. } //end of the same index
  15588. } // end of for CCS_QUANTITY
  15589. }
  15590. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15591. {
  15592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15593. {
  15594. tempIndex = ((gun_index==2) ? 1: 0);
  15595. }
  15596. else
  15597. {
  15598. tempIndex = gun_index;
  15599. }
  15600. for (int index = 0; index < GB_QUANTITY; index++)
  15601. {
  15602. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15603. {
  15604. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15605. } //end of the same index
  15606. } // end of for GB_QUANTITY
  15607. }
  15608. else if(gunType[gun_index] == GUN_TYPE_DO)
  15609. {
  15610. tempIndex = gun_index;
  15611. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15612. {
  15613. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15614. {
  15615. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15616. } //end of the same index
  15617. }
  15618. }
  15619. else
  15620. {
  15621. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15622. {
  15623. tempIndex = 2;
  15624. }
  15625. else
  15626. {
  15627. tempIndex = gun_index;
  15628. }
  15629. for (int index = 0; index < AC_QUANTITY; index++)
  15630. {
  15631. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15632. {
  15633. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15634. }//end of the same index
  15635. }//end of for AC_QUANTITY
  15636. }
  15637. return result;
  15638. }
  15639. void refreshProcDogTimer()
  15640. {
  15641. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  15642. }
  15643. void InitialSystemValue(void)
  15644. {
  15645. int connectorIndex = 0;
  15646. //int valueASCII = 0;
  15647. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15648. gunTotalNumber=0;
  15649. SystemInitial = 0;
  15650. localversion=0;
  15651. BootNotificationInterval = 0;
  15652. authorizeRetryTimes = 0;
  15653. GunStatusInterval = 10;
  15654. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15655. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15656. //Hear Beat
  15657. HeartBeatWithNOResponse = 0;
  15658. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15659. FirstHeartBeat = 0;
  15660. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15661. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15662. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15663. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15664. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15665. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15666. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15667. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15668. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15669. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15670. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15671. memset(gunType, 0, ARRAY_SIZE(gunType));
  15672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15673. {
  15674. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15675. {
  15676. // DO series
  15677. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15678. {
  15679. SystemInitial = SystemInitial + 1;
  15680. gunTotalNumber = gunTotalNumber + 1;
  15681. gunType[connectorIndex] = GUN_TYPE_DO;
  15682. connectorIndex = connectorIndex + 1;
  15683. }
  15684. }
  15685. else
  15686. {
  15687. // DM, DW, DS series
  15688. //check connector / socket type (index: 8, 9, 10)
  15689. for(int index=7; index <10 ; index++)
  15690. {
  15691. if(index != 8)
  15692. {
  15693. // DC Connector
  15694. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15695. {
  15696. SystemInitial = SystemInitial + 1;
  15697. gunTotalNumber = gunTotalNumber + 1;
  15698. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15699. connectorIndex = connectorIndex + 1;
  15700. }
  15701. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15702. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15703. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15704. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15705. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15706. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15707. {
  15708. SystemInitial = SystemInitial + 1;
  15709. gunTotalNumber = gunTotalNumber + 1;
  15710. gunType[connectorIndex] = GUN_TYPE_CCS;
  15711. connectorIndex = connectorIndex + 1;
  15712. }
  15713. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15714. {
  15715. SystemInitial = SystemInitial + 1;
  15716. gunTotalNumber = gunTotalNumber + 1;
  15717. gunType[connectorIndex] = GUN_TYPE_GBT;
  15718. connectorIndex = connectorIndex + 1;
  15719. }
  15720. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15721. {
  15722. SystemInitial = SystemInitial + 1;
  15723. gunTotalNumber = gunTotalNumber + 1;
  15724. gunType[connectorIndex] = GUN_TYPE_DO;
  15725. connectorIndex = connectorIndex + 1;
  15726. }
  15727. }
  15728. else
  15729. {
  15730. // AC Connector
  15731. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15732. {
  15733. SystemInitial = SystemInitial + 1;
  15734. gunTotalNumber = gunTotalNumber + 1;
  15735. gunType[connectorIndex] = GUN_TYPE_AC;
  15736. connectorIndex = connectorIndex + 1;
  15737. }
  15738. }
  15739. }
  15740. }
  15741. //DEBUG_INFO("DC ...\n");
  15742. }
  15743. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15744. {
  15745. //check connector / socket type (index: 8, 9, 10)
  15746. for(int index=7; index <10 ; index++)
  15747. {
  15748. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15749. {
  15750. SystemInitial = SystemInitial + 1;
  15751. gunTotalNumber = gunTotalNumber + 1;
  15752. gunType[connectorIndex] = GUN_TYPE_AC;
  15753. connectorIndex = connectorIndex + 1;
  15754. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15755. }
  15756. }
  15757. }
  15758. //Status && ConnectorPlugIn Setting
  15759. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15760. {
  15761. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15762. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15763. }
  15764. for (int index = 0; index < CCS_QUANTITY; index++)
  15765. {
  15766. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15767. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15768. }
  15769. for (int index = 0; index < GB_QUANTITY; index++)
  15770. {
  15771. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15772. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15773. }
  15774. for (int index = 0; index < AC_QUANTITY; index++)
  15775. {
  15776. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15777. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15778. }
  15779. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15780. {
  15781. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15782. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15783. }
  15784. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15785. {
  15786. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15787. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15788. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15789. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15790. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15791. }
  15792. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15793. clientTime.Heartbeat=time((time_t*)NULL);
  15794. sleep(1);
  15795. }
  15796. void LWS_Send(char *str)
  15797. {
  15798. //=====================================================
  15799. // Check InternetConn 0: disconnected, 1: connected
  15800. //====================================================
  15801. if(GetOcppConnStatus() == 0)
  15802. {
  15803. DEBUG_INFO("offline now !!!\n");
  15804. return;
  15805. }
  15806. // Only disable isWebsocketSendable operation initiated by charger
  15807. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15808. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15809. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15810. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15811. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15812. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15813. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15814. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15815. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15816. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15817. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15818. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15819. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15820. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15821. {
  15822. isWebsocketSendable = 0;
  15823. }
  15824. pthread_mutex_lock(&lock_send);
  15825. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15826. sprintf((char *)SendBuffer, "%s", str);
  15827. SendBufLen = strlen(str);
  15828. pthread_mutex_unlock(&lock_send);
  15829. lws_callback_on_writable(wsi_client);
  15830. //lws_service(context, 0);
  15831. //sleep(1);
  15832. }
  15833. void LWS_SendNow(char *str)
  15834. {
  15835. //=====================================================
  15836. // Check InternetConn 0: disconnected, 1: connected
  15837. //====================================================
  15838. if(GetOcppConnStatus() == 0)
  15839. {
  15840. DEBUG_INFO("offline now !!!\n");
  15841. return;
  15842. }
  15843. // Only disable isWebsocketSendable operation initiated by charger
  15844. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15845. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15846. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15847. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15848. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15849. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15850. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15851. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15852. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15853. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15854. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15855. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15856. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15857. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15858. {
  15859. isWebsocketSendable = 0;
  15860. }
  15861. pthread_mutex_lock(&lock_send);
  15862. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15863. sprintf((char *)SendBuffer, "%s", str);
  15864. SendBufLen = strlen(str);
  15865. pthread_mutex_unlock(&lock_send);
  15866. lws_callback_on_writable(wsi_client);
  15867. lws_service(context, 0);
  15868. //sleep(1);
  15869. }