MessageHandler.c 782 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP_PH/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP_PH/TxDefaultProfile_0.json"
  7. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. struct OCPP16Data *ShmOCPP16DataPH;
  12. //ConfigurationMaxKeys
  13. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  14. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  15. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  16. //=================================
  17. // StatusNotification cycle
  18. //=================================
  19. static int server_cycle_Status = 120;
  20. //===============================
  21. // Configuration: unknown key
  22. //===============================
  23. static char unknownkey[10][36] = {0};
  24. static int UnknownKeynum = 0;
  25. //===============================
  26. // Gun Total Numbers
  27. //===============================
  28. static int gunTotalNumber = 0;
  29. static uint8_t gunType[4] = {0};
  30. //===============================
  31. // Local List Version
  32. //===============================
  33. static int locallistVersion=0;
  34. static char idTagAuthorization[32] = {0};
  35. //===============================
  36. // OCPP sign variable
  37. //===============================
  38. static int server_sign = FALSE;
  39. int server_pending = FALSE;
  40. static int BootNotificationInterval = 0;
  41. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  42. //===============================
  43. // OCPP auth variable
  44. //===============================
  45. static int authorizeRetryTimes = 0; //number of Retry times
  46. //===============================
  47. // OCPP other variables
  48. //===============================
  49. static int HeartBeatWaitTime = 10;
  50. static int FirstHeartBeat = 0;
  51. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  52. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  53. static char CurrentChargingProfileScheduleStr[30] = {0};
  54. //========================================
  55. // OCPP status/previous related variables
  56. //========================================
  57. static int GunStatusInterval = 10;
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[21];
  75. char parentIdTag[21];
  76. char expiryDate[36];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char TriggerStatusNotificationReq:1; //bit 3,
  116. unsigned char isOnCharging:1; //bit 4.
  117. unsigned char :3; //bit 5~7
  118. }bits[CONNECTOR_QUANTITY];
  119. }CpinitiateMsg;
  120. CpinitiateMsg cpinitateMsg;
  121. //GetConfiguration Array
  122. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  123. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  124. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  125. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  126. #if 0
  127. static char *ChargePointErrorCodeStr[] = {
  128. MACROSTR(ConnectorLockFailure),
  129. MACROSTR(EVCommunicationError),
  130. MACROSTR(GroundFailure),
  131. MACROSTR(HighTemperature),
  132. MACROSTR(InternalError),
  133. MACROSTR(LocalListConflict),
  134. MACROSTR(NoError),
  135. MACROSTR(OtherError),
  136. MACROSTR(OverCurrentFailure),
  137. MACROSTR(OverVoltage),
  138. MACROSTR(PowerMeterFailure),
  139. MACROSTR(PowerSwitchFailure),
  140. MACROSTR(ReaderFailure),
  141. MACROSTR(ResetFailure),
  142. MACROSTR(UnderVoltage),
  143. MACROSTR(WeakSignal)
  144. };
  145. #endif
  146. static char * ChargePointStatusStr[] = {
  147. MACROSTR(Available),
  148. MACROSTR(Preparing),
  149. MACROSTR(Charging),
  150. MACROSTR(SuspendedEVSE),
  151. MACROSTR(SuspendedEV),
  152. MACROSTR(Finishing),
  153. MACROSTR(Reserved),
  154. MACROSTR(Unavailable),
  155. MACROSTR(Faulted)
  156. };
  157. static char *RegistrationStatusStr[] = {
  158. MACROSTR(Accepted),
  159. MACROSTR(Pending),
  160. MACROSTR(Rejected)
  161. };
  162. static char *AvailabilityTypeStr[] = {
  163. MACROSTR(Inoperative),
  164. MACROSTR(Operative)
  165. };
  166. static char *AvailabilityStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Rejected),
  169. MACROSTR(Scheduled)
  170. };
  171. static char *ConfigurationStatusStr[] = {
  172. MACROSTR(Accepted),
  173. MACROSTR(Rejected),
  174. MACROSTR(RebootRequired),
  175. MACROSTR(NotSupported)
  176. };
  177. static char *ClearCacheStatusStr[] = {
  178. MACROSTR(Accepted),
  179. MACROSTR(Rejected)
  180. };
  181. static char *ChargingProfilePurposeTypeStr[] = {
  182. MACROSTR(ChargePointMaxProfile),
  183. MACROSTR(TxDefaultProfile),
  184. MACROSTR(TxProfile)
  185. };
  186. static char *ChargingProfileStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected),
  189. MACROSTR(NotSupported)
  190. };
  191. static char *ClearChargingProfileStatusStr[] = {
  192. MACROSTR(Accepted),
  193. MACROSTR(Unknown)
  194. };
  195. static char *GetCompositeScheduleStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected)
  198. };
  199. static char *UpdateTypeStr[] = {
  200. MACROSTR(Differential),
  201. MACROSTR(Full)
  202. };
  203. static char *UpdateStatusStr[] = {
  204. MACROSTR(Accepted),
  205. MACROSTR(Failed),
  206. MACROSTR(NotSupported),
  207. MACROSTR(VersionMismatch)
  208. };
  209. static char *RemoteStartStopStatusStr[] = {
  210. MACROSTR(Accepted),
  211. MACROSTR(Rejected)
  212. };
  213. static char *ReservationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Faulted),
  216. MACROSTR(Occupied),
  217. MACROSTR(Rejected),
  218. MACROSTR(Unavailable)
  219. };
  220. static char *ResetTypeStr[] = {
  221. MACROSTR(Hard),
  222. MACROSTR(Soft)
  223. };
  224. static char *ResetStatusStr[] = {
  225. MACROSTR(Accepted),
  226. MACROSTR(Rejected)
  227. };
  228. static char * DiagnosticsStatusStr[] = {
  229. MACROSTR(Idle),
  230. MACROSTR(Uploaded),
  231. MACROSTR(UploadFailed),
  232. MACROSTR(Uploading)
  233. };
  234. static char * FirmwareStatusStr[] = {
  235. MACROSTR(Downloaded),
  236. MACROSTR(DownloadFailed),
  237. MACROSTR(Downloading),
  238. MACROSTR(Idle),
  239. MACROSTR(InstallationFailed),
  240. MACROSTR(Installing),
  241. MACROSTR(Installed)
  242. };
  243. static char * MessageTriggerStr[] = {
  244. MACROSTR(BootNotification),
  245. MACROSTR(DiagnosticsStatusNotification),
  246. MACROSTR(FirmwareStatusNotification),
  247. MACROSTR(Heartbeat),
  248. MACROSTR(MeterValues),
  249. MACROSTR(StatusNotification)
  250. };
  251. static char * TriggerMessageStatusStr[] = {
  252. MACROSTR(Accepted),
  253. MACROSTR(Rejected),
  254. MACROSTR(NotImplemented)
  255. };
  256. static char * UnlockStatusStr[] = {
  257. MACROSTR(Unlocked),
  258. MACROSTR(UnlockFailed),
  259. MACROSTR(NotSupported)
  260. };
  261. #if 0
  262. static char * StopTransactionReasonStr[] = {
  263. MACROSTR(EmergencyStop),
  264. MACROSTR(EVDisconnected),
  265. MACROSTR(HardReset),
  266. MACROSTR(Local),
  267. MACROSTR(Other),
  268. MACROSTR(PowerLoss),
  269. MACROSTR(Reboot),
  270. MACROSTR(Remote),
  271. MACROSTR(SoftReset),
  272. MACROSTR(UnlockCommand),
  273. MACROSTR(DeAuthorized)
  274. };
  275. #endif
  276. static char * CancelReservationStatusStr[] = {
  277. MACROSTR(Accepted),
  278. MACROSTR(Rejected)
  279. };
  280. static char * ReadingContextStr[] = {
  281. MACROSTR(Interruption.Begin),
  282. MACROSTR(Interruption.End),
  283. MACROSTR(Other),
  284. MACROSTR(Sample.Clock),
  285. MACROSTR(Sample.Periodic),
  286. MACROSTR(Transaction.Begin),
  287. MACROSTR(Transaction.End),
  288. MACROSTR(Trigger)
  289. };
  290. static char * ValueFormatStr[] = {
  291. MACROSTR(Raw),
  292. MACROSTR(SignedData)
  293. };
  294. static char * MeasurandStr[] = {
  295. MACROSTR(Current.Export),
  296. MACROSTR(Current.Import),
  297. MACROSTR(Current.Offered),
  298. MACROSTR(Energy.Active.Export.Register),
  299. MACROSTR(Energy.Active.Import.Register),
  300. MACROSTR(Energy.Reactive.Export.Register),
  301. MACROSTR(Energy.Reactive.Import.Register),
  302. MACROSTR(Energy.Active.Export.Interval),
  303. MACROSTR(Energy.Active.Import.Interval),
  304. MACROSTR(Energy.Reactive.Export.Interval),
  305. MACROSTR(Energy.Reactive.Import.Interval),
  306. MACROSTR(Frequency),
  307. MACROSTR(Power.Active.Export),
  308. MACROSTR(Power.Active.Import),
  309. MACROSTR(Power.Factor),
  310. MACROSTR(Power.Offered),
  311. MACROSTR(Power.Reactive.ExportMACROSTR),
  312. MACROSTR(Power.Reactive.Import),
  313. MACROSTR(RPM),
  314. MACROSTR(SoC),
  315. MACROSTR(Temperature),
  316. MACROSTR(Voltage)
  317. };
  318. static char * LocationStr[] = {
  319. MACROSTR(Body),
  320. MACROSTR(Cable),
  321. MACROSTR(EV),
  322. MACROSTR(Inlet),
  323. MACROSTR(Outlet)
  324. };
  325. static char * PhaseStr[] = {
  326. MACROSTR(L1),
  327. MACROSTR(L2),
  328. MACROSTR(L3),
  329. MACROSTR(N),
  330. MACROSTR(L1-N),
  331. MACROSTR(L2-N),
  332. MACROSTR(L3-N),
  333. MACROSTR(L1-L2),
  334. MACROSTR(L2-L3),
  335. MACROSTR(L3-L1)
  336. };
  337. static char * UnitOfMeasureStr[] = {
  338. MACROSTR(Wh),
  339. MACROSTR(kWh),
  340. MACROSTR(varh),
  341. MACROSTR(kvarh),
  342. MACROSTR(W),
  343. MACROSTR(kW),
  344. MACROSTR(VA),
  345. MACROSTR(kVA),
  346. MACROSTR(var),
  347. MACROSTR(kvar),
  348. MACROSTR(A),
  349. MACROSTR(V),
  350. MACROSTR(Celsius),
  351. MACROSTR(Fahrenheit),
  352. MACROSTR(K),
  353. MACROSTR(Percent)
  354. };
  355. //=========================================
  356. // Save configuration
  357. //=========================================
  358. int runShellCmd(const char*cmd)
  359. {
  360. int result = FAIL;
  361. char buf[256];
  362. FILE *fp;
  363. fp = popen(cmd, "r");
  364. if(fp != NULL)
  365. {
  366. while(fgets(buf, sizeof(buf), fp) != NULL)
  367. {
  368. DEBUG_INFO("%s\n", buf);
  369. }
  370. result = PASS;
  371. }
  372. pclose(fp);
  373. return result;
  374. }
  375. int StoreUsrConfigData(struct SysConfigData *UsrData)
  376. {
  377. int result = PASS;
  378. int fd,wrd;
  379. unsigned int i,Chk;
  380. unsigned char *ptr, *BufTmp;
  381. int MtdBlockSize = 0x300000;
  382. Chk=0;
  383. ptr=(unsigned char *)UsrData;
  384. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  385. {
  386. memset(BufTmp,0,MtdBlockSize);
  387. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  388. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  389. Chk+=*(BufTmp+i);
  390. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  391. // Output configuration to file.
  392. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  393. if (fd < 0)
  394. {
  395. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  396. free(BufTmp);
  397. return 0;
  398. }
  399. wrd=write(fd, BufTmp, MtdBlockSize);
  400. close(fd);
  401. if(wrd<MtdBlockSize)
  402. {
  403. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  404. free(BufTmp);
  405. return 0;
  406. }
  407. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  408. DEBUG_INFO("Erase /dev/mtd10.\n");
  409. runShellCmd("flash_erase /dev/mtd10 0 0");
  410. DEBUG_INFO("Write /dev/mtd10.\n");
  411. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  412. DEBUG_INFO("Erase /dev/mtd11.\n");
  413. runShellCmd("flash_erase /dev/mtd11 0 0");
  414. DEBUG_INFO("Write /dev/mtd11.\n");
  415. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  416. system("rm -f /mnt/EvseConfig.bin");
  417. DEBUG_INFO("EvseConfig write to flash OK\n");
  418. }
  419. else
  420. {
  421. DEBUG_ERROR("alloc BlockSize NG\r\n");
  422. result = FAIL;
  423. }
  424. if(BufTmp!=NULL)
  425. free(BufTmp);
  426. return result;
  427. }
  428. //=========================================
  429. // Sqlite3 related function
  430. //=========================================
  431. static int selectSqlCount = 0;
  432. static int callback(void *data, int argc, char **argv, char **azColName){
  433. int i;
  434. //printf("%s: ", (const char*)data);
  435. selectSqlCount = argc;
  436. for(i = 0; i<argc; i++){
  437. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  438. }
  439. //printf("\n");
  440. return 0;
  441. }
  442. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  443. //int i;
  444. //printf("%s:\n", (const char*)data);
  445. locallistVersion = (argv[5] ? atoi(argv[5]) : 0);
  446. DEBUG_INFO("Callback query locallistVersion : %d\n", locallistVersion);
  447. return 0;
  448. }
  449. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  450. //printf("%s:\n", (const char*)data);
  451. //idTag
  452. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  453. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  454. //parentIdTag
  455. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  456. //expir_date
  457. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  458. //status
  459. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  460. //version
  461. if(columenCount > 5)
  462. idTagQuery.listVersionInt = atoi(columnValue[5]);
  463. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  464. return 0;
  465. }
  466. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  467. {
  468. // localversion = argv[5] ? atoi(argv[5]) : 0;
  469. // printf("localversion=%d\n", localversion);
  470. return 0;
  471. }
  472. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  473. {
  474. for (int i = 0; i < n_columns; i++)
  475. {
  476. DEBUG_INFO("%s\t", col_values[i]);
  477. }
  478. DEBUG_INFO("\n");
  479. return 0;
  480. }
  481. int OCPP_cleanLocalCache()
  482. {
  483. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  484. char *errMsg = 0;
  485. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  486. if (SQLITE_OK != rc)
  487. {
  488. DEBUG_INFO("SQL error: %s\n",errMsg);
  489. return FALSE;
  490. }
  491. return TRUE;
  492. }
  493. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  494. {
  495. int isSuccess = TRUE;
  496. int ret = 0;
  497. //const char* data = "Callback function called";
  498. char sql[300];
  499. char zErrMsg[200];
  500. memset(sql, 0, 300);
  501. memset(zErrMsg, 0, 200);
  502. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  503. //* Execute SQL statement */
  504. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  505. if( ret != SQLITE_OK )
  506. {
  507. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  508. isSuccess = FALSE;
  509. }
  510. return isSuccess;
  511. }
  512. void OCPP_getIdTagFromLocalCache(char idTag[])
  513. {
  514. int rc = 0;
  515. char sql[100];
  516. char zErrMsg[100];
  517. memset(sql, 0, 100);
  518. memset(zErrMsg, 0, 100);
  519. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  520. memset(&idTagQuery, 0, sizeof(idTagQuery));
  521. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  522. /* Execute SQL statement */
  523. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  524. if( rc != SQLITE_OK )
  525. {
  526. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  527. }
  528. }
  529. void OCPP_getListVerion()
  530. {
  531. int rc = 0;
  532. // const char* data = "Callback function called";
  533. char sql[100];
  534. char zErrMsg[100];
  535. memset(sql, 0, 100);
  536. memset(zErrMsg, 0, 100);
  537. strcpy(sql, "select * from ocpp_auth_local order by idx");
  538. /* Execute SQL statement */
  539. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  540. if( rc != SQLITE_OK )
  541. {
  542. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  543. }
  544. }
  545. void OCPP_get_TableAuthlocalAllData(void)
  546. {
  547. int rc = 0;
  548. char sql[100];
  549. char zErrMsg[100];
  550. memset(sql, 0, 100);
  551. memset(zErrMsg, 0, 100);
  552. sprintf(sql,"select * from ocpp_auth_local ");
  553. /* Execute SQL statement */
  554. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  555. if( rc != SQLITE_OK )
  556. {
  557. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  558. }
  559. //return ver;
  560. }
  561. int OCPP_cleanLocalList()
  562. {
  563. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  564. char *errMsg = 0;
  565. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  566. if (SQLITE_OK != rc)
  567. {
  568. DEBUG_INFO("%s\n",errMsg);
  569. return FALSE;
  570. }
  571. return TRUE;
  572. }
  573. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  574. {
  575. int isSuccess = FALSE;
  576. int ret = 0;
  577. //const char* data = "Callback function called";
  578. char sql[300];
  579. char zErrMsg[200];
  580. memset(sql, 0, 300);
  581. memset(zErrMsg, 0, 200);
  582. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  583. //* Execute SQL statement */
  584. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  585. if( ret != SQLITE_OK )
  586. {
  587. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  588. return isSuccess;
  589. }
  590. memset(sql, 0, 300);
  591. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  592. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  593. if( ret != SQLITE_OK )
  594. {
  595. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  596. return isSuccess;
  597. }
  598. isSuccess = TRUE;
  599. return isSuccess;
  600. }
  601. void OCPP_getIdTagFromLocalList(char idTag[])
  602. {
  603. int rc = 0;
  604. // const char* data = "Callback function called";
  605. char sql[100];
  606. char zErrMsg[100];
  607. memset(sql, 0, 100);
  608. memset(zErrMsg, 0, 100);
  609. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  610. memset(&idTagQuery, 0, sizeof(idTagQuery));
  611. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  612. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  613. /* Execute SQL statement */
  614. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  615. if( rc != SQLITE_OK )
  616. {
  617. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  618. }
  619. //return ver;
  620. }
  621. void OCPP_deleteIdTagFromLocalList(char idTag[])
  622. {
  623. //int ver = 0;
  624. //int isSuccess = FALSE;
  625. int rc = 0;
  626. char sql[100];
  627. char zErrMsg[100];
  628. memset(sql, 0, 100);
  629. memset(zErrMsg, 0, 100);
  630. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  631. //* Execute SQL statement */
  632. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  633. if( rc != SQLITE_OK )
  634. {
  635. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  636. }
  637. }
  638. int getCurrentYear()
  639. {
  640. int result = 0;
  641. time_t CurrentTime;
  642. struct tm *tm;
  643. CurrentTime = time(NULL);
  644. tm=localtime(&CurrentTime);
  645. result = (tm->tm_year + 1900);
  646. return result;
  647. }
  648. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  649. {
  650. int result = PASS;
  651. char* errMsg = NULL;
  652. char sqlStr[8192];
  653. sprintf(sqlStr, "insert into ocpp_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  654. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  655. {
  656. result = FAIL;
  657. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  658. }
  659. sprintf(sqlStr, "delete from ocpp_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  660. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  661. {
  662. result = FAIL;
  663. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  664. }
  665. return result;
  666. }
  667. //==========================================
  668. // Check time passed since today
  669. //==========================================
  670. long long DiffTimebWithNow(struct timeb ST)
  671. {
  672. //return milli-second
  673. struct timeb ET;
  674. long long StartTime,StopTime;
  675. ftime(&ET);
  676. StartTime=(long long)ST.time;
  677. StopTime=(long long)ET.time;
  678. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  679. }
  680. int getTimePassSinceToday(uint8_t gun_index)
  681. {
  682. int result = -1;
  683. static time_t lastTime[4];
  684. time_t t;
  685. struct tm *tmStartToday;
  686. struct timeb tbStartToday;
  687. t=time(NULL);
  688. if(difftime(t, lastTime[gun_index])>0)
  689. {
  690. tmStartToday=localtime(&t);
  691. tmStartToday->tm_hour = 0;
  692. tmStartToday->tm_min = 0;
  693. tmStartToday->tm_sec = 0;
  694. tbStartToday.time = mktime(tmStartToday);
  695. tbStartToday.millitm = 0;
  696. result = DiffTimebWithNow(tbStartToday)/1000;
  697. lastTime[gun_index] = t;
  698. }
  699. return result;
  700. }
  701. void getNowDatetime(uint8_t *data)
  702. {
  703. time_t t = time(NULL);
  704. struct tm tm = *localtime(&t);
  705. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  706. }
  707. int syncDateTimeRTC(uint8_t *data)
  708. {
  709. struct ParsingResult
  710. {
  711. int result;
  712. int scanedElement;
  713. int year;
  714. int month;
  715. int mday;
  716. int hour;
  717. int min;
  718. int sec;
  719. int tz_hour;
  720. int tz_min;
  721. float minSec;
  722. }result;
  723. struct tm tmOrg;
  724. struct tm *tmTarget;
  725. struct timeb tbTarget;
  726. char buf[128];
  727. memset(&result, 0x00, sizeof(struct ParsingResult));
  728. result.result = PASS;
  729. if(strstr((char*)data, ".") != NULL)
  730. {
  731. // Original data with mini second
  732. if(strstr((char*)data, "Z") != NULL)
  733. {
  734. // Original data with Z
  735. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  736. &result.year,
  737. &result.month,
  738. &result.mday,
  739. &result.hour,
  740. &result.min,
  741. &result.sec,
  742. &result.minSec);
  743. }
  744. else
  745. {
  746. // Original data without Z
  747. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  748. &result.year,
  749. &result.month,
  750. &result.mday,
  751. &result.hour,
  752. &result.min,
  753. &result.sec,
  754. &result.minSec,
  755. &result.tz_hour,
  756. &result.tz_min);
  757. }
  758. }
  759. else
  760. {
  761. // Original data without mini second
  762. if(strstr((char*)data, "Z") != NULL)
  763. {
  764. // Original data with Z
  765. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  766. &result.year,
  767. &result.month,
  768. &result.mday,
  769. &result.hour,
  770. &result.min,
  771. &result.sec);
  772. }
  773. else
  774. {
  775. // Original data without Z
  776. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  777. &result.year,
  778. &result.month,
  779. &result.mday,
  780. &result.hour,
  781. &result.min,
  782. &result.sec,
  783. &result.tz_hour,
  784. &result.tz_min);
  785. }
  786. }
  787. tmOrg.tm_year = result.year - 1900;
  788. tmOrg.tm_mon = result.month - 1;
  789. tmOrg.tm_mday = result.mday;
  790. tmOrg.tm_hour = result.hour;
  791. tmOrg.tm_min = result.min;
  792. tmOrg.tm_sec = result.sec;
  793. tmOrg.tm_gmtoff = 0;
  794. tbTarget.time = mktime(&tmOrg);
  795. tbTarget.timezone = 0;
  796. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  797. tmTarget = gmtime(&tbTarget.time);
  798. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  799. //DEBUG_INFO(" org date time: %s\n", data);
  800. //DEBUG_INFO("parse date time: %s\n", buf);
  801. system(buf);
  802. system("/sbin/hwclock -w --systohc");
  803. if(result.scanedElement < 6)
  804. result.result = FAIL;
  805. return result.result;
  806. }
  807. //==========================================
  808. // GetCompositeSchedule logic related function
  809. //==========================================
  810. int DiffTimebSec(struct timeb ST, struct timeb ET)
  811. {
  812. //return milli-second
  813. unsigned int StartTime,StopTime;
  814. StartTime=(unsigned int)ST.time;
  815. StopTime=(unsigned int)ET.time;
  816. return (StopTime-StartTime);
  817. }
  818. int DiffTimebWithNowSec(struct timeb ST)
  819. {
  820. //return milli-second
  821. struct timeb ET;
  822. unsigned int StartTime,StopTime;
  823. ftime(&ET);
  824. StartTime=(unsigned int)ST.time;
  825. StopTime=(unsigned int)ET.time;
  826. return (StopTime-StartTime);
  827. }
  828. int getStartStop(uint8_t *start, uint8_t *stop)
  829. {
  830. int result = -1;
  831. struct tm tmStart;
  832. struct timeb tbStart;
  833. struct tm tmStop;
  834. struct timeb tbStop;
  835. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  836. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  837. {
  838. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  839. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  840. tmStart.tm_year -= 1900;
  841. tmStart.tm_mon -= 1;
  842. tbStart.time = mktime(&tmStart);
  843. tbStart.millitm = 0;
  844. tmStop.tm_year -= 1900;
  845. tmStop.tm_mon -= 1;
  846. tbStop.time = mktime(&tmStop);
  847. tbStop.millitm = 0;
  848. result = DiffTimebSec(tbStart, tbStop);
  849. //DEBUG_INFO("getStartStop(): %d\n", result);
  850. }
  851. else
  852. {
  853. DEBUG_WARN("Start or stop date parsing error.\r\n");
  854. }
  855. return result;
  856. }
  857. int isOvertNow(uint8_t *start)
  858. {
  859. int result = NO;
  860. struct tm tmStart;
  861. struct timeb tbStart;
  862. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  863. {
  864. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  865. tmStart.tm_year -= 1900;
  866. tmStart.tm_mon -= 1;
  867. tbStart.time = mktime(&tmStart);
  868. tbStart.millitm = 0;
  869. if(DiffTimebWithNowSec(tbStart) <= 0)
  870. result = NO;
  871. else
  872. result = YES;
  873. }
  874. else
  875. {
  876. DEBUG_WARN("Start date parsing error.\n");
  877. }
  878. return result;
  879. }
  880. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  881. {
  882. int result = -1;
  883. struct tm tmStart;
  884. struct timeb tbStart;
  885. struct tm tmStop;
  886. struct timeb tbStop;
  887. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  888. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  889. {
  890. tmStart.tm_year -= 1900;
  891. tmStart.tm_mon -= 1;
  892. tbStart.time = mktime(&tmStart);
  893. tbStart.millitm = 0;
  894. tmStop.tm_year -= 1900;
  895. tmStop.tm_mon -= 1;
  896. tbStop.time = mktime(&tmStop);
  897. tbStop.millitm = 0;
  898. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  899. }
  900. return result;
  901. }
  902. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile, uint8_t isUnitA)
  903. {
  904. FILE *fp;
  905. char profileFileName[128];
  906. char *line = NULL;
  907. size_t len = 0;
  908. time_t CurrentTime;
  909. struct tm *tmComposite;
  910. struct StructChargingProfile maxProfile;
  911. struct StructChargingProfile defaultTxProfile;
  912. struct StructChargingProfile txProfile;
  913. struct StructChargingSchedulePeriod tmpPeriod;
  914. uint8_t limitMax=0;
  915. uint8_t limitDef=0;
  916. uint8_t limitTx=0;
  917. int compositePeriodIdx = 0;
  918. CurrentTime = time(NULL);
  919. tmComposite=localtime(&CurrentTime);
  920. 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);
  921. if(isUnitA)
  922. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  923. else
  924. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "W");
  925. compositeProfile->ChargingSchedule.Duration = durationReq;
  926. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  927. {
  928. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  929. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  930. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  931. }
  932. compositeProfile->ChargingProfileId = 0;
  933. compositeProfile->StackLevel = 99 ;
  934. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  935. maxProfile.ChargingProfileId = -1;
  936. defaultTxProfile.ChargingProfileId = -1;
  937. txProfile.ChargingProfileId = -1;
  938. maxProfile.ChargingSchedule.Duration = -1;
  939. defaultTxProfile.ChargingSchedule.Duration = -1;
  940. txProfile.ChargingSchedule.Duration = -1;
  941. system("rm -f /tmp/*.json");
  942. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  943. /*
  944. * Search valid charging profile
  945. */
  946. //DEBUG_INFO("====================================\n");
  947. // Search tx profile
  948. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  949. if((access(profileFileName, F_OK))!=-1)
  950. {
  951. fp = fopen(profileFileName, "r");
  952. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  953. {
  954. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  955. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  956. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  957. }
  958. txProfile.ChargingProfileId = -1;
  959. txProfile.StackLevel = -1;
  960. while(getline(&line, &len, fp) != -1)
  961. {
  962. json_object *obj = NULL;
  963. obj = json_tokener_parse(line);
  964. if(is_error(obj))
  965. {
  966. DEBUG_ERROR("Parse txProfile from file error.\n");
  967. }
  968. else
  969. {
  970. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  971. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  972. )
  973. {
  974. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  975. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  976. )
  977. {
  978. struct tm tmFrom, tmTo;
  979. struct timeb tbFrom, tbTo;
  980. 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) &&
  981. (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))
  982. {
  983. tmFrom.tm_year -= 1900;
  984. tmFrom.tm_mon -= 1;
  985. tbFrom.time = mktime(&tmFrom);
  986. tmTo.tm_year -= 1900;
  987. tmTo.tm_mon -= 1;
  988. tbTo.time = mktime(&tmTo);
  989. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  990. {
  991. if(txProfile.ChargingProfileId == -1)
  992. DEBUG_INFO("TxProfile found.\n");
  993. else
  994. DEBUG_INFO("TxProfile updated.\n");
  995. // Required item
  996. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  997. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  998. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  999. if(isUnitA)
  1000. {
  1001. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1002. 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++)
  1003. {
  1004. 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"));
  1005. 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?
  1006. 3:
  1007. 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")));
  1008. 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")));
  1009. }
  1010. }
  1011. else
  1012. {
  1013. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1014. 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++)
  1015. {
  1016. 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"));
  1017. 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?
  1018. 3:
  1019. 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")));
  1020. 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));
  1021. }
  1022. }
  1023. // Optional item
  1024. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1025. {
  1026. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1027. }
  1028. else
  1029. {
  1030. sprintf((char*)txProfile.ValidFrom, " ");
  1031. }
  1032. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1033. {
  1034. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1035. }
  1036. else
  1037. {
  1038. sprintf((char*)txProfile.ValidTo, " ");
  1039. }
  1040. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1041. {
  1042. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1043. }
  1044. else
  1045. {
  1046. sprintf((char*)txProfile.RecurrencyKind, " ");
  1047. }
  1048. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1049. {
  1050. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1051. }
  1052. else
  1053. {
  1054. txProfile.TransactionId = -1;
  1055. }
  1056. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1057. {
  1058. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1059. }
  1060. else
  1061. {
  1062. txProfile.ChargingSchedule.Duration = 86400;
  1063. }
  1064. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1065. {
  1066. 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")));
  1067. }
  1068. else
  1069. {
  1070. 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));
  1071. }
  1072. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1073. {
  1074. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1075. }
  1076. else
  1077. {
  1078. txProfile.ChargingSchedule.MinChargingRate = -1;
  1079. }
  1080. }
  1081. }
  1082. }
  1083. else
  1084. {
  1085. if(txProfile.ChargingProfileId == -1)
  1086. DEBUG_INFO("TxProfile found.\n");
  1087. else
  1088. DEBUG_INFO("TxProfile updated.\n");
  1089. // Required item
  1090. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1091. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1092. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1093. if(isUnitA)
  1094. {
  1095. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1096. 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++)
  1097. {
  1098. 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"));
  1099. 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?
  1100. 3:
  1101. 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")));
  1102. 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")));
  1103. }
  1104. }
  1105. else
  1106. {
  1107. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "W");
  1108. 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++)
  1109. {
  1110. 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"));
  1111. 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?
  1112. 3:
  1113. 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")));
  1114. 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));
  1115. }
  1116. }
  1117. // Optional item
  1118. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1119. {
  1120. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1121. }
  1122. else
  1123. {
  1124. sprintf((char*)txProfile.ValidFrom, " ");
  1125. }
  1126. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1127. {
  1128. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1129. }
  1130. else
  1131. {
  1132. sprintf((char*)txProfile.ValidTo, " ");
  1133. }
  1134. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1135. {
  1136. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1137. }
  1138. else
  1139. {
  1140. sprintf((char*)txProfile.RecurrencyKind, " ");
  1141. }
  1142. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1143. {
  1144. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1145. }
  1146. else
  1147. {
  1148. txProfile.TransactionId = -1;
  1149. }
  1150. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1151. {
  1152. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1153. }
  1154. else
  1155. {
  1156. txProfile.ChargingSchedule.Duration = 86400;
  1157. }
  1158. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1159. {
  1160. 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")));
  1161. }
  1162. else
  1163. {
  1164. 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));
  1165. }
  1166. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1167. {
  1168. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1169. }
  1170. else
  1171. {
  1172. txProfile.ChargingSchedule.MinChargingRate = -1;
  1173. }
  1174. }
  1175. }
  1176. }
  1177. json_object_put(obj);
  1178. }
  1179. fclose(fp);
  1180. /*
  1181. if(txProfile.ChargingProfileId != -1)
  1182. {
  1183. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1184. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1185. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1186. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1187. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1188. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1189. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1190. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1191. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1192. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1193. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1194. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1195. {
  1196. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1197. {
  1198. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1199. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1200. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1201. }
  1202. }
  1203. }
  1204. else
  1205. DEBUG_INFO("TxProfile not found.\n");*/
  1206. }
  1207. // Search default tx profile
  1208. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1209. if((access(profileFileName, F_OK))==-1)
  1210. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1211. if((access(profileFileName, F_OK))!=-1)
  1212. {
  1213. fp = fopen(profileFileName, "r");
  1214. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1215. {
  1216. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1217. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1218. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1219. }
  1220. defaultTxProfile.ChargingProfileId = -1;
  1221. defaultTxProfile.StackLevel = -1;
  1222. while(getline(&line, &len, fp) != -1)
  1223. {
  1224. json_object *obj = NULL;
  1225. obj = json_tokener_parse(line);
  1226. if(is_error(obj))
  1227. {
  1228. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1229. }
  1230. else
  1231. {
  1232. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1233. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1234. )
  1235. {
  1236. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1237. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1238. )
  1239. {
  1240. struct tm tmFrom, tmTo;
  1241. struct timeb tbFrom, tbTo;
  1242. 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) &&
  1243. (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))
  1244. {
  1245. tmFrom.tm_year -= 1900;
  1246. tmFrom.tm_mon -= 1;
  1247. tbFrom.time = mktime(&tmFrom);
  1248. tmTo.tm_year -= 1900;
  1249. tmTo.tm_mon -= 1;
  1250. tbTo.time = mktime(&tmTo);
  1251. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1252. {
  1253. if(defaultTxProfile.ChargingProfileId == -1)
  1254. DEBUG_INFO("TxDefaultProfile found.\n");
  1255. else
  1256. DEBUG_INFO("TxDefaultProfile updated.\n");
  1257. // Required item
  1258. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1259. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1260. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1261. if(isUnitA)
  1262. {
  1263. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1264. 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++)
  1265. {
  1266. 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"));
  1267. 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?
  1268. 3:
  1269. 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")));
  1270. 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")));
  1271. }
  1272. }
  1273. else
  1274. {
  1275. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1276. 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++)
  1277. {
  1278. 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"));
  1279. 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?
  1280. 3:
  1281. 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")));
  1282. 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));
  1283. }
  1284. }
  1285. // Optional item
  1286. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1287. {
  1288. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1289. }
  1290. else
  1291. {
  1292. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1293. }
  1294. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1295. {
  1296. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1297. }
  1298. else
  1299. {
  1300. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1301. }
  1302. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1303. {
  1304. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1305. }
  1306. else
  1307. {
  1308. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1309. }
  1310. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1311. {
  1312. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1313. }
  1314. else
  1315. {
  1316. defaultTxProfile.TransactionId = -1;
  1317. }
  1318. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1319. {
  1320. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1321. }
  1322. else
  1323. {
  1324. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1325. }
  1326. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1327. {
  1328. 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")));
  1329. }
  1330. else
  1331. {
  1332. 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));
  1333. }
  1334. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1335. {
  1336. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1337. }
  1338. else
  1339. {
  1340. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1341. }
  1342. }
  1343. }
  1344. }
  1345. else
  1346. {
  1347. if(defaultTxProfile.ChargingProfileId == -1)
  1348. DEBUG_INFO("TxDefaultProfile found.\n");
  1349. else
  1350. DEBUG_INFO("TxDefaultProfile updated.\n");
  1351. // Required item
  1352. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1353. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1354. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1355. if(isUnitA)
  1356. {
  1357. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1358. 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++)
  1359. {
  1360. 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"));
  1361. 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?
  1362. 3:
  1363. 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")));
  1364. 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")));
  1365. }
  1366. }
  1367. else
  1368. {
  1369. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1370. 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++)
  1371. {
  1372. 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"));
  1373. 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?
  1374. 3:
  1375. 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")));
  1376. 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));
  1377. }
  1378. }
  1379. // Optional item
  1380. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1381. {
  1382. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1383. }
  1384. else
  1385. {
  1386. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1387. }
  1388. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1389. {
  1390. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1391. }
  1392. else
  1393. {
  1394. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1395. }
  1396. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1397. {
  1398. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1399. }
  1400. else
  1401. {
  1402. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1403. }
  1404. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1405. {
  1406. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1407. }
  1408. else
  1409. {
  1410. defaultTxProfile.TransactionId = -1;
  1411. }
  1412. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1413. {
  1414. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1415. }
  1416. else
  1417. {
  1418. defaultTxProfile.ChargingSchedule.Duration = 86400;
  1419. }
  1420. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1421. {
  1422. 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")));
  1423. }
  1424. else
  1425. {
  1426. 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));
  1427. }
  1428. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1429. {
  1430. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1431. }
  1432. else
  1433. {
  1434. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1435. }
  1436. }
  1437. }
  1438. }
  1439. json_object_put(obj);
  1440. }
  1441. fclose(fp);
  1442. /*
  1443. if(defaultTxProfile.ChargingProfileId != -1)
  1444. {
  1445. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1446. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1447. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1448. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1449. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1450. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1451. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1452. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1453. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1454. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1455. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1456. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1457. {
  1458. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1459. {
  1460. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1461. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1462. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1463. }
  1464. }
  1465. }
  1466. else
  1467. DEBUG_INFO("TxDefaultProfile not found.\n");
  1468. DEBUG_INFO("------------------------------------\n");*/
  1469. }
  1470. // Search max profile
  1471. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  1472. if((access(profileFileName, F_OK))!=-1)
  1473. {
  1474. fp = fopen(profileFileName, "r");
  1475. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1476. {
  1477. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1478. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1479. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1480. }
  1481. maxProfile.ChargingProfileId = -1;
  1482. maxProfile.StackLevel = -1;
  1483. while(getline(&line, &len, fp) != -1)
  1484. {
  1485. json_object *obj = NULL;
  1486. obj = json_tokener_parse(line);
  1487. if(is_error(obj))
  1488. {
  1489. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1490. }
  1491. else
  1492. {
  1493. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1494. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1495. )
  1496. {
  1497. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1498. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1499. )
  1500. {
  1501. struct tm tmFrom, tmTo;
  1502. struct timeb tbFrom, tbTo;
  1503. 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) &&
  1504. (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))
  1505. {
  1506. tmFrom.tm_year -= 1900;
  1507. tmFrom.tm_mon -= 1;
  1508. tbFrom.time = mktime(&tmFrom);
  1509. tmTo.tm_year -= 1900;
  1510. tmTo.tm_mon -= 1;
  1511. tbTo.time = mktime(&tmTo);
  1512. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1513. {
  1514. if(maxProfile.ChargingProfileId == -1)
  1515. DEBUG_INFO("MaxProfile found.\n");
  1516. else
  1517. DEBUG_INFO("MaxProfile updated.\n");
  1518. // Required item
  1519. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1520. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1521. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1522. if(isUnitA)
  1523. {
  1524. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1525. 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++)
  1526. {
  1527. 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"));
  1528. 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?
  1529. 3:
  1530. 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")));
  1531. 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")));
  1532. }
  1533. }
  1534. else
  1535. {
  1536. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1537. 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++)
  1538. {
  1539. 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"));
  1540. 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?
  1541. 3:
  1542. 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")));
  1543. 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));
  1544. }
  1545. }
  1546. // Optional item
  1547. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1548. {
  1549. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1550. }
  1551. else
  1552. {
  1553. sprintf((char*)maxProfile.ValidFrom, " ");
  1554. }
  1555. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1556. {
  1557. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1558. }
  1559. else
  1560. {
  1561. sprintf((char*)maxProfile.ValidTo, " ");
  1562. }
  1563. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1564. {
  1565. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1566. }
  1567. else
  1568. {
  1569. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1570. }
  1571. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1572. {
  1573. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1574. }
  1575. else
  1576. {
  1577. maxProfile.TransactionId = -1;
  1578. }
  1579. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1580. {
  1581. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1582. }
  1583. else
  1584. {
  1585. maxProfile.ChargingSchedule.Duration = 86400;
  1586. }
  1587. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1588. {
  1589. 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")));
  1590. }
  1591. else
  1592. {
  1593. 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));
  1594. }
  1595. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1596. {
  1597. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1598. }
  1599. else
  1600. {
  1601. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1602. }
  1603. }
  1604. }
  1605. }
  1606. else
  1607. {
  1608. if(maxProfile.ChargingProfileId == -1)
  1609. DEBUG_INFO("MaxProfile found.\n");
  1610. else
  1611. DEBUG_INFO("MaxProfile updated.\n");
  1612. // Required item
  1613. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1614. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1615. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1616. if(isUnitA)
  1617. {
  1618. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1619. 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++)
  1620. {
  1621. 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"));
  1622. 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?
  1623. 3:
  1624. 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")));
  1625. 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")));
  1626. }
  1627. }
  1628. else
  1629. {
  1630. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "W");
  1631. 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++)
  1632. {
  1633. 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"));
  1634. 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?
  1635. 3:
  1636. 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")));
  1637. 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));
  1638. }
  1639. }
  1640. // Optional item
  1641. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1642. {
  1643. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1644. }
  1645. else
  1646. {
  1647. sprintf((char*)maxProfile.ValidFrom, " ");
  1648. }
  1649. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1650. {
  1651. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1652. }
  1653. else
  1654. {
  1655. sprintf((char*)maxProfile.ValidTo, " ");
  1656. }
  1657. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1658. {
  1659. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1660. }
  1661. else
  1662. {
  1663. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1664. }
  1665. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1666. {
  1667. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1668. }
  1669. else
  1670. {
  1671. maxProfile.TransactionId = -1;
  1672. }
  1673. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1674. {
  1675. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1676. }
  1677. else
  1678. {
  1679. maxProfile.ChargingSchedule.Duration = 86400;
  1680. }
  1681. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1682. {
  1683. 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")));
  1684. }
  1685. else
  1686. {
  1687. 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));
  1688. }
  1689. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1690. {
  1691. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1692. }
  1693. else
  1694. {
  1695. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1696. }
  1697. }
  1698. }
  1699. }
  1700. json_object_put(obj);
  1701. }
  1702. fclose(fp);
  1703. /*
  1704. if(maxProfile.ChargingProfileId !=-1)
  1705. {
  1706. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1707. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1708. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1709. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1710. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1711. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1712. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1713. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1714. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1715. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1716. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1717. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1718. {
  1719. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1720. {
  1721. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1722. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1723. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1724. }
  1725. }
  1726. }
  1727. else
  1728. DEBUG_INFO("MaxProfile not found.\n");
  1729. DEBUG_INFO("------------------------------------\n");*/
  1730. }
  1731. /*
  1732. * Align found profile start schedule & periods
  1733. */
  1734. //DEBUG_INFO("====================================\n");
  1735. /*
  1736. // For local test usage, force modify found profile start schedule info
  1737. 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);
  1738. 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);
  1739. 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);
  1740. */
  1741. if(txProfile.ChargingProfileId != -1)
  1742. {
  1743. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1744. {
  1745. if(txProfile.ChargingSchedule.Duration != -1)
  1746. {
  1747. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1748. 0:
  1749. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1750. }
  1751. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1752. {
  1753. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1754. {
  1755. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1756. 0:
  1757. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1758. if(idxPeriod > 0)
  1759. {
  1760. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1761. {
  1762. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1763. }
  1764. }
  1765. }
  1766. }
  1767. }
  1768. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1769. {
  1770. if(txProfile.ChargingSchedule.Duration != -1)
  1771. {
  1772. txProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1773. 0:
  1774. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1775. }
  1776. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1777. {
  1778. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1779. {
  1780. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1781. 0:
  1782. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1783. if(idxPeriod > 0)
  1784. {
  1785. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1786. {
  1787. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1788. }
  1789. }
  1790. }
  1791. }
  1792. }
  1793. else
  1794. {
  1795. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1796. {
  1797. if(txProfile.ChargingSchedule.Duration != -1)
  1798. {
  1799. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1800. 0:
  1801. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1802. }
  1803. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1804. {
  1805. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1806. {
  1807. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1808. 0:
  1809. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1810. if(idxPeriod > 0)
  1811. {
  1812. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1813. {
  1814. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1815. }
  1816. }
  1817. }
  1818. }
  1819. }
  1820. else
  1821. {
  1822. if(txProfile.ChargingSchedule.Duration != -1)
  1823. {
  1824. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1825. 0:
  1826. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1827. }
  1828. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1829. {
  1830. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1831. {
  1832. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1833. 0:
  1834. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1835. if(idxPeriod > 0)
  1836. {
  1837. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1838. {
  1839. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1840. }
  1841. }
  1842. }
  1843. }
  1844. }
  1845. }
  1846. /*
  1847. DEBUG_INFO("txProfile after align.\n");
  1848. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1849. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1850. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1851. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1852. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1853. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1854. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1855. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1856. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1857. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1858. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1859. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1860. {
  1861. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1862. {
  1863. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1864. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1865. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1866. }
  1867. }*/
  1868. }
  1869. if(defaultTxProfile.ChargingProfileId != -1)
  1870. {
  1871. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1872. {
  1873. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1874. {
  1875. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1876. 0:
  1877. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1878. }
  1879. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1880. {
  1881. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1882. {
  1883. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1884. 0:
  1885. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1886. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1887. {
  1888. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1889. }
  1890. if(idxPeriod > 0)
  1891. {
  1892. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1893. {
  1894. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1895. }
  1896. }
  1897. }
  1898. }
  1899. }
  1900. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1901. {
  1902. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1903. {
  1904. defaultTxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1905. 0:
  1906. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1907. }
  1908. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1909. {
  1910. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1911. {
  1912. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1913. 0:
  1914. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1915. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1916. {
  1917. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1918. }
  1919. if(idxPeriod > 0)
  1920. {
  1921. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1922. {
  1923. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1924. }
  1925. }
  1926. }
  1927. }
  1928. }
  1929. else
  1930. {
  1931. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1932. {
  1933. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1934. {
  1935. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1936. 0:
  1937. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1938. }
  1939. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1940. {
  1941. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1942. {
  1943. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1944. 0:
  1945. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1946. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1947. {
  1948. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1949. }
  1950. if(idxPeriod > 0)
  1951. {
  1952. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1953. {
  1954. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1955. }
  1956. }
  1957. }
  1958. }
  1959. }
  1960. else
  1961. {
  1962. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1963. {
  1964. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1965. 0:
  1966. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1967. }
  1968. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1969. {
  1970. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1971. {
  1972. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1973. 0:
  1974. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1975. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1976. {
  1977. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1978. }
  1979. if(idxPeriod > 0)
  1980. {
  1981. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1982. {
  1983. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1984. }
  1985. }
  1986. }
  1987. }
  1988. }
  1989. }
  1990. /*
  1991. DEBUG_INFO("defaultTxProfile after align.\n");
  1992. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1993. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1994. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1995. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1996. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1997. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1998. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1999. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2000. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  2001. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  2002. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  2003. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2004. {
  2005. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2006. {
  2007. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2008. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2009. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2010. }
  2011. }
  2012. DEBUG_INFO("------------------------------------\n");*/
  2013. }
  2014. if(maxProfile.ChargingProfileId != -1)
  2015. {
  2016. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  2017. {
  2018. if(maxProfile.ChargingSchedule.Duration != -1)
  2019. {
  2020. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2021. 0:
  2022. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2023. }
  2024. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2025. {
  2026. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2027. {
  2028. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2029. 0:
  2030. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  2031. if(idxPeriod > 0)
  2032. {
  2033. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2034. {
  2035. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2036. }
  2037. }
  2038. }
  2039. }
  2040. }
  2041. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  2042. {
  2043. if(maxProfile.ChargingSchedule.Duration != -1)
  2044. {
  2045. maxProfile.ChargingSchedule.Duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2046. 0:
  2047. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2048. }
  2049. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2050. {
  2051. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2052. {
  2053. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  2054. 0:
  2055. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16DataPH->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  2056. if(idxPeriod > 0)
  2057. {
  2058. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2059. {
  2060. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. else
  2067. {
  2068. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  2069. {
  2070. if(maxProfile.ChargingSchedule.Duration != -1)
  2071. {
  2072. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2073. 0:
  2074. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2075. }
  2076. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2077. {
  2078. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2079. {
  2080. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  2081. 0:
  2082. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  2083. if(idxPeriod > 0)
  2084. {
  2085. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2086. {
  2087. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2088. }
  2089. }
  2090. }
  2091. }
  2092. }
  2093. else
  2094. {
  2095. if(maxProfile.ChargingSchedule.Duration != -1)
  2096. {
  2097. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2098. 0:
  2099. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2100. }
  2101. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2102. {
  2103. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  2104. {
  2105. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  2106. 0:
  2107. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  2108. if(idxPeriod > 0)
  2109. {
  2110. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  2111. {
  2112. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. }
  2119. /*
  2120. DEBUG_INFO("MaxProfile after align.\n");
  2121. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  2122. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  2123. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  2124. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  2125. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  2126. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  2127. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  2128. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2129. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  2130. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  2131. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  2132. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2133. {
  2134. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2135. {
  2136. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2137. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2138. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2139. }
  2140. }
  2141. DEBUG_INFO("------------------------------------\n");*/
  2142. }
  2143. /*
  2144. * Merge to conposite schedule
  2145. */
  2146. //DEBUG_INFO("====================================\n");
  2147. // Find each profile period quantity
  2148. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2149. {
  2150. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2151. limitMax = idx+1;
  2152. }
  2153. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2154. {
  2155. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2156. limitDef = idx+1;
  2157. }
  2158. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  2159. {
  2160. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  2161. limitTx = idx+1;
  2162. }
  2163. // TxProfile found, composite schedule based on it
  2164. if(txProfile.ChargingProfileId != -1)
  2165. {
  2166. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  2167. {
  2168. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  2169. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  2170. (txProfile.ChargingSchedule.Duration > 0))
  2171. {
  2172. if(maxProfile.ChargingProfileId != -1)
  2173. {
  2174. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2175. {
  2176. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  2177. {
  2178. if((maxProfile.ChargingSchedule.Duration > 0))
  2179. {
  2180. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2181. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2182. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2183. }
  2184. else
  2185. {
  2186. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  2187. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  2188. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  2189. }
  2190. }
  2191. if(idxMaxPeriod == (limitMax-1))
  2192. {
  2193. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2194. {
  2195. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2196. {
  2197. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2198. compositePeriodIdx++;
  2199. }
  2200. else
  2201. {
  2202. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. else
  2209. {
  2210. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2211. {
  2212. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2213. compositePeriodIdx++;
  2214. }
  2215. else
  2216. {
  2217. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  2218. }
  2219. }
  2220. }
  2221. if(idxTxPeriod == (limitTx-1))
  2222. {
  2223. if(defaultTxProfile.ChargingProfileId != -1)
  2224. {
  2225. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2226. {
  2227. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  2228. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2229. (defaultTxProfile.ChargingSchedule.Duration>0))
  2230. {
  2231. if(maxProfile.ChargingProfileId != -1)
  2232. {
  2233. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2234. {
  2235. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2236. {
  2237. if((maxProfile.ChargingSchedule.Duration > 0))
  2238. {
  2239. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2240. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2241. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  2242. }
  2243. else
  2244. {
  2245. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2246. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2247. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2248. }
  2249. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2250. {
  2251. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2252. {
  2253. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2254. compositePeriodIdx++;
  2255. }
  2256. else
  2257. {
  2258. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2259. }
  2260. }
  2261. // Delete duplicate period
  2262. if(compositePeriodIdx > 1)
  2263. {
  2264. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2265. {
  2266. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2267. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2268. compositePeriodIdx -= 1;
  2269. }
  2270. }
  2271. }
  2272. else
  2273. break;
  2274. }
  2275. }
  2276. else
  2277. {
  2278. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2279. {
  2280. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2281. compositePeriodIdx++;
  2282. }
  2283. else
  2284. {
  2285. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2286. }
  2287. }
  2288. }
  2289. }
  2290. }
  2291. }
  2292. }
  2293. }
  2294. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2295. else if(defaultTxProfile.ChargingProfileId != -1)
  2296. {
  2297. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2298. {
  2299. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2300. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  2301. (defaultTxProfile.ChargingSchedule.Duration > 0))
  2302. {
  2303. if(maxProfile.ChargingProfileId != -1)
  2304. {
  2305. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2306. {
  2307. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2308. {
  2309. if((maxProfile.ChargingSchedule.Duration > 0))
  2310. {
  2311. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2312. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2313. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2314. }
  2315. else
  2316. {
  2317. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2318. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2319. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  2320. }
  2321. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2322. {
  2323. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2324. {
  2325. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2326. compositePeriodIdx++;
  2327. }
  2328. else
  2329. {
  2330. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2331. }
  2332. }
  2333. // Delete duplicate period
  2334. if(compositePeriodIdx > 1)
  2335. {
  2336. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2337. {
  2338. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2339. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2340. compositePeriodIdx -= 1;
  2341. }
  2342. }
  2343. }
  2344. else
  2345. break;
  2346. }
  2347. }
  2348. else
  2349. {
  2350. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2351. {
  2352. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2353. compositePeriodIdx++;
  2354. }
  2355. else
  2356. {
  2357. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. // Fill other period by MaxProfile
  2364. if(maxProfile.ChargingProfileId != -1)
  2365. {
  2366. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2367. {
  2368. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2369. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  2370. (maxProfile.ChargingSchedule.Duration > 0))
  2371. {
  2372. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2373. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2374. {
  2375. tmpPeriod.StartPeriod = (compositePeriodIdx==0)?0:compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2376. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2377. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2378. }
  2379. if((compositePeriodIdx > 0 ) && (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2380. {
  2381. tmpPeriod.StartPeriod = (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod>compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod:compositeProfile->ChargingSchedule.Duration;
  2382. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2383. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2384. }
  2385. if(tmpPeriod.Limit != -1)
  2386. {
  2387. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2388. {
  2389. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2390. {
  2391. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2392. compositePeriodIdx++;
  2393. }
  2394. else
  2395. {
  2396. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2397. }
  2398. }
  2399. // Delete duplicate period
  2400. if(compositePeriodIdx > 1)
  2401. {
  2402. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit == compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-2].Limit)
  2403. {
  2404. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].StartPeriod = -1;
  2405. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx-1].Limit = -1;
  2406. compositePeriodIdx -= 1;
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  2414. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2415. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2416. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2417. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2418. {
  2419. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2420. {
  2421. compositeProfile->ChargingProfileId = 1;
  2422. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2423. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2424. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2425. }
  2426. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2427. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2428. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2429. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2430. }
  2431. if(line)
  2432. free(line);
  2433. ShmOCPP16DataPH->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  2434. }
  2435. //==========================================
  2436. // Init all share memory
  2437. //==========================================
  2438. int InitShareMemory()
  2439. {
  2440. int result = PASS;
  2441. int MeterSMId;
  2442. //creat ShmSysConfigAndInfo
  2443. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2444. {
  2445. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2446. result = FAIL;
  2447. }
  2448. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2449. {
  2450. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2451. result = FAIL;
  2452. }
  2453. else
  2454. {}
  2455. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2456. {
  2457. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2458. result = FAIL;
  2459. }
  2460. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2461. {
  2462. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2463. result = FAIL;
  2464. }
  2465. else
  2466. {}
  2467. //creat ShmPsuData
  2468. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2469. {
  2470. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2471. result = FAIL;
  2472. }
  2473. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2474. {
  2475. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2476. result = FAIL;
  2477. }
  2478. else
  2479. {}
  2480. //link ShmOCPP16Data
  2481. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2482. {
  2483. DEBUG_ERROR("shmget ShmOCPP16Data NG\n");
  2484. result = FAIL;
  2485. }
  2486. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2487. {
  2488. DEBUG_ERROR("shmat ShmOCPP16Data NG\n");
  2489. result = FAIL;
  2490. }
  2491. else
  2492. {}
  2493. //creat ShmOCPP16DataPH
  2494. if ((MeterSMId = shmget(3001, sizeof(struct OCPP16Data), IPC_CREAT|0777)) < 0)
  2495. {
  2496. DEBUG_ERROR("shmget ShmOCPP16DataPH NG\n");
  2497. result = FAIL;
  2498. }
  2499. else if ((ShmOCPP16DataPH = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2500. {
  2501. DEBUG_ERROR("shmat ShmOCPP16DataPH NG\n");
  2502. result = FAIL;
  2503. }
  2504. else
  2505. {}
  2506. /****************************** For Initial Settings************************************************/
  2507. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = NULL;
  2508. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = NULL;
  2509. // allocate Configuration memory address
  2510. ShmOCPP16DataPH->GetConfiguration.Key = staticKeyArray;
  2511. ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2512. ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2513. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2514. //offline MeterValue Interval
  2515. TempMeterValueInterval = 0;
  2516. return result;
  2517. }
  2518. int ProcessShareMemory()
  2519. {
  2520. if(InitShareMemory() == FAIL)
  2521. {
  2522. DEBUG_ERROR("InitShareMemory NG\n");
  2523. if(ShmStatusCodeData!=NULL)
  2524. {
  2525. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2526. }
  2527. sleep(5);
  2528. return FAIL;
  2529. }
  2530. return PASS;
  2531. }
  2532. void CheckSystemValue(void)
  2533. {
  2534. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2535. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2536. char filenmae[100]={0};
  2537. char str[100]={0};
  2538. int tempIndex = 0;
  2539. //===============================
  2540. // send Heartbeat
  2541. //===============================
  2542. //HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  2543. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2544. {
  2545. clientTime.Heartbeat=time((time_t*)NULL);
  2546. if(server_sign == TRUE)
  2547. {
  2548. HeartBeatWaitTime = ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval;
  2549. }
  2550. else
  2551. {
  2552. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2553. }
  2554. }
  2555. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2556. {
  2557. //parameter for test
  2558. sendHeartbeatRequest(0);
  2559. //==============================================
  2560. // Reset Waiting Time
  2561. //==============================================
  2562. HeartBeatWithNOResponse += 2;
  2563. }
  2564. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2565. {
  2566. //==========================================
  2567. // csu trigger DataTransferReq
  2568. //==========================================
  2569. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq == 1))
  2570. {
  2571. sendDataTransferRequest(gun_index);
  2572. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 0;
  2573. }
  2574. //===============================
  2575. // CSU Trigger Authorize Request
  2576. //===============================
  2577. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2578. {
  2579. sendAuthorizeRequest(0);
  2580. authorizeRetryTimes = authorizeRetryTimes + 1;
  2581. if(authorizeRetryTimes < 3)
  2582. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  2583. }
  2584. else if((server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2585. {
  2586. authorizeRetryTimes = 0;
  2587. SetOcppConnStatus(FALSE);
  2588. server_sign = FALSE;
  2589. }
  2590. 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))
  2591. {
  2592. sendAuthorizeRequest(0);
  2593. }
  2594. //==============================================
  2595. // CSU Trigger Smart Charging Profilw
  2596. //==============================================
  2597. if(ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2598. {
  2599. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16DataPH->SmartChargingProfile[gun_index], TRUE);
  2600. ShmOCPP16DataPH->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2601. }
  2602. //==============================================
  2603. // Charger start transaction
  2604. //==============================================
  2605. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2606. {
  2607. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2608. memcpy(&ShmOCPP16DataPH->StartTransaction[gun_index], &ShmOCPP16DataPH->StartTransaction[gun_index], sizeof(struct StructStartTransaction));
  2609. sendStartTransactionRequest(gun_index);
  2610. clientTime.StartTransaction = time((time_t*)NULL);
  2611. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2612. storeTempStopTransaction(gun_index);
  2613. }
  2614. //==============================================
  2615. // Charger stop transaction
  2616. //==============================================
  2617. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2618. {
  2619. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2620. memcpy(&ShmOCPP16DataPH->StopTransaction[gun_index], &ShmOCPP16DataPH->StopTransaction[gun_index], sizeof(struct StructStopTransaction));
  2621. sendStopTransactionRequest(gun_index);
  2622. clientTime.StopTransaction = time((time_t*)NULL);
  2623. }
  2624. //==============================================
  2625. // Charger status report
  2626. //==============================================
  2627. //--- Check Mode Change ---//
  2628. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2629. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2630. {
  2631. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2632. {
  2633. tempIndex = ((gun_index==2) ? 1: 0);
  2634. }
  2635. else
  2636. {
  2637. tempIndex = gun_index;
  2638. }
  2639. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2640. {
  2641. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2642. {
  2643. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2644. {
  2645. // Sent unplug message for California pricing logic
  2646. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 0))
  2647. {
  2648. uint8_t ts[20];
  2649. getNowDatetime(ts);
  2650. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2651. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2652. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2653. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2654. }
  2655. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2656. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2657. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2658. }
  2659. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2660. {
  2661. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2662. if((access(filenmae,F_OK))!=-1)
  2663. {
  2664. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2665. sprintf(str,"rm -f %s",filenmae);
  2666. system(str);
  2667. }
  2668. }
  2669. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2670. #if 1 // for TempStopTransaction
  2671. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2672. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2673. {
  2674. checkTempStopTransaction(gun_index);
  2675. }
  2676. #endif
  2677. }
  2678. }
  2679. }
  2680. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2681. {
  2682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2683. {
  2684. tempIndex = ((gun_index==2) ? 1: 0);
  2685. }
  2686. else
  2687. {
  2688. tempIndex = gun_index;
  2689. }
  2690. for (int index = 0; index < CCS_QUANTITY; index++)
  2691. {
  2692. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2693. {
  2694. 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]*/ )
  2695. {
  2696. // Sent unplug message for California pricing logic
  2697. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 0))
  2698. {
  2699. uint8_t ts[20];
  2700. getNowDatetime(ts);
  2701. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2702. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2703. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2704. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2705. }
  2706. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2707. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2708. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2709. }
  2710. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2711. {
  2712. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2713. if((access(filenmae,F_OK))!=-1)
  2714. {
  2715. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2716. sprintf(str,"rm -f %s",filenmae);
  2717. system(str);
  2718. }
  2719. }
  2720. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2721. #if 1 // for TempStopTransaction
  2722. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2723. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2724. {
  2725. checkTempStopTransaction(gun_index);
  2726. }
  2727. #endif
  2728. }
  2729. }
  2730. }
  2731. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2732. {
  2733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2734. {
  2735. tempIndex = ((gun_index==2) ? 1: 0);
  2736. }
  2737. else
  2738. {
  2739. tempIndex = gun_index;
  2740. }
  2741. for (int index = 0; index < GB_QUANTITY; index++)
  2742. {
  2743. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2744. {
  2745. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2746. {
  2747. // Sent unplug message for California pricing logic
  2748. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 0))
  2749. {
  2750. uint8_t ts[20];
  2751. getNowDatetime(ts);
  2752. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2753. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2754. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2755. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2756. }
  2757. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2758. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2759. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2760. }
  2761. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2762. {
  2763. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2764. if((access(filenmae,F_OK))!=-1)
  2765. {
  2766. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2767. sprintf(str,"rm -f %s",filenmae);
  2768. system(str);
  2769. }
  2770. }
  2771. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2772. #if 1 // for TempStopTransaction
  2773. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2774. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2775. {
  2776. checkTempStopTransaction(gun_index);
  2777. }
  2778. #endif
  2779. }
  2780. }
  2781. }
  2782. else if(gunType[gun_index] == GUN_TYPE_DO)
  2783. {
  2784. tempIndex = gun_index;
  2785. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2786. {
  2787. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2788. {
  2789. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2790. {
  2791. // Sent unplug message for California pricing logic
  2792. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 0))
  2793. {
  2794. uint8_t ts[20];
  2795. getNowDatetime(ts);
  2796. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2797. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2798. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2799. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2800. }
  2801. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2802. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2803. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2804. }
  2805. 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
  2806. {
  2807. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2808. if((access(filenmae,F_OK))!=-1)
  2809. {
  2810. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2811. sprintf(str,"rm -f %s",filenmae);
  2812. system(str);
  2813. }
  2814. }
  2815. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2816. #if 1 // for TempStopTransaction
  2817. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  2818. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2819. {
  2820. checkTempStopTransaction(gun_index);
  2821. }
  2822. #endif
  2823. }
  2824. }
  2825. }
  2826. else
  2827. {
  2828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2829. {
  2830. tempIndex = 2;
  2831. }
  2832. else
  2833. {
  2834. tempIndex = gun_index;
  2835. }
  2836. for (int index = 0; index < AC_QUANTITY; index++)
  2837. {
  2838. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2839. {
  2840. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2841. {
  2842. // Sent unplug message for California pricing logic
  2843. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)
  2844. {
  2845. uint8_t ts[20];
  2846. getNowDatetime(ts);
  2847. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2848. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].MessageId, "ConnectorUnplugged");
  2849. sprintf((char*)ShmOCPP16DataPH->DataTransfer[gun_index].Data, "{\\\"idTx\\\":%d,\\\"timestamp\\\":\\\"%s\\\"}", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId, ts);
  2850. ShmOCPP16DataPH->CsMsg.bits[gun_index].DataTransferReq = 1;
  2851. }
  2852. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2853. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2854. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2855. }
  2856. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2857. {
  2858. sprintf(filenmae,"/Storage/OCPP_PH/TxProfile_%d.json",(gun_index+1));
  2859. if((access(filenmae,F_OK))!=-1)
  2860. {
  2861. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2862. sprintf(str,"rm -f %s",filenmae);
  2863. system(str);
  2864. }
  2865. }
  2866. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  2867. #if 1 // for TempStopTransaction
  2868. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  2869. (ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2870. {
  2871. checkTempStopTransaction(gun_index);
  2872. }
  2873. #endif
  2874. }
  2875. }// END
  2876. }
  2877. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  2878. (
  2879. (cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == 1)
  2880. )
  2881. )
  2882. {
  2883. if(SystemInitial > 0)
  2884. SystemInitial -= 1;
  2885. memcpy(&ShmOCPP16DataPH->StatusNotification[gun_index], &ShmOCPP16DataPH->StatusNotification[gun_index], sizeof(struct StructStatusNotification));
  2886. sendStatusNotificationRequest(gun_index);
  2887. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2888. }
  2889. //==============================================
  2890. // Meter report
  2891. //==============================================
  2892. // Trigger MeterValue
  2893. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2894. {
  2895. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2896. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2897. }
  2898. // ClockAlign MeterValue
  2899. 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))
  2900. {
  2901. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2902. {
  2903. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2904. {
  2905. tempIndex = ((gun_index==2) ? 1: 0);
  2906. }
  2907. else
  2908. {
  2909. tempIndex = gun_index;
  2910. }
  2911. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2912. {
  2913. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2914. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2915. {
  2916. reqClockAlignMeter[gun_index] = 1;
  2917. }
  2918. }// End for CHAdeMO
  2919. }
  2920. else if(gunType[gun_index] == GUN_TYPE_CCS)
  2921. {
  2922. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2923. {
  2924. tempIndex = ((gun_index==2) ? 1: 0);
  2925. }
  2926. else
  2927. {
  2928. tempIndex = gun_index;
  2929. }
  2930. for (int index = 0; index < CCS_QUANTITY; index++)
  2931. {
  2932. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2933. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2934. {
  2935. reqClockAlignMeter[gun_index] = 1;
  2936. }
  2937. } // End for CCS
  2938. }
  2939. else if(gunType[gun_index] == GUN_TYPE_GBT)
  2940. {
  2941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2942. {
  2943. tempIndex = ((gun_index==2) ? 1: 0);
  2944. }
  2945. else
  2946. {
  2947. tempIndex = gun_index;
  2948. }
  2949. for (int index = 0; index < GB_QUANTITY; index++)
  2950. {
  2951. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2952. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2953. {
  2954. reqClockAlignMeter[gun_index] = 1;
  2955. }
  2956. }// End for GB
  2957. }
  2958. else if(gunType[gun_index] == GUN_TYPE_DO)
  2959. {
  2960. tempIndex = gun_index;
  2961. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2962. {
  2963. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2964. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2965. {
  2966. reqClockAlignMeter[gun_index] = 1;
  2967. }
  2968. }
  2969. }
  2970. else
  2971. {
  2972. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2973. {
  2974. tempIndex = 2;
  2975. }
  2976. else
  2977. {
  2978. tempIndex = gun_index;
  2979. }
  2980. for (int index = 0; index < AC_QUANTITY; index++)
  2981. {
  2982. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2983. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2984. {
  2985. reqClockAlignMeter[gun_index] = 1;
  2986. }
  2987. }//End for AC
  2988. }
  2989. if(reqClockAlignMeter[gun_index] == 1)
  2990. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2991. }
  2992. // Sample period MeterValue
  2993. 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))))
  2994. {
  2995. //check Transaction active
  2996. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  2997. {
  2998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2999. {
  3000. tempIndex = ((gun_index==2) ? 1: 0);
  3001. }
  3002. else
  3003. {
  3004. tempIndex = gun_index;
  3005. }
  3006. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3007. {
  3008. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3009. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3010. {
  3011. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3012. {
  3013. reqSampleMeter[gun_index] = 1;
  3014. }
  3015. }
  3016. }// End for CHAdeMO
  3017. }
  3018. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3019. {
  3020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3021. {
  3022. tempIndex = ((gun_index==2) ? 1: 0);
  3023. }
  3024. else
  3025. {
  3026. tempIndex = gun_index;
  3027. }
  3028. for (int index = 0; index < CCS_QUANTITY; index++)
  3029. {
  3030. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3031. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3032. {
  3033. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3034. {
  3035. reqSampleMeter[gun_index] = 1;
  3036. }
  3037. }
  3038. } // End for CCS
  3039. }
  3040. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3041. {
  3042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3043. {
  3044. tempIndex = ((gun_index==2) ? 1: 0);
  3045. }
  3046. else
  3047. {
  3048. tempIndex = gun_index;
  3049. }
  3050. for (int index = 0; index < GB_QUANTITY; index++)
  3051. {
  3052. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3053. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3054. {
  3055. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  3056. {
  3057. reqSampleMeter[gun_index] = 1;
  3058. }
  3059. }
  3060. }// End for GB
  3061. }
  3062. else if(gunType[gun_index] == GUN_TYPE_DO)
  3063. {
  3064. tempIndex = gun_index;
  3065. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3066. {
  3067. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3068. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3069. {
  3070. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  3071. {
  3072. reqSampleMeter[gun_index] = 1;
  3073. }
  3074. }
  3075. }
  3076. }
  3077. else
  3078. {
  3079. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3080. {
  3081. tempIndex = 2;
  3082. }
  3083. else
  3084. {
  3085. tempIndex = gun_index;
  3086. }
  3087. for (int index = 0; index < AC_QUANTITY; index++)
  3088. {
  3089. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  3090. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3091. {
  3092. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  3093. {
  3094. reqSampleMeter[gun_index] = 1;
  3095. }
  3096. }
  3097. }//End for AC
  3098. }
  3099. if(reqSampleMeter[gun_index] == 1)
  3100. {
  3101. if(atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)>0)
  3102. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  3103. storeTempStopTransaction(gun_index);
  3104. }
  3105. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3106. }
  3107. //==============================================
  3108. // Check Connector reserved
  3109. //==============================================
  3110. //===============================
  3111. // Check if Reserve is expired
  3112. //===============================
  3113. if((server_sign == TRUE) && (ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  3114. {
  3115. double diff_t;
  3116. struct tm tp;
  3117. // current time
  3118. time_t t = time(NULL);
  3119. strptime((char *)ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  3120. tp.tm_isdst = -1;
  3121. time_t utc = mktime(&tp);
  3122. diff_t = difftime(utc, t);
  3123. if(diff_t <= 0)
  3124. {
  3125. DEBUG_INFO("reserve expired.\n");
  3126. memset(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16DataPH->ReserveNow[gun_index].ExpiryDate));
  3127. }
  3128. }//END OF Check if Reserve is expired
  3129. //==========================================
  3130. // csu trigger FirmwareStatusNotificationReq
  3131. //==========================================
  3132. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  3133. {
  3134. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status);
  3135. }
  3136. //==========================================
  3137. // csu trigger DiagnosticsStatusNotificationReq
  3138. //==========================================
  3139. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq == 1))
  3140. {
  3141. sendDiagnosticsStatusNotificationRequest((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status);
  3142. }
  3143. //==========================================
  3144. // csu trigger CancelReservationConf
  3145. //==========================================
  3146. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf == 1))
  3147. {
  3148. sendCancelReservationConfirmation((char *)ShmOCPP16DataPH->CancelReservation[gun_index].guid,(char *)ShmOCPP16DataPH->CancelReservation[gun_index].ResponseStatus);
  3149. ShmOCPP16DataPH->CsMsg.bits[gun_index].CancelReservationConf = 0;
  3150. }
  3151. //==========================================
  3152. // csu trigger ChangeAvailabilityConf
  3153. //==========================================
  3154. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  3155. {
  3156. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16DataPH->ChangeAvailability[gun_index].ResponseStatus);
  3157. }
  3158. //==========================================
  3159. // csu trigger UnlockConnectorConf
  3160. //==========================================
  3161. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  3162. {
  3163. sendUnlockConnectorConfirmation((char *)ShmOCPP16DataPH->UnlockConnector[gun_index].guid, (char *)ShmOCPP16DataPH->UnlockConnector[gun_index].ResponseStatus);
  3164. ShmOCPP16DataPH->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  3165. }
  3166. //==========================================
  3167. // csu trigger ReserveNowConf
  3168. //==========================================
  3169. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf == 1))
  3170. {
  3171. sendReserveNowTransactionConfirmation((char *)ShmOCPP16DataPH->ReserveNow[gun_index].guid, (char *)ShmOCPP16DataPH->ReserveNow[gun_index].ResponseStatus);
  3172. ShmOCPP16DataPH->CsMsg.bits[gun_index].ReserveNowConf = 0;
  3173. }
  3174. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq == 1) && (access("/Storage/OCPP_PH/certCP.csr",F_OK) != -1))
  3175. {
  3176. sendSignCertificateRequest();
  3177. }
  3178. }
  3179. }
  3180. //==========================================
  3181. // send request routine
  3182. //==========================================
  3183. int sendAuthorizeRequest(int gun_index)
  3184. {
  3185. mtrace();
  3186. int result = FAIL;
  3187. char message[100]={0};
  3188. char guid[37];
  3189. char tempdata[65]={0};
  3190. DEBUG_INFO("sendAuthorizeRequest...\n");
  3191. memset(&(ShmOCPP16DataPH->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  3192. //Local Authorize
  3193. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16DataPH->OcppConnStatus == 0))
  3194. {
  3195. DEBUG_INFO("Allow OfflineTx UnknownId Pass.\n");
  3196. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  3197. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  3198. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Accepted");
  3199. result = PASS;
  3200. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3201. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3202. authorizeRetryTimes = 0;
  3203. return result;
  3204. }
  3205. 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))||
  3206. ((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  3207. {
  3208. // Query from cache
  3209. DEBUG_INFO("Authorize from cache.\n");
  3210. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3211. // Query from list
  3212. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3213. {
  3214. DEBUG_INFO("Authorize from list.\n");
  3215. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3216. }
  3217. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  3218. {
  3219. if(strcmp(idTagQuery.idTagstr,"") == 0)
  3220. {
  3221. DEBUG_INFO("Local Authorization Fail, Card %s is not in local cache and list.\n", ShmSysConfigAndInfo->SysConfig.UserId);
  3222. }
  3223. else if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  3224. {
  3225. DEBUG_INFO("Local Authorization Fail, Card %s is not Accepted.\n", idTagQuery.idTagstr);
  3226. }
  3227. if(!GetOcppConnStatus())
  3228. {
  3229. DEBUG_INFO("off-line Local Authorization Fail.\n");
  3230. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3231. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3232. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Invalid");
  3233. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3234. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3235. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3236. authorizeRetryTimes = 0;
  3237. return result;
  3238. }
  3239. }
  3240. else
  3241. {
  3242. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  3243. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  3244. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, idTagQuery.parentIdTag);
  3245. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  3246. sprintf((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, "Expired");
  3247. else
  3248. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  3249. DEBUG_INFO("ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status);
  3250. result = PASS;
  3251. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3252. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  3253. authorizeRetryTimes = 0;
  3254. return result;
  3255. }
  3256. }
  3257. //initialize struct Authorize
  3258. memset(&(ShmOCPP16DataPH->Authorize), 0 , sizeof(struct StructAuthorize));
  3259. //get data from shared memory
  3260. strcpy((char *)ShmOCPP16DataPH->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3261. random_uuid(guid);
  3262. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16DataPH->Authorize.IdTag);
  3263. LWS_Send(message);
  3264. sprintf(tempdata, "Authorize,%d", gun_index);
  3265. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3266. {
  3267. result = PASS;
  3268. DEBUG_INFO("Authorize mapItem pass\n");
  3269. }
  3270. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  3271. return result;
  3272. }
  3273. int sendBootNotificationRequest(void)
  3274. {
  3275. mtrace();
  3276. int result = FAIL;
  3277. char message[500]={0}, payload[700]={0};
  3278. char guid[37]={0};
  3279. char tempdata[65]={0};
  3280. // Fill BootNotification fields
  3281. strcpy((char *)ShmOCPP16DataPH->BootNotification.CbSN,(const char *)ShmOCPP16DataPH->ChargeBoxId);
  3282. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  3283. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  3284. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3285. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  3286. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  3287. strcpy((char *)ShmOCPP16DataPH->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  3288. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  3289. ShmOCPP16DataPH->ChargeBoxId
  3290. ,ShmSysConfigAndInfo->SysConfig.ModelName
  3291. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  3292. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  3293. ,ShmOCPP16DataPH->BootNotification.CpFwVersion
  3294. ,ShmOCPP16DataPH->BootNotification.CpIccid
  3295. ,ShmOCPP16DataPH->BootNotification.CpImsi);
  3296. random_uuid(guid);
  3297. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  3298. LWS_Send(message);
  3299. sprintf(tempdata, "BootNotification,0");
  3300. 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*/)
  3301. {
  3302. result = PASS;
  3303. }
  3304. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3305. strcpy(queuedata,message);
  3306. return result;
  3307. }
  3308. int sendDataTransferRequest(int gun_index)
  3309. {
  3310. mtrace();
  3311. char message[1000]={0};
  3312. char guid[37]={0};
  3313. char tempdata[65]={0};
  3314. int result = FAIL;
  3315. random_uuid(guid);
  3316. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  3317. MESSAGE_TYPE_CALL,
  3318. guid,
  3319. ShmOCPP16DataPH->DataTransfer[gun_index].VendorId,
  3320. ShmOCPP16DataPH->DataTransfer[gun_index].MessageId,
  3321. ShmOCPP16DataPH->DataTransfer[gun_index].Data);
  3322. LWS_Send(message);
  3323. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  3324. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3325. {
  3326. result = PASS;
  3327. DEBUG_INFO("DataTransfer mapItem pass\n");
  3328. }
  3329. return result;
  3330. }
  3331. int sendDiagnosticsStatusNotificationRequest(char *status)
  3332. {
  3333. mtrace();
  3334. int result = FAIL;
  3335. char message[110]={0};
  3336. char guid[37]={0};
  3337. char tempdata[65]={0};
  3338. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  3339. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest...\n");
  3340. sprintf((char *)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  3341. random_uuid(guid);
  3342. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  3343. LWS_SendNow(message);
  3344. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  3345. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3346. {
  3347. result = PASS;
  3348. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  3349. }
  3350. //#ifdef SystemLogMessage
  3351. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  3352. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3353. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  3354. //#endif
  3355. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  3356. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  3357. //record status
  3358. if(strcmp(status,"Idle")==0)
  3359. {
  3360. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  3361. }
  3362. else if(strcmp(status,"Uploaded")==0)
  3363. {
  3364. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  3365. }
  3366. else if(strcmp(status,"UploadFailed")==0)
  3367. {
  3368. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  3369. }
  3370. else if(strcmp(status,"Uploading")==0)
  3371. {
  3372. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  3373. }
  3374. return result;
  3375. }
  3376. int sendFirmwareStatusNotificationRequest(char *status)
  3377. {
  3378. mtrace();
  3379. int result = FAIL;
  3380. char message[110]={0};
  3381. char guid[37]={0};
  3382. char tempdata[65]={0};
  3383. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  3384. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  3385. sprintf((char *)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", (const char *)status);
  3386. random_uuid(guid);
  3387. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  3388. LWS_SendNow(message);
  3389. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  3390. 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*/)
  3391. {
  3392. result = PASS;
  3393. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  3394. }
  3395. //#ifdef SystemLogMessage
  3396. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  3397. //DEBUG_INFO("Message: %s\n", SendBuffer);
  3398. //#endif
  3399. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  3400. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  3401. //record status
  3402. if(strcmp(status,"Downloaded")==0)
  3403. {
  3404. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  3405. }
  3406. else if(strcmp(status,"DownloadFailed")==0)
  3407. {
  3408. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  3409. }
  3410. else if(strcmp(status,"Downloading")==0)
  3411. {
  3412. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  3413. }
  3414. else if(strcmp(status,"Idle")==0)
  3415. {
  3416. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  3417. }
  3418. else if(strcmp(status,"InstallationFailed")==0)
  3419. {
  3420. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  3421. }
  3422. else if(strcmp(status,"Installing")==0)
  3423. {
  3424. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  3425. }
  3426. else if(strcmp(status,"Installed")==0)
  3427. {
  3428. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  3429. }
  3430. return result;
  3431. }
  3432. int sendHeartbeatRequest(int gun_index)
  3433. {
  3434. mtrace();
  3435. int result = FAIL;
  3436. char message[80]={0};
  3437. char guid[37]={0};
  3438. char tempdata[65]={0};
  3439. random_uuid(guid);
  3440. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  3441. , MESSAGE_TYPE_CALL
  3442. , guid );
  3443. LWS_Send(message);
  3444. sprintf(tempdata, "Heartbeat,%d", 0);
  3445. 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*/)
  3446. {
  3447. result = PASS;
  3448. }
  3449. return result;
  3450. }
  3451. int sendStartTransactionRequest(int gun_index)
  3452. {
  3453. mtrace();
  3454. int result = FAIL;
  3455. char message[250]={0};
  3456. char guid[37]={0};
  3457. struct timeval tmnow;
  3458. struct tm *tm;
  3459. char buf[28];//, usec_buf[6];
  3460. char tempdata[65]={0};
  3461. int tempIndex = 0;
  3462. DEBUG_INFO("sendStartTransactionRequest...\n");
  3463. gettimeofday(&tmnow, NULL);
  3464. time_t t;
  3465. t = time(NULL);
  3466. /*UTC time and date*/
  3467. tm = gmtime(&t);
  3468. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3469. #if 0 // remove temporally
  3470. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3471. strcat(buf,".");
  3472. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3473. strcat(buf,usec_buf);
  3474. #endif
  3475. ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  3476. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp, buf);
  3477. //strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  3478. // clear StartTransaction Response
  3479. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  3480. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  3481. strcpy((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  3482. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = 0;
  3483. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  3484. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3485. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3486. {
  3487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3488. {
  3489. tempIndex = ((gun_index==2) ? 1: 0);
  3490. }
  3491. else
  3492. {
  3493. tempIndex = gun_index;
  3494. }
  3495. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3496. {
  3497. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3498. {
  3499. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3500. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  3501. }
  3502. }
  3503. }
  3504. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3505. {
  3506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3507. {
  3508. tempIndex = ((gun_index==2) ? 1: 0);
  3509. }
  3510. else
  3511. {
  3512. tempIndex = gun_index;
  3513. }
  3514. for (int index = 0; index < CCS_QUANTITY; index++)
  3515. {
  3516. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3517. {
  3518. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3519. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3520. }
  3521. }
  3522. }
  3523. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3524. {
  3525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3526. {
  3527. tempIndex = ((gun_index==2) ? 1: 0);
  3528. }
  3529. else
  3530. {
  3531. tempIndex = gun_index;
  3532. }
  3533. for (int index = 0; index < GB_QUANTITY; index++)
  3534. {
  3535. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3536. {
  3537. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3538. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3539. }
  3540. }
  3541. }
  3542. else if(gunType[gun_index] == GUN_TYPE_DO)
  3543. {
  3544. tempIndex = gun_index;
  3545. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3546. {
  3547. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3548. {
  3549. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3550. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  3551. }
  3552. }
  3553. }
  3554. else
  3555. {
  3556. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3557. {
  3558. tempIndex = 2;
  3559. }
  3560. else
  3561. {
  3562. tempIndex = gun_index;
  3563. }
  3564. for (int index = 0; index < AC_QUANTITY; index++)
  3565. {
  3566. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3567. {
  3568. ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3569. ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3570. }
  3571. }
  3572. }
  3573. random_uuid(guid);
  3574. if(ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3575. {
  3576. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3577. , gun_index +1
  3578. , MESSAGE_TYPE_CALL
  3579. , guid
  3580. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  3581. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  3582. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  3583. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  3584. }
  3585. else
  3586. {
  3587. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3588. , gun_index +1
  3589. , MESSAGE_TYPE_CALL
  3590. , guid
  3591. , ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId
  3592. , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag
  3593. , ShmOCPP16DataPH->StartTransaction[gun_index].MeterStart
  3594. , ShmOCPP16DataPH->StartTransaction[gun_index].ReservationId
  3595. , ShmOCPP16DataPH->StartTransaction[gun_index].Timestamp );
  3596. }
  3597. #if 1
  3598. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3599. 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*/)
  3600. {
  3601. result = PASS;
  3602. }
  3603. #endif
  3604. strcpy(queuedata, message);
  3605. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3606. OCPP_insert_transaction_msg(YES, queuedata);
  3607. return result;
  3608. }
  3609. int sendStatusNotificationRequest(int gun_index)
  3610. {
  3611. mtrace();
  3612. int result = FAIL;
  3613. char message[600]={0};
  3614. char guid[37];
  3615. int currentStatus = 0;
  3616. struct timeval tmnow;
  3617. struct tm *tm;
  3618. char buf[28];//, usec_buf[6];
  3619. char tempdata[65]={0};
  3620. int tempIndex = 0;
  3621. uint8_t isStateChanged = TRUE;
  3622. DEBUG_INFO("sendStatusNotificationRequest...\n");
  3623. gettimeofday(&tmnow, NULL);
  3624. time_t t;
  3625. t = time(NULL);
  3626. /*UTC time and date*/
  3627. tm = gmtime(&t);
  3628. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3629. #if 0 // remove temporally
  3630. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3631. strcat(buf,".");
  3632. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3633. strcat(buf,usec_buf);
  3634. #endif
  3635. //printf("%s",buf);
  3636. ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3637. //strcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3638. // it's option
  3639. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Info, "");
  3640. /*
  3641. enum _SYSTEM_STATUS
  3642. {
  3643. S_BOOTING = 0,
  3644. S_IDLE, = 1
  3645. S_AUTHORIZING, =2
  3646. S_REASSIGN_CHECK, =3
  3647. S_REASSIGN, =4
  3648. S_PRECHARGE, =5
  3649. S_PREPARING_FOR_EV, =6
  3650. S_PREPARING_FOR_EVSE, =7
  3651. S_CHARGING, =8
  3652. S_TERMINATING, =9
  3653. S_COMPLETE, =10
  3654. S_ALARM, =11
  3655. S_FAULT =12
  3656. }
  3657. */
  3658. //check Transaction active
  3659. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3660. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  3661. {
  3662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3663. {
  3664. tempIndex = ((gun_index==2) ? 1: 0);
  3665. }
  3666. else
  3667. {
  3668. tempIndex = gun_index;
  3669. }
  3670. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3671. {
  3672. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3673. {
  3674. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3675. {
  3676. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3677. {
  3678. currentStatus = Preparing; //OCPP Status: Preparing
  3679. }
  3680. else
  3681. {
  3682. currentStatus = Available; //OCPP Status: Available
  3683. }
  3684. }
  3685. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3686. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3687. ) //S_PRECHARGE
  3688. {
  3689. currentStatus = Preparing; //OCPP Status: Preparing
  3690. }
  3691. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3692. {
  3693. currentStatus = Charging; //OCPP Status: Charging
  3694. }
  3695. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3696. {
  3697. currentStatus = Finishing; //OCPP Status: Finishing
  3698. }
  3699. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3700. {
  3701. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3702. }
  3703. 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
  3704. {
  3705. currentStatus = Unavailable; //OCPP Status: Unavailable
  3706. }
  3707. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3708. {
  3709. currentStatus = Faulted; //OCPP Status: Faulted
  3710. }
  3711. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3712. {
  3713. currentStatus = Reserved; //OCPP Status: Reserved
  3714. }
  3715. } //end of the same index
  3716. }//end of for CHAdeMO_QUANTITY
  3717. }
  3718. else if(gunType[gun_index] == GUN_TYPE_CCS)
  3719. {
  3720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3721. {
  3722. tempIndex = ((gun_index==2) ? 1: 0);
  3723. }
  3724. else
  3725. {
  3726. tempIndex = gun_index;
  3727. }
  3728. for (int index = 0; index < CCS_QUANTITY; index++)
  3729. {
  3730. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3731. {
  3732. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3733. {
  3734. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3735. {
  3736. currentStatus = Preparing; //OCPP Status: Preparing
  3737. }
  3738. else
  3739. {
  3740. currentStatus = Available; //OCPP Status: Available
  3741. }
  3742. }
  3743. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3744. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3745. ) //S_PRECHARGE
  3746. {
  3747. currentStatus = Preparing; //OCPP Status: Preparing
  3748. }
  3749. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3750. {
  3751. currentStatus = Charging; //OCPP Status: Charging
  3752. }
  3753. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3754. {
  3755. currentStatus = Finishing; //OCPP Status: Finishing
  3756. }
  3757. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3758. {
  3759. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3760. }
  3761. 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
  3762. {
  3763. currentStatus = Unavailable; //OCPP Status : Unavailable
  3764. }
  3765. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3766. {
  3767. currentStatus = Faulted; //OCPP Status: Faulted
  3768. }
  3769. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3770. {
  3771. currentStatus = Reserved; //OCPP Status: Reserved
  3772. }
  3773. } //end of the same index
  3774. } // end of for CCS_QUANTITY
  3775. }
  3776. else if(gunType[gun_index] == GUN_TYPE_GBT)
  3777. {
  3778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3779. {
  3780. tempIndex = ((gun_index==2) ? 1: 0);
  3781. }
  3782. else
  3783. {
  3784. tempIndex = gun_index;
  3785. }
  3786. for (int index = 0; index < GB_QUANTITY; index++)
  3787. {
  3788. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3789. {
  3790. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3791. {
  3792. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3793. {
  3794. currentStatus = Preparing; //OCPP Status: Preparing
  3795. }
  3796. else
  3797. {
  3798. currentStatus = Available; //OCPP Status: Available
  3799. }
  3800. }
  3801. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3802. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3803. ) //S_PRECHARGE
  3804. {
  3805. currentStatus = Preparing; //OCPP Status: Preparing
  3806. }
  3807. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3808. {
  3809. currentStatus = Charging; //OCPP Status: Charging
  3810. }
  3811. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3812. {
  3813. currentStatus = Finishing; //OCPP Status: Finishing
  3814. }
  3815. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3816. {
  3817. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3818. }
  3819. 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
  3820. {
  3821. currentStatus = Unavailable; //OCPP Status: Unavailable
  3822. }
  3823. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3824. {
  3825. currentStatus = Faulted; //OCPP Status: Faulted
  3826. }
  3827. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3828. {
  3829. currentStatus = Reserved; //OCPP Status: Reserved
  3830. }
  3831. } //end of the same index
  3832. } // end of for GB_QUANTITY
  3833. }
  3834. else if(gunType[gun_index] == GUN_TYPE_DO)
  3835. {
  3836. tempIndex = gun_index;
  3837. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3838. {
  3839. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3840. {
  3841. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3842. {
  3843. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3844. {
  3845. currentStatus = Preparing; //OCPP Status: Preparing
  3846. }
  3847. else
  3848. {
  3849. currentStatus = Available; //OCPP Status: Available
  3850. }
  3851. }
  3852. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3853. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3854. ) //S_PRECHARGE
  3855. {
  3856. currentStatus = Preparing; //OCPP Status: Preparing
  3857. }
  3858. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3859. {
  3860. currentStatus = Charging; //OCPP Status: Charging
  3861. }
  3862. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3863. {
  3864. currentStatus = Finishing; //OCPP Status: Finishing
  3865. }
  3866. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3867. {
  3868. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3869. }
  3870. 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
  3871. {
  3872. currentStatus = Unavailable; //OCPP Status: Unavailable
  3873. }
  3874. 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
  3875. {
  3876. currentStatus = Faulted; //OCPP Status: Faulted
  3877. }
  3878. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3879. {
  3880. currentStatus = Reserved; //OCPP Status: Reserved
  3881. }
  3882. } //end of the same index
  3883. }
  3884. }
  3885. else
  3886. {
  3887. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3888. {
  3889. tempIndex = 2;
  3890. }
  3891. else
  3892. {
  3893. tempIndex = gun_index;
  3894. }
  3895. for (int index = 0; index < AC_QUANTITY; index++)
  3896. {
  3897. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3898. {
  3899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3900. {
  3901. 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))
  3902. {
  3903. currentStatus = Preparing; //OCPP Status: Preparing
  3904. }
  3905. else
  3906. {
  3907. currentStatus = Available; //OCPP Status: Available
  3908. }
  3909. }
  3910. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3911. {
  3912. currentStatus = Preparing; //OCPP Status: Preparing
  3913. }
  3914. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3915. {
  3916. currentStatus = Charging; //OCPP Status: Charging
  3917. }
  3918. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3919. {
  3920. currentStatus = Finishing; //OCPP Status: Finishing
  3921. }
  3922. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3923. {
  3924. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B))
  3925. currentStatus = SuspendedEV; //OCPP Status: SuspendedEV
  3926. else
  3927. currentStatus = SuspendedEVSE; //OCPP Status: SuspendedEVSE
  3928. }
  3929. 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
  3930. {
  3931. currentStatus = Unavailable; //OCPP Status: Unavailable
  3932. }
  3933. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3934. {
  3935. currentStatus = Faulted; //OCPP Status: Faulted
  3936. }
  3937. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3938. {
  3939. currentStatus = Reserved; //OCPP Status: Reserved
  3940. }
  3941. }//end of the same index
  3942. }//end of for AC_QUANTITY
  3943. }
  3944. //it's option
  3945. if(((strstr((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]) != NULL) || (((currentStatus == SuspendedEV) || (currentStatus == SuspendedEVSE)) && ShmOCPP16DataPH->CsMsg.bits[gun_index].RemoteStopTransactionReq)) &&
  3946. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  3947. {
  3948. isStateChanged = FALSE;
  3949. }
  3950. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3951. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp, buf);
  3952. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].VendorId, (char*)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  3953. strcpy((char *)ShmOCPP16DataPH->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3954. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode, ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode));
  3955. memcpy(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode, ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, ARRAY_SIZE(ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode));
  3956. random_uuid(guid);
  3957. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3958. , MESSAGE_TYPE_CALL
  3959. , guid
  3960. , ShmOCPP16DataPH->StatusNotification[gun_index].ConnectorId
  3961. , ShmOCPP16DataPH->StatusNotification[gun_index].ErrorCode
  3962. , ShmOCPP16DataPH->StatusNotification[gun_index].Info
  3963. , ShmOCPP16DataPH->StatusNotification[gun_index].Status
  3964. , ShmOCPP16DataPH->StatusNotification[gun_index].Timestamp
  3965. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorId
  3966. , ShmOCPP16DataPH->StatusNotification[gun_index].VendorErrorCode);
  3967. if((server_sign == TRUE) && isStateChanged)
  3968. {
  3969. LWS_Send(message);
  3970. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3971. 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*/)
  3972. {
  3973. //DEBUG_ERROR("statusNotification mapitem pass");
  3974. result = PASS;
  3975. }
  3976. }
  3977. else
  3978. {
  3979. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  3980. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  3981. result = PASS;
  3982. }
  3983. return result;
  3984. }
  3985. int sendStopTransactionRequest(int gun_index)
  3986. {
  3987. mtrace();
  3988. int result = FAIL;
  3989. //char message[1500]={0};
  3990. char guid[37]={0};
  3991. char tempdata[65]={0};
  3992. int tempIndex = 0;
  3993. char TempStopTransaction[256];
  3994. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  3995. //int idx_sample=0;
  3996. DEBUG_INFO("sendStopTransactionRequest \n");
  3997. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3998. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  3999. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  4000. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4001. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4002. {
  4003. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4004. {
  4005. tempIndex = ((gun_index==2) ? 1: 0);
  4006. }
  4007. else
  4008. {
  4009. tempIndex = gun_index;
  4010. }
  4011. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4012. {
  4013. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4014. {
  4015. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  4016. }
  4017. }// END OF CHAdeMO_QUANTITY
  4018. }
  4019. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4020. {
  4021. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4022. {
  4023. tempIndex = ((gun_index==2) ? 1: 0);
  4024. }
  4025. else
  4026. {
  4027. tempIndex = gun_index;
  4028. }
  4029. for (int index = 0; index < CCS_QUANTITY; index++)
  4030. {
  4031. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4032. {
  4033. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  4034. }
  4035. }// END OF CCS_QUANTITY
  4036. }
  4037. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4038. {
  4039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4040. {
  4041. tempIndex = ((gun_index==2) ? 1: 0);
  4042. }
  4043. else
  4044. {
  4045. tempIndex = gun_index;
  4046. }
  4047. for (int index = 0; index < GB_QUANTITY; index++)
  4048. {
  4049. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4050. {
  4051. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  4052. }
  4053. }// END OF GB_QUANTITY
  4054. }
  4055. else if(gunType[gun_index] == GUN_TYPE_DO)
  4056. {
  4057. tempIndex = gun_index;
  4058. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4059. {
  4060. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4061. {
  4062. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  4063. }
  4064. }// END OF GB_QUANTITY
  4065. }
  4066. else
  4067. {
  4068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4069. {
  4070. tempIndex = 2;
  4071. }
  4072. else
  4073. {
  4074. tempIndex = gun_index;
  4075. }
  4076. for (int index = 0; index < AC_QUANTITY; index++)
  4077. {
  4078. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4079. {
  4080. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  4081. }
  4082. }// END OF AC_QUANTITY
  4083. }
  4084. //====================================== Stop Transaction Time =====================================================
  4085. struct timeval tmnow;
  4086. struct tm *tm;
  4087. char buf[28];//, usec_buf[6];
  4088. gettimeofday(&tmnow, NULL);
  4089. time_t t;
  4090. t = time(NULL);
  4091. /*UTC time and date*/
  4092. tm = gmtime(&t);
  4093. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4094. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  4095. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  4096. random_uuid(guid);
  4097. /***********************************transactionData******************************************************/
  4098. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  4099. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  4100. //=================================
  4101. // Transaction_Begin
  4102. //=================================
  4103. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4104. {
  4105. //============================================ Energy.Active.Import.Interval ================================
  4106. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  4107. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4108. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  4109. 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*/]);
  4110. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4111. 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))
  4112. {
  4113. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  4114. }
  4115. else
  4116. {
  4117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  4118. }
  4119. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  4120. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4121. }
  4122. //=================================
  4123. // Transaction_End
  4124. //=================================
  4125. // ================================= Current.Import L1 ===============================================
  4126. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4127. {
  4128. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  4129. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4130. {
  4131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4132. {
  4133. tempIndex = ((gun_index==2) ? 1: 0);
  4134. }
  4135. else
  4136. {
  4137. tempIndex = gun_index;
  4138. }
  4139. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4140. {
  4141. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4142. {
  4143. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4144. }
  4145. }// End of for CHAdeMO_QUANTITY
  4146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4147. }
  4148. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4149. {
  4150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4151. {
  4152. tempIndex = ((gun_index==2) ? 1: 0);
  4153. }
  4154. else
  4155. {
  4156. tempIndex = gun_index;
  4157. }
  4158. for (int index = 0; index < CCS_QUANTITY; index++)
  4159. {
  4160. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4161. {
  4162. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4163. }
  4164. }// End of for CCS_QUANTITY
  4165. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4166. }
  4167. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4168. {
  4169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4170. {
  4171. tempIndex = ((gun_index==2) ? 1: 0);
  4172. }
  4173. else
  4174. {
  4175. tempIndex = gun_index;
  4176. }
  4177. for (int index = 0; index < GB_QUANTITY; index++)
  4178. {
  4179. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4180. {
  4181. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4182. }
  4183. }// End of for GB_QUANTITY
  4184. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4185. }
  4186. else if(gunType[gun_index] == GUN_TYPE_DO)
  4187. {
  4188. tempIndex = gun_index;
  4189. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4190. {
  4191. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4192. {
  4193. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  4194. }
  4195. }
  4196. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  4197. }
  4198. else
  4199. {
  4200. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4201. {
  4202. tempIndex = 2;
  4203. }
  4204. else
  4205. {
  4206. tempIndex = gun_index;
  4207. }
  4208. for (int index = 0; index < AC_QUANTITY; index++)
  4209. {
  4210. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4211. {
  4212. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  4213. }
  4214. }// End of for AC_QUANTITY
  4215. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  4216. }
  4217. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4218. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  4219. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  4220. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  4221. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4222. }
  4223. // ================================= Energy.Active.Import.Interval ==============================================
  4224. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  4225. {
  4226. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4227. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4228. {
  4229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4230. {
  4231. tempIndex = ((gun_index==2) ? 1: 0);
  4232. }
  4233. else
  4234. {
  4235. tempIndex = gun_index;
  4236. }
  4237. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4238. {
  4239. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4240. {
  4241. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4242. }
  4243. }// END OF CHAdeMO_QUANTITY
  4244. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4245. }
  4246. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4247. {
  4248. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4249. {
  4250. tempIndex = ((gun_index==2) ? 1: 0);
  4251. }
  4252. else
  4253. {
  4254. tempIndex = gun_index;
  4255. }
  4256. for (int index = 0; index < CCS_QUANTITY; index++)
  4257. {
  4258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4259. {
  4260. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4261. }
  4262. }// END OF CCS_QUANTITY
  4263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4264. }
  4265. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4266. {
  4267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4268. {
  4269. tempIndex = ((gun_index==2) ? 1: 0);
  4270. }
  4271. else
  4272. {
  4273. tempIndex = gun_index;
  4274. }
  4275. for (int index = 0; index < GB_QUANTITY; index++)
  4276. {
  4277. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4278. {
  4279. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4280. }
  4281. }// END OF GB_QUANTITY
  4282. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4283. }
  4284. else if(gunType[gun_index] == GUN_TYPE_DO)
  4285. {
  4286. tempIndex = gun_index;
  4287. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4288. {
  4289. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4290. {
  4291. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4292. }
  4293. }
  4294. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  4295. }
  4296. else
  4297. {
  4298. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4299. {
  4300. tempIndex = 2;
  4301. }
  4302. else
  4303. {
  4304. tempIndex = gun_index;
  4305. }
  4306. for (int index = 0; index < AC_QUANTITY; index++)
  4307. {
  4308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4309. {
  4310. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  4311. }
  4312. }// END OF AC_QUANTITY
  4313. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  4314. }
  4315. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4316. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  4317. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  4318. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  4319. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4320. }
  4321. //=================================== Power.Active.Import ==================================================
  4322. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  4323. {
  4324. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4325. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4326. {
  4327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4328. {
  4329. tempIndex = ((gun_index==2) ? 1: 0);
  4330. }
  4331. else
  4332. {
  4333. tempIndex = gun_index;
  4334. }
  4335. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4336. {
  4337. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4338. {
  4339. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4340. }
  4341. } // End for CHAdeMO_QUANTITY
  4342. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4343. }
  4344. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4345. {
  4346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4347. {
  4348. tempIndex = ((gun_index==2) ? 1: 0);
  4349. }
  4350. else
  4351. {
  4352. tempIndex = gun_index;
  4353. }
  4354. for (int index = 0; index < CCS_QUANTITY; index++)
  4355. {
  4356. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4357. {
  4358. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4359. }
  4360. } // END for CCS_QUANTITY
  4361. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4362. }
  4363. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4364. {
  4365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4366. {
  4367. tempIndex = ((gun_index==2) ? 1: 0);
  4368. }
  4369. else
  4370. {
  4371. tempIndex = gun_index;
  4372. }
  4373. for (int index = 0; index < GB_QUANTITY; index++)
  4374. {
  4375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4376. {
  4377. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4378. }
  4379. }// END for GB_QUANTITY
  4380. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4381. }
  4382. else if(gunType[gun_index] == GUN_TYPE_DO)
  4383. {
  4384. tempIndex = gun_index;
  4385. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4386. {
  4387. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4388. {
  4389. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4390. }
  4391. }
  4392. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  4393. }
  4394. else
  4395. {
  4396. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4397. {
  4398. tempIndex = 2;
  4399. }
  4400. else
  4401. {
  4402. tempIndex = gun_index;
  4403. }
  4404. for (int index = 0; index < AC_QUANTITY; index++)
  4405. {
  4406. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4407. {
  4408. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  4409. }
  4410. } // END for AC_QUANTITY
  4411. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  4412. }
  4413. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4414. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  4415. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  4416. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  4417. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  4418. }
  4419. //============================ Voltage L1 ====================================
  4420. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4421. {
  4422. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4423. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4424. {
  4425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4426. {
  4427. tempIndex = ((gun_index==2) ? 1: 0);
  4428. }
  4429. else
  4430. {
  4431. tempIndex = gun_index;
  4432. }
  4433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4434. {
  4435. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4436. {
  4437. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4438. }
  4439. } // END OF FOR CHAdeMO_QUANTITY
  4440. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4441. }
  4442. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4443. {
  4444. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4445. {
  4446. tempIndex = ((gun_index==2) ? 1: 0);
  4447. }
  4448. else
  4449. {
  4450. tempIndex = gun_index;
  4451. }
  4452. for (int index = 0; index < CCS_QUANTITY; index++)
  4453. {
  4454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4455. {
  4456. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4457. }
  4458. } // END OF FOR CCS_QUANTITY
  4459. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4460. }
  4461. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4462. {
  4463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4464. {
  4465. tempIndex = ((gun_index==2) ? 1: 0);
  4466. }
  4467. else
  4468. {
  4469. tempIndex = gun_index;
  4470. }
  4471. for (int index = 0; index < GB_QUANTITY; index++)
  4472. {
  4473. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4474. {
  4475. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4476. }
  4477. } // END OF FOR GB_QUANTITY
  4478. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4479. }
  4480. else if(gunType[gun_index] == GUN_TYPE_DO)
  4481. {
  4482. tempIndex = gun_index;
  4483. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4484. {
  4485. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4486. {
  4487. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  4488. }
  4489. }
  4490. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  4491. }
  4492. else
  4493. {
  4494. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4495. {
  4496. tempIndex = 2;
  4497. }
  4498. else
  4499. {
  4500. tempIndex = gun_index;
  4501. }
  4502. for (int index = 0; index < AC_QUANTITY; index++)
  4503. {
  4504. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4505. {
  4506. 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
  4507. }
  4508. } // END OF FOR AC_QUANTITY
  4509. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  4510. }
  4511. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4512. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  4513. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  4514. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  4515. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4516. }
  4517. //====================== End SoC ================================
  4518. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4519. {
  4520. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4521. 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))
  4522. {
  4523. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4524. {
  4525. tempIndex = ((gun_index==2) ? 1: 0);
  4526. }
  4527. else
  4528. {
  4529. tempIndex = gun_index;
  4530. }
  4531. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4532. {
  4533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4534. {
  4535. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4536. {
  4537. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  4538. }
  4539. }
  4540. }
  4541. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4542. {
  4543. for (int index = 0; index < CCS_QUANTITY; index++)
  4544. {
  4545. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4546. {
  4547. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  4548. }
  4549. }
  4550. }
  4551. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4552. {
  4553. for (int index = 0; index < GB_QUANTITY; index++)
  4554. {
  4555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4556. {
  4557. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  4558. }
  4559. }
  4560. }
  4561. else if(gunType[gun_index] == GUN_TYPE_DO)
  4562. {
  4563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4564. {
  4565. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4566. {
  4567. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  4568. }
  4569. }
  4570. }
  4571. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4572. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  4573. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4574. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  4575. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  4576. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4577. } // END FOR DC CASE
  4578. }
  4579. // ================================= Current.Import L2 ===============================================
  4580. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4581. {
  4582. // AC 3 phse L2 current
  4583. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4584. {
  4585. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4586. {
  4587. tempIndex = 2;
  4588. }
  4589. else
  4590. {
  4591. tempIndex = gun_index;
  4592. }
  4593. for (int index = 0; index < AC_QUANTITY; index++)
  4594. {
  4595. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4596. {
  4597. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4598. }
  4599. }// End of for AC_QUANTITY
  4600. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4601. }
  4602. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4604. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4605. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4606. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4607. }
  4608. // ================================= Current.Import L3 ===============================================
  4609. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  4610. {
  4611. // AC 3 phse L3 current
  4612. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4613. {
  4614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4615. {
  4616. tempIndex = 2;
  4617. }
  4618. else
  4619. {
  4620. tempIndex = gun_index;
  4621. }
  4622. for (int index = 0; index < AC_QUANTITY; index++)
  4623. {
  4624. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4625. {
  4626. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4627. }
  4628. }// End of for AC_QUANTITY
  4629. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4630. }
  4631. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4632. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4633. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4634. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4635. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4636. }
  4637. //============================ Voltage L2 ====================================
  4638. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4639. {
  4640. // AC 3 phse L2 voltage
  4641. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4642. {
  4643. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4644. {
  4645. tempIndex = 2;
  4646. }
  4647. else
  4648. {
  4649. tempIndex = gun_index;
  4650. }
  4651. for (int index = 0; index < AC_QUANTITY; index++)
  4652. {
  4653. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4654. {
  4655. 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
  4656. }
  4657. } // END OF FOR AC_QUANTITY
  4658. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4659. }
  4660. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4661. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4662. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4663. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4664. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4665. }
  4666. //============================ Voltage L3 ====================================
  4667. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  4668. {
  4669. // AC 3 phse L3 voltage
  4670. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  4671. {
  4672. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4673. {
  4674. tempIndex = 2;
  4675. }
  4676. else
  4677. {
  4678. tempIndex = gun_index;
  4679. }
  4680. for (int index = 0; index < AC_QUANTITY; index++)
  4681. {
  4682. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4683. {
  4684. 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
  4685. }
  4686. } // END OF FOR AC_QUANTITY
  4687. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4688. }
  4689. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4690. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4691. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4692. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4693. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4694. }
  4695. //====================== Start SoC ================================
  4696. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  4697. {
  4698. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4699. 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))
  4700. {
  4701. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  4702. {
  4703. tempIndex = ((gun_index==2) ? 1: 0);
  4704. }
  4705. else
  4706. {
  4707. tempIndex = gun_index;
  4708. }
  4709. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4710. {
  4711. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4712. {
  4713. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4714. {
  4715. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4716. }
  4717. }
  4718. }
  4719. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4720. {
  4721. for (int index = 0; index < CCS_QUANTITY; index++)
  4722. {
  4723. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4724. {
  4725. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4726. }
  4727. }
  4728. }
  4729. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4730. {
  4731. for (int index = 0; index < GB_QUANTITY; index++)
  4732. {
  4733. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4734. {
  4735. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4736. }
  4737. }
  4738. }
  4739. else if(gunType[gun_index] == GUN_TYPE_DO)
  4740. {
  4741. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4742. {
  4743. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4744. {
  4745. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4746. }
  4747. }
  4748. }
  4749. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4750. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4751. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4752. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4754. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4755. } // END FOR DC CASE
  4756. }
  4757. //================================================ Message create ====================================================
  4758. json_object *StopTransaction = json_object_new_object();
  4759. json_object *transactionDatas = json_object_new_array();
  4760. json_object *sampledValues = json_object_new_array();
  4761. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  4762. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  4763. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  4764. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  4765. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  4766. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason) > 0)
  4767. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].StopReason));
  4768. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  4769. {
  4770. json_object *transactionData = json_object_new_object();
  4771. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4772. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4773. {
  4774. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4775. {
  4776. json_object *sampledValue = json_object_new_object();
  4777. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4778. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4779. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4780. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4781. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4782. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4783. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4784. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4785. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4786. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4787. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4788. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4789. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4790. json_object_array_add(sampledValues, sampledValue);
  4791. }
  4792. }
  4793. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4794. json_object_array_add(transactionDatas, transactionData);
  4795. }
  4796. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4797. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4798. ,MESSAGE_TYPE_CALL
  4799. ,guid
  4800. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4801. json_object_put(StopTransaction);
  4802. #if 1 // for TempStopTransaction
  4803. //Delete TempStopTransaction
  4804. if((access(TempStopTransaction,F_OK))!=-1)
  4805. {
  4806. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4807. }
  4808. #endif
  4809. #if 1
  4810. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4811. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4812. {
  4813. result = PASS;
  4814. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4815. }
  4816. #endif
  4817. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4818. OCPP_insert_transaction_msg(NO, queuedata);
  4819. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4820. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StopTransaction[gun_index].IdTag);
  4821. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, TRUE);
  4822. if((ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4823. {
  4824. SetTransactionIdZero(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId);
  4825. }
  4826. //for test
  4827. //ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4828. return result;
  4829. }
  4830. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4831. {
  4832. mtrace();
  4833. int result = FAIL;
  4834. char guid[37]={0};
  4835. char tempdata[65]={0};
  4836. int tempIndex = 0;
  4837. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4838. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4839. memset(&ShmOCPP16DataPH->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4840. //set value
  4841. ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4842. 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) )?
  4843. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId :
  4844. -1);
  4845. random_uuid(guid);
  4846. //UTC Date time
  4847. struct timeval tmnow;
  4848. struct tm *tm;
  4849. char buf[28];//, usec_buf[6];
  4850. gettimeofday(&tmnow, NULL);
  4851. time_t t;
  4852. t = time(NULL);
  4853. /*UTC time and date*/
  4854. tm = gmtime(&t);
  4855. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4856. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4857. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4858. //********************************(1)Current.Import L1************************************************/
  4859. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  4860. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  4861. (dataType == ReadingContext_Trigger))
  4862. {
  4863. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4864. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4865. {
  4866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4867. {
  4868. tempIndex = ((gun_index==2) ? 1: 0);
  4869. }
  4870. else
  4871. {
  4872. tempIndex = gun_index;
  4873. }
  4874. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4875. {
  4876. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4877. {
  4878. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4879. }
  4880. }
  4881. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4882. }
  4883. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4884. {
  4885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4886. {
  4887. tempIndex = ((gun_index==2) ? 1: 0);
  4888. }
  4889. else
  4890. {
  4891. tempIndex = gun_index;
  4892. }
  4893. for (int index = 0; index < CCS_QUANTITY; index++)
  4894. {
  4895. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4896. {
  4897. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4898. }
  4899. }
  4900. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4901. }
  4902. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4903. {
  4904. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4905. {
  4906. tempIndex = ((gun_index==2) ? 1: 0);
  4907. }
  4908. else
  4909. {
  4910. tempIndex = gun_index;
  4911. }
  4912. for (int index = 0; index < GB_QUANTITY; index++)
  4913. {
  4914. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4915. {
  4916. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4917. }
  4918. }
  4919. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4920. }
  4921. else if(gunType[gun_index] == GUN_TYPE_DO)
  4922. {
  4923. tempIndex = gun_index;
  4924. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4925. {
  4926. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4927. {
  4928. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4929. }
  4930. }
  4931. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4932. }
  4933. else
  4934. {
  4935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4936. {
  4937. tempIndex = 2;
  4938. }
  4939. else
  4940. {
  4941. tempIndex = gun_index;
  4942. }
  4943. for (int index = 0; index < AC_QUANTITY; index++)
  4944. {
  4945. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4946. {
  4947. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4948. }
  4949. }
  4950. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4951. }
  4952. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4953. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4954. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4955. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4956. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4957. }
  4958. //********************************(2)Energy.Active.Import.Register ************************************************/
  4959. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4960. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Register") != NULL)) ||
  4961. (dataType == ReadingContext_Trigger))
  4962. {
  4963. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4964. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4965. {
  4966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4967. {
  4968. tempIndex = ((gun_index==2) ? 1: 0);
  4969. }
  4970. else
  4971. {
  4972. tempIndex = gun_index;
  4973. }
  4974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4975. {
  4976. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4977. {
  4978. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4979. }
  4980. }
  4981. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4982. }
  4983. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4984. {
  4985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4986. {
  4987. tempIndex = ((gun_index==2) ? 1: 0);
  4988. }
  4989. else
  4990. {
  4991. tempIndex = gun_index;
  4992. }
  4993. for (int index = 0; index < CCS_QUANTITY; index++)
  4994. {
  4995. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4996. {
  4997. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4998. }
  4999. }
  5000. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5001. }
  5002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5003. {
  5004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5005. {
  5006. tempIndex = ((gun_index==2) ? 1: 0);
  5007. }
  5008. else
  5009. {
  5010. tempIndex = gun_index;
  5011. }
  5012. for (int index = 0; index < GB_QUANTITY; index++)
  5013. {
  5014. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5015. {
  5016. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  5017. }
  5018. }
  5019. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5020. }
  5021. else if(gunType[gun_index] == GUN_TYPE_DO)
  5022. {
  5023. tempIndex = gun_index;
  5024. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5025. {
  5026. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5027. {
  5028. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  5029. }
  5030. }
  5031. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  5032. }
  5033. else
  5034. {
  5035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5036. {
  5037. tempIndex = 2;
  5038. }
  5039. else
  5040. {
  5041. tempIndex = gun_index;
  5042. }
  5043. for (int index = 0; index < AC_QUANTITY; index++)
  5044. {
  5045. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5046. {
  5047. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  5048. }
  5049. }
  5050. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  5051. }
  5052. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  5053. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  5054. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  5055. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  5056. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5057. }
  5058. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5059. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5060. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)) ||
  5061. (dataType == ReadingContext_Trigger))
  5062. {
  5063. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5064. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5065. {
  5066. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5067. {
  5068. tempIndex = ((gun_index==2) ? 1: 0);
  5069. }
  5070. else
  5071. {
  5072. tempIndex = gun_index;
  5073. }
  5074. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5075. {
  5076. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5077. {
  5078. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  5079. }
  5080. } // END OF FOR CHAdeMO_QUANTITY
  5081. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5082. }
  5083. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5084. {
  5085. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5086. {
  5087. tempIndex = ((gun_index==2) ? 1: 0);
  5088. }
  5089. else
  5090. {
  5091. tempIndex = gun_index;
  5092. }
  5093. for (int index = 0; index < CCS_QUANTITY; index++)
  5094. {
  5095. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5096. {
  5097. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  5098. }
  5099. } // END OF CCS_QUANTITY
  5100. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5101. }
  5102. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5103. {
  5104. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5105. {
  5106. tempIndex = ((gun_index==2) ? 1: 0);
  5107. }
  5108. else
  5109. {
  5110. tempIndex = gun_index;
  5111. }
  5112. for (int index = 0; index < GB_QUANTITY; index++)
  5113. {
  5114. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5115. {
  5116. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  5117. }
  5118. } // END OF GB_QUANTITY
  5119. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5120. }
  5121. else if(gunType[gun_index] == GUN_TYPE_DO)
  5122. {
  5123. tempIndex = gun_index;
  5124. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5125. {
  5126. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5127. {
  5128. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  5129. }
  5130. }
  5131. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  5132. }
  5133. else
  5134. {
  5135. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5136. {
  5137. tempIndex = 2;
  5138. }
  5139. else
  5140. {
  5141. tempIndex = gun_index;
  5142. }
  5143. for (int index = 0; index < AC_QUANTITY; index++)
  5144. {
  5145. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5146. {
  5147. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  5148. }
  5149. }
  5150. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  5151. }
  5152. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  5153. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  5154. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  5155. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  5156. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  5157. }
  5158. //********************************(4)Power.Active.Import************************************************/
  5159. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Power.Active.Import") != NULL)) ||
  5160. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Power.Active.Import") != NULL)) ||
  5161. (dataType == ReadingContext_Trigger))
  5162. {
  5163. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5164. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5165. {
  5166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5167. {
  5168. tempIndex = ((gun_index==2) ? 1: 0);
  5169. }
  5170. else
  5171. {
  5172. tempIndex = gun_index;
  5173. }
  5174. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5175. {
  5176. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5177. {
  5178. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  5179. }
  5180. } // END OF FOR
  5181. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5182. }
  5183. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5184. {
  5185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5186. {
  5187. tempIndex = ((gun_index==2) ? 1: 0);
  5188. }
  5189. else
  5190. {
  5191. tempIndex = gun_index;
  5192. }
  5193. for (int index = 0; index < CCS_QUANTITY; index++)
  5194. {
  5195. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5196. {
  5197. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  5198. }
  5199. }
  5200. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5201. }
  5202. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5203. {
  5204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5205. {
  5206. tempIndex = ((gun_index==2) ? 1: 0);
  5207. }
  5208. else
  5209. {
  5210. tempIndex = gun_index;
  5211. }
  5212. for (int index = 0; index < GB_QUANTITY; index++)
  5213. {
  5214. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5215. {
  5216. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5217. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  5218. }
  5219. }
  5220. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5221. }
  5222. else if(gunType[gun_index] == GUN_TYPE_DO)
  5223. {
  5224. tempIndex = gun_index;
  5225. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5226. {
  5227. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5228. {
  5229. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  5230. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  5231. }
  5232. }
  5233. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  5234. }
  5235. else
  5236. {
  5237. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5238. {
  5239. tempIndex = 2;
  5240. }
  5241. else
  5242. {
  5243. tempIndex = gun_index;
  5244. }
  5245. for (int index = 0; index < AC_QUANTITY; index++)
  5246. {
  5247. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5248. {
  5249. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  5250. }
  5251. }
  5252. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  5253. }
  5254. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  5255. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  5256. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  5257. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  5258. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  5259. }
  5260. //***********************************************(5)VOLTAGE L1******************************************************/
  5261. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5262. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5263. (dataType == ReadingContext_Trigger))
  5264. {
  5265. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5266. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5267. {
  5268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5269. {
  5270. tempIndex = ((gun_index==2) ? 1: 0);
  5271. }
  5272. else
  5273. {
  5274. tempIndex = gun_index;
  5275. }
  5276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5277. {
  5278. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5279. {
  5280. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  5281. }
  5282. }
  5283. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5284. }
  5285. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5286. {
  5287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5288. {
  5289. tempIndex = ((gun_index==2) ? 1: 0);
  5290. }
  5291. else
  5292. {
  5293. tempIndex = gun_index;
  5294. }
  5295. for (int index = 0; index < CCS_QUANTITY; index++)
  5296. {
  5297. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5298. {
  5299. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  5300. }
  5301. }
  5302. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5303. }
  5304. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5305. {
  5306. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5307. {
  5308. tempIndex = ((gun_index==2) ? 1: 0);
  5309. }
  5310. else
  5311. {
  5312. tempIndex = gun_index;
  5313. }
  5314. for (int index = 0; index < GB_QUANTITY; index++)
  5315. {
  5316. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5317. {
  5318. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  5319. }
  5320. }
  5321. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5322. }
  5323. else if(gunType[gun_index] == GUN_TYPE_DO)
  5324. {
  5325. tempIndex = gun_index;
  5326. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5327. {
  5328. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5329. {
  5330. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  5331. }
  5332. }
  5333. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  5334. }
  5335. else
  5336. {
  5337. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5338. {
  5339. tempIndex = 2;
  5340. }
  5341. else
  5342. {
  5343. tempIndex = gun_index;
  5344. }
  5345. for (int index = 0; index < AC_QUANTITY; index++)
  5346. {
  5347. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5348. {
  5349. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  5350. }
  5351. }
  5352. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  5353. }
  5354. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  5355. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  5356. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  5357. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  5358. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5359. }
  5360. //***********************************************(6)SOC******************************************************/
  5361. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "SOC") != NULL)) ||
  5362. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "SOC") != NULL)) ||
  5363. (dataType == ReadingContext_Trigger))
  5364. {
  5365. 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))
  5366. {
  5367. //idx_sample=5;
  5368. //sampledValue = NULL;
  5369. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  5370. {
  5371. tempIndex = ((gun_index==2) ? 1: 0);
  5372. }
  5373. else
  5374. {
  5375. tempIndex = gun_index;
  5376. }
  5377. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5378. {
  5379. //tempIndex = ((gun_index==2) ? 1: 0);
  5380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5381. {
  5382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5383. {
  5384. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  5385. }
  5386. }
  5387. }
  5388. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5389. {
  5390. //tempIndex = ((gun_index==2) ? 1: 0);
  5391. for (int index = 0; index < CCS_QUANTITY; index++)
  5392. {
  5393. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5394. {
  5395. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  5396. }
  5397. }
  5398. }
  5399. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5400. {
  5401. //tempIndex = ((gun_index==2) ? 1: 0);
  5402. for (int index = 0; index < GB_QUANTITY; index++)
  5403. {
  5404. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5405. {
  5406. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  5407. }
  5408. }
  5409. }
  5410. else if(gunType[gun_index] == GUN_TYPE_DO)
  5411. {
  5412. //tempIndex = ((gun_index==2) ? 1: 0);
  5413. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5414. {
  5415. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5416. {
  5417. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  5418. }
  5419. }
  5420. }
  5421. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  5422. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  5423. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  5424. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  5425. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  5426. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  5427. }
  5428. }
  5429. //********************************(7)Current.Import L2************************************************/
  5430. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5431. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5432. (dataType == ReadingContext_Trigger))
  5433. {
  5434. // Only for AC 3 phase
  5435. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5436. {
  5437. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5438. {
  5439. tempIndex = 2;
  5440. }
  5441. else
  5442. {
  5443. tempIndex = gun_index;
  5444. }
  5445. for (int index = 0; index < AC_QUANTITY; index++)
  5446. {
  5447. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5448. {
  5449. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  5450. }
  5451. }
  5452. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  5453. }
  5454. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  5455. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  5456. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  5457. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  5458. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5459. }
  5460. //********************************(8)Current.Import L3************************************************/
  5461. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import") != NULL)) ||
  5462. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import") != NULL)) ||
  5463. (dataType == ReadingContext_Trigger))
  5464. {
  5465. // Only for AC 3 phase
  5466. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5467. {
  5468. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5469. {
  5470. tempIndex = 2;
  5471. }
  5472. else
  5473. {
  5474. tempIndex = gun_index;
  5475. }
  5476. for (int index = 0; index < AC_QUANTITY; index++)
  5477. {
  5478. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5479. {
  5480. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  5481. }
  5482. }
  5483. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  5484. }
  5485. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  5486. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  5487. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  5488. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  5489. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  5490. }
  5491. //***********************************************(9)VOLTAGE L2******************************************************/
  5492. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5493. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5494. (dataType == ReadingContext_Trigger))
  5495. {
  5496. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5497. {
  5498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5499. {
  5500. tempIndex = 2;
  5501. }
  5502. else
  5503. {
  5504. tempIndex = gun_index;
  5505. }
  5506. for (int index = 0; index < AC_QUANTITY; index++)
  5507. {
  5508. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5509. {
  5510. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  5511. }
  5512. }
  5513. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  5514. }
  5515. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  5516. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  5517. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  5518. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  5519. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5520. }
  5521. //***********************************************(10)VOLTAGE L3******************************************************/
  5522. if(((dataType == ReadingContext_Sample_Clock) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Voltage") != NULL)) ||
  5523. ((dataType == ReadingContext_Sample_Periodic) && (strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Voltage") != NULL)) ||
  5524. (dataType == ReadingContext_Trigger))
  5525. {
  5526. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  5527. {
  5528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5529. {
  5530. tempIndex = 2;
  5531. }
  5532. else
  5533. {
  5534. tempIndex = gun_index;
  5535. }
  5536. for (int index = 0; index < AC_QUANTITY; index++)
  5537. {
  5538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5539. {
  5540. sprintf((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  5541. }
  5542. }
  5543. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  5544. }
  5545. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  5546. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  5547. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  5548. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  5549. strcpy((char *)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  5550. }
  5551. // Message create ====================================================================================================
  5552. if(TRUE)
  5553. {
  5554. json_object *MeterValueReq = json_object_new_object();
  5555. json_object *MeterValues = json_object_new_array();
  5556. json_object *sampledValues = json_object_new_array();
  5557. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].ConnectorId));
  5558. if(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1)
  5559. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16DataPH->MeterValues[gun_index].TransactionId));
  5560. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue);idxMeter++)
  5561. {
  5562. json_object *MeterValue = json_object_new_object();
  5563. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  5564. {
  5565. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  5566. {
  5567. json_object *sampledValue = json_object_new_object();
  5568. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  5569. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  5570. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  5571. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  5572. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  5573. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  5574. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  5575. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  5576. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  5577. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  5578. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  5579. if(strlen((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  5580. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  5581. json_object_array_add(sampledValues, sampledValue);
  5582. }
  5583. }
  5584. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  5585. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  5586. json_object_array_add(MeterValues, MeterValue);
  5587. }
  5588. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  5589. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  5590. ,gun_index + 1
  5591. ,MESSAGE_TYPE_CALL
  5592. ,guid
  5593. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  5594. json_object_put(MeterValueReq);
  5595. }
  5596. // Put request guid to hash map
  5597. sprintf(tempdata, "MeterValues,%d", (gun_index));
  5598. 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*/)
  5599. {
  5600. result = PASS;
  5601. //DEBUG_INFO("MeterValues mapitem pass\n");
  5602. }
  5603. if((dataType != ReadingContext_Trigger) &&
  5604. (dataType != ReadingContext_Sample_Clock) &&
  5605. (ShmOCPP16DataPH->MeterValues[gun_index].TransactionId != -1))
  5606. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  5607. else
  5608. {
  5609. if(FirstHeartBeat)
  5610. LWS_Send(queuedata +2);
  5611. }
  5612. return result;
  5613. }
  5614. int sendLogStatusNotificationRequest(char *status)
  5615. {
  5616. mtrace();
  5617. int result = PASS;
  5618. char message[4096]={0};
  5619. char guid[37]={0};
  5620. char tempdata[128]={0};
  5621. json_object *LogStatusNotification = json_object_new_object();
  5622. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5623. ShmOCPP16DataPH->LogStatusNotification.requestId = ShmOCPP16DataPH->GetLog.requestId;
  5624. sprintf((char *)ShmOCPP16DataPH->LogStatusNotification.status,"%s",(const char *)status);
  5625. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->LogStatusNotification.status));
  5626. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->LogStatusNotification.requestId));
  5627. random_uuid(guid);
  5628. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5629. json_object_put(LogStatusNotification);
  5630. LWS_Send(message);
  5631. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5632. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5633. {
  5634. result = PASS;
  5635. }
  5636. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 0;
  5637. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 0;
  5638. return result;
  5639. }
  5640. int sendSecurityEventNotificationRequest()
  5641. {
  5642. mtrace();
  5643. int result = PASS;
  5644. char message[4096]={0};
  5645. char guid[37]={0};
  5646. char tempdata[128]={0};
  5647. json_object *SecurityEventNotification = json_object_new_object();
  5648. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  5649. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.type));
  5650. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.timestamp));
  5651. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP16DataPH->SecurityEventNotification.techInfo));
  5652. random_uuid(guid);
  5653. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  5654. json_object_put(SecurityEventNotification);
  5655. LWS_Send(message);
  5656. sprintf(tempdata, "SecurityEventNotification,0");
  5657. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5658. {
  5659. result = PASS;
  5660. }
  5661. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationReq = 0;
  5662. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 0;
  5663. return result;
  5664. }
  5665. int sendSignCertificateRequest()
  5666. {
  5667. mtrace();
  5668. int result = PASS;
  5669. char message[4096]={0};
  5670. char guid[37]={0};
  5671. char tempdata[128]={0};
  5672. json_object *SignCertificate = json_object_new_object();
  5673. DEBUG_INFO("sendSignCertificateRequest...\n");
  5674. // Read csr file content
  5675. memset(ShmOCPP16DataPH->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->SignCertificate.csr));
  5676. FILE *fp=fopen("/Storage/OCPP_PH/certCP.csr","r");
  5677. char *line = NULL;
  5678. size_t len = 0;
  5679. while(getline(&line, &len, fp) != -1)
  5680. {
  5681. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  5682. {
  5683. memcpy(&ShmOCPP16DataPH->SignCertificate.csr[strlen((char*)ShmOCPP16DataPH->SignCertificate.csr)], line, (strlen(line)-1));
  5684. }
  5685. }
  5686. fclose(fp);
  5687. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP16DataPH->SignCertificate.csr));
  5688. random_uuid(guid);
  5689. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  5690. json_object_put(SignCertificate);
  5691. LWS_Send(message);
  5692. sprintf(tempdata, "SignCertificate,0");
  5693. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5694. {
  5695. result = PASS;
  5696. }
  5697. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 0;
  5698. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 0;
  5699. return result;
  5700. }
  5701. int sendSignedFirmwareStatusNotificationRequest(char *status)
  5702. {
  5703. mtrace();
  5704. int result = PASS;
  5705. char message[110]={0};
  5706. char guid[37]={0};
  5707. char tempdata[65]={0};
  5708. json_object *FirmwareStatusNotification = json_object_new_object();
  5709. DEBUG_INFO("sendSignedFirmwareStatusNotificationRequest...\n");
  5710. sprintf((char *)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status , "%s", (const char *)status);
  5711. ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId = ShmOCPP16DataPH->SignedUpdateFirmware.requestId;
  5712. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedFirmwareStatusNotification.status));
  5713. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP16DataPH->SignedFirmwareStatusNotification.requestId));
  5714. random_uuid(guid);
  5715. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5716. json_object_put(FirmwareStatusNotification);
  5717. LWS_Send(message);
  5718. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5719. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5720. {
  5721. result = PASS;
  5722. }
  5723. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationReq = 0;
  5724. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 0;
  5725. return result;
  5726. }
  5727. //==========================================
  5728. // send confirm routine
  5729. //==========================================
  5730. int sendCancelReservationConfirmation(char *uuid,char *payload)
  5731. {
  5732. mtrace();
  5733. int result = FAIL;
  5734. char message[100]={0};
  5735. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5736. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5737. LWS_Send(message);
  5738. result = TRUE;
  5739. return result;
  5740. }
  5741. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5742. {
  5743. mtrace();
  5744. int result = FAIL;
  5745. char message[100]={0};
  5746. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5747. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5748. LWS_Send(message);
  5749. result = TRUE;
  5750. return result;
  5751. }
  5752. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5753. {
  5754. mtrace();
  5755. int result = FAIL;
  5756. char message[100]={0};
  5757. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5758. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5759. LWS_Send(message);
  5760. result = TRUE;
  5761. return result;
  5762. }
  5763. int sendClearCacheConfirmation(char *uuid,char *payload)
  5764. {
  5765. mtrace();
  5766. int result = FAIL;
  5767. char message[500]={0};
  5768. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5769. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5770. LWS_Send(message);
  5771. return result;
  5772. }
  5773. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5774. {
  5775. mtrace();
  5776. int result = FAIL;
  5777. char message[500]={0};
  5778. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5779. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5780. LWS_Send(message);
  5781. return result;
  5782. }
  5783. int sendDataTransferConfirmation(char *uuid,char *payload)
  5784. {
  5785. mtrace();
  5786. char statusStr[20]={0};
  5787. char dataStr[10]={0};
  5788. char sstr[20]={0};
  5789. int c = 0;
  5790. char *loc;
  5791. int result = FAIL;
  5792. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5793. /**********************status**************************/
  5794. loc = strstr(payload, "status");
  5795. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5796. c = 0;
  5797. while (loc[3+strlen("status")+c] != '\"')
  5798. {
  5799. sstr[c] = loc[3+strlen("status")+c];
  5800. c++;
  5801. }
  5802. sstr[c] = '\0';
  5803. strcpy(statusStr, sstr);
  5804. /**********************data**************************/
  5805. loc = strstr(payload, "data");
  5806. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5807. c = 0;
  5808. while (loc[3+strlen("data")+c] != '\"')
  5809. {
  5810. sstr[c] = loc[3+strlen("data")+c];
  5811. c++;
  5812. }
  5813. sstr[c] = '\0';
  5814. strcpy(dataStr, sstr);
  5815. return result;
  5816. }
  5817. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5818. {
  5819. mtrace();
  5820. int result = FAIL;
  5821. char message[1000]={0};
  5822. int CompositeScheduleIndex = 0;
  5823. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5824. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5825. if(nPeriod == 0)
  5826. {
  5827. if(strcmp((const char *)ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5828. {
  5829. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5830. ,MESSAGE_TYPE_CALLRESULT
  5831. ,uuid
  5832. ,payload
  5833. ,connectorIdInt);
  5834. }
  5835. else
  5836. {
  5837. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5838. ,MESSAGE_TYPE_CALLRESULT
  5839. ,uuid
  5840. ,payload
  5841. ,connectorIdInt
  5842. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5843. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5844. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5845. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5846. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5847. }
  5848. }
  5849. else
  5850. {
  5851. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5852. ,MESSAGE_TYPE_CALLRESULT
  5853. ,uuid
  5854. ,payload
  5855. ,connectorIdInt
  5856. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5857. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5858. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5859. ,ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5860. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5861. {
  5862. if (idx_sample == 0)
  5863. {
  5864. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5865. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5866. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5867. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5868. }
  5869. else
  5870. {
  5871. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5872. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5873. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5874. , ShmOCPP16DataPH->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5875. }
  5876. }
  5877. sprintf(message + strlen(message), "]}}]");
  5878. }
  5879. LWS_Send(message);
  5880. result = TRUE;
  5881. return result;
  5882. }
  5883. int sendGetConfigurationConfirmation(char *uuid)
  5884. {
  5885. mtrace();
  5886. int result = FAIL;
  5887. int MaxKeySupported = 0;
  5888. int sentConfigurationNumber= 0;
  5889. int sentunConfigurationNumber= 0;
  5890. char message[4000]={0};
  5891. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5892. MaxKeySupported = atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5893. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5894. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5895. ,MESSAGE_TYPE_CALLRESULT
  5896. ,uuid );
  5897. //configuration key
  5898. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5899. {
  5900. if(strcmp((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5901. {
  5902. if (sentConfigurationNumber == 0)
  5903. {
  5904. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5905. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5906. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5907. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5908. }
  5909. else
  5910. {
  5911. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5912. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5913. , atoi((const char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5914. , ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5915. }
  5916. sentConfigurationNumber = sentConfigurationNumber + 1;
  5917. }
  5918. }
  5919. sprintf(message + strlen(message), "]");
  5920. if(UnknownKeynum != 0)
  5921. {
  5922. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5923. //unkown key
  5924. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5925. {
  5926. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5927. DEBUG_INFO("unkown key:%s\n", ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5928. if(sentunConfigurationNumber == 0)
  5929. {
  5930. sprintf(message + strlen(message), "\"%s\""
  5931. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5932. }
  5933. else
  5934. {
  5935. sprintf(message + strlen(message), ",\"%s\""
  5936. , ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5937. }
  5938. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5939. }
  5940. sprintf(message + strlen(message), "]");
  5941. }
  5942. sprintf(message + strlen(message), "}]");
  5943. LWS_Send(message);
  5944. return result;
  5945. }
  5946. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5947. {
  5948. mtrace();
  5949. int result = FAIL;
  5950. char message[400]={0};
  5951. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5952. if(strcmp(payload,"")==0)
  5953. {
  5954. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5955. }
  5956. else
  5957. {
  5958. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5959. }
  5960. LWS_Send(message);
  5961. result = TRUE;
  5962. return result;
  5963. }
  5964. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5965. {
  5966. mtrace();
  5967. int result = FAIL;
  5968. char message[80]={0};
  5969. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5970. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion);
  5971. LWS_Send(message);
  5972. result = TRUE;
  5973. return result;
  5974. }
  5975. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5976. {
  5977. mtrace();
  5978. int result = FAIL;
  5979. char message[80]={0};
  5980. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5981. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5982. LWS_Send(message);
  5983. result = TRUE;
  5984. return result;
  5985. }
  5986. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5987. {
  5988. mtrace();
  5989. int result = FAIL;
  5990. char message[80]={0};
  5991. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5992. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5993. LWS_Send(message);
  5994. result = TRUE;
  5995. return result;
  5996. }
  5997. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5998. {
  5999. mtrace();
  6000. int result = FAIL;
  6001. char message[80]={0};
  6002. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  6003. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  6004. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6005. LWS_Send(message);
  6006. result = TRUE;
  6007. return result;
  6008. }
  6009. int sendResetConfirmation(char *uuid,char *payload)
  6010. {
  6011. mtrace();
  6012. int result = FAIL;
  6013. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  6014. char message[80]={0};
  6015. ShmOCPP16DataPH->MsMsg.bits.ResetConf = 0;
  6016. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6017. LWS_Send(message);
  6018. result = TRUE;
  6019. return result;
  6020. }
  6021. int sendSendLocalListConfirmation(char *uuid,char *payload)
  6022. {
  6023. mtrace();
  6024. int result = FAIL;
  6025. char message[500]={0};
  6026. // [ 3, "1571284266109", { "status": "Accepted" } ]
  6027. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  6028. LWS_Send(message);
  6029. result = TRUE;
  6030. return result;
  6031. }
  6032. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  6033. {
  6034. mtrace();
  6035. int result = FAIL;
  6036. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  6037. char message[80]={0};
  6038. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  6039. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6040. LWS_Send(message);
  6041. result = TRUE;
  6042. return result;
  6043. }
  6044. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  6045. {
  6046. mtrace();
  6047. int result = FAIL;
  6048. char message[80]={0};
  6049. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  6050. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6051. LWS_Send(message);
  6052. result = TRUE;
  6053. return result;
  6054. }
  6055. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  6056. {
  6057. mtrace();
  6058. int result = FAIL;
  6059. char message[80]={0};
  6060. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6061. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  6062. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  6063. LWS_Send(message);
  6064. result = TRUE;
  6065. return result;
  6066. }
  6067. int sendUpdateFirmwareConfirmation(char *uuid)
  6068. {
  6069. mtrace();
  6070. int result = FAIL;
  6071. char message[60]={0};
  6072. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  6073. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  6074. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  6075. LWS_Send(message);
  6076. result = TRUE;
  6077. return result;
  6078. }
  6079. int sendCertificateSignedConfirmation(char *uuid)
  6080. {
  6081. mtrace();
  6082. int result = PASS;
  6083. char message[4096]={0};
  6084. json_object *CertificateSigned = json_object_new_object();
  6085. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  6086. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP16DataPH->CertificateSigned.Response_status));
  6087. sprintf(message,"[%d,\"%s\",%s]"
  6088. ,MESSAGE_TYPE_CALLRESULT
  6089. ,uuid
  6090. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  6091. json_object_put(CertificateSigned);
  6092. LWS_Send(message);
  6093. return result;
  6094. }
  6095. int sendDeleteCertificateConfirmation(char *uuid)
  6096. {
  6097. mtrace();
  6098. int result = PASS;
  6099. char message[4096]={0};
  6100. json_object *DeleteCertificate = json_object_new_object();
  6101. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  6102. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status));
  6103. sprintf(message,"[%d,\"%s\",%s]"
  6104. ,MESSAGE_TYPE_CALLRESULT
  6105. ,uuid
  6106. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  6107. json_object_put(DeleteCertificate);
  6108. LWS_Send(message);
  6109. return result;
  6110. }
  6111. int sendExtendedTriggerMessageConfirmation(char *uuid)
  6112. {
  6113. mtrace();
  6114. int result = PASS;
  6115. char message[4096]={0};
  6116. json_object *ExtendedTriggerMessage = json_object_new_object();
  6117. DEBUG_INFO("sendExtendedTriggerMessageConfirmation...\n");
  6118. json_object_object_add(ExtendedTriggerMessage, "status", json_object_new_string((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status));
  6119. sprintf(message,"[%d,\"%s\",%s]"
  6120. ,MESSAGE_TYPE_CALLRESULT
  6121. ,uuid
  6122. ,json_object_to_json_string_ext(ExtendedTriggerMessage, JSON_C_TO_STRING_PLAIN));
  6123. json_object_put(ExtendedTriggerMessage);
  6124. LWS_Send(message);
  6125. return result;
  6126. }
  6127. int sendGetInstalledCertificateIdsConfirmation(char *uuid)
  6128. {
  6129. mtrace();
  6130. int result = PASS;
  6131. char message[4096]={0};
  6132. json_object *GetInstalledCertificateIds = json_object_new_object();
  6133. json_object *certificateHashDataDatas = json_object_new_array();
  6134. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  6135. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status));
  6136. if(strlen((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[0].hashAlgorithm) > 0)
  6137. {
  6138. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData);idx++)
  6139. {
  6140. json_object *certificateHashData = json_object_new_object();
  6141. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].hashAlgorithm));
  6142. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerNameHash));
  6143. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].issuerKeyHash));
  6144. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData[idx].serialNumber));
  6145. json_object_array_add(certificateHashDataDatas, certificateHashData);
  6146. }
  6147. json_object_object_add(GetInstalledCertificateIds , "certificateHashData", certificateHashDataDatas);
  6148. }
  6149. else
  6150. {
  6151. json_object_put(certificateHashDataDatas);
  6152. }
  6153. sprintf(message,"[%d,\"%s\",%s]"
  6154. ,MESSAGE_TYPE_CALLRESULT
  6155. ,uuid
  6156. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  6157. json_object_put(GetInstalledCertificateIds);
  6158. LWS_Send(message);
  6159. return result;
  6160. }
  6161. int sendGetLogConfirmation(char *uuid)
  6162. {
  6163. mtrace();
  6164. int result = PASS;
  6165. char message[4096]={0};
  6166. json_object *GetLog = json_object_new_object();
  6167. DEBUG_INFO("sendGetLogConfirmation...\n");
  6168. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_status));
  6169. if(strlen((char*)ShmOCPP16DataPH->GetLog.Response_filename) > 0)
  6170. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP16DataPH->GetLog.Response_filename));
  6171. sprintf(message,"[%d,\"%s\",%s]"
  6172. ,MESSAGE_TYPE_CALLRESULT
  6173. ,uuid
  6174. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  6175. json_object_put(GetLog);
  6176. LWS_Send(message);
  6177. return result;
  6178. }
  6179. int sendInstallCertificateConfirmation(char *uuid)
  6180. {
  6181. mtrace();
  6182. int result = PASS;
  6183. char message[4096]={0};
  6184. json_object *InstallCertificate = json_object_new_object();
  6185. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  6186. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP16DataPH->InstallCertificate.Response_status));
  6187. sprintf(message,"[%d,\"%s\",%s]"
  6188. ,MESSAGE_TYPE_CALLRESULT
  6189. ,uuid
  6190. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  6191. json_object_put(InstallCertificate);
  6192. LWS_Send(message);
  6193. return result;
  6194. }
  6195. int sendSignedUpdateFirmwareConfirmation(char *uuid)
  6196. {
  6197. mtrace();
  6198. int result = PASS;
  6199. char message[4096]={0};
  6200. json_object *SignedUpdateFirmware = json_object_new_object();
  6201. DEBUG_INFO("sendSignedUpdateFirmwareConfirmation...\n");
  6202. json_object_object_add(SignedUpdateFirmware, "status", json_object_new_string((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status));
  6203. sprintf(message,"[%d,\"%s\",%s]"
  6204. ,MESSAGE_TYPE_CALLRESULT
  6205. ,uuid
  6206. ,json_object_to_json_string_ext(SignedUpdateFirmware, JSON_C_TO_STRING_PLAIN));
  6207. json_object_put(SignedUpdateFirmware);
  6208. LWS_Send(message);
  6209. return result;
  6210. }
  6211. int sendUnknownConfirmation(char *uuid)
  6212. {
  6213. mtrace();
  6214. int result = PASS;
  6215. char message[256]={0};
  6216. DEBUG_INFO("sendUnknownConfirmation...\n");
  6217. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  6218. LWS_Send(message);
  6219. return result;
  6220. }
  6221. //==========================================
  6222. // Handle server request routine Start
  6223. //==========================================
  6224. int handleCancelReservationRequest(char *uuid, char *payload)
  6225. {
  6226. mtrace();
  6227. int result = FAIL;
  6228. int gunNO = 0;
  6229. int reservationIdInt = -1;
  6230. char comfirmstr[20];
  6231. DEBUG_INFO("handleCancelReservationRequest...\n");
  6232. json_object *CancelReservation;
  6233. CancelReservation = json_tokener_parse(payload);
  6234. if(!is_error(CancelReservation))
  6235. {
  6236. // Required data
  6237. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  6238. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  6239. }
  6240. json_object_put(CancelReservation);
  6241. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  6242. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6243. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  6244. if(reservationIdInt != -1)
  6245. {
  6246. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6247. //check Transaction active
  6248. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6249. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6250. {
  6251. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  6252. {
  6253. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6254. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6255. if(gunType[2] == GUN_TYPE_CHAdeMO)
  6256. {
  6257. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  6258. }
  6259. else
  6260. {
  6261. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  6262. }
  6263. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6264. goto end;
  6265. }
  6266. }
  6267. for (int index = 0; index < CCS_QUANTITY; index++)
  6268. {
  6269. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  6270. {
  6271. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6272. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6273. if(gunType[2] == GUN_TYPE_CCS)
  6274. {
  6275. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  6276. }
  6277. else
  6278. {
  6279. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  6280. }
  6281. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6282. goto end;
  6283. }
  6284. }
  6285. for (int index = 0; index < GB_QUANTITY; index++)
  6286. {
  6287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  6288. {
  6289. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6290. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6291. if(gunType[2] == GUN_TYPE_GBT)
  6292. {
  6293. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  6294. }
  6295. else
  6296. {
  6297. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  6298. }
  6299. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6300. goto end;
  6301. }
  6302. }
  6303. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6304. {
  6305. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  6306. {
  6307. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6308. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6309. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  6310. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6311. goto end;
  6312. }
  6313. }
  6314. for (int index = 0; index < AC_QUANTITY; index++)
  6315. {
  6316. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  6317. {
  6318. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  6319. sprintf((char *)ShmOCPP16DataPH->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  6320. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6321. {
  6322. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  6323. }
  6324. else
  6325. {
  6326. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  6327. }
  6328. ShmOCPP16DataPH->CsMsg.bits[gunNO].CancelReservationReq = 1;
  6329. goto end;
  6330. }
  6331. }
  6332. }
  6333. //The reservationId does NOT match the reservationId
  6334. sendCancelReservationConfirmation(uuid, comfirmstr);
  6335. end:
  6336. // Fill in ocpp packet uuid
  6337. strcpy((char *)ShmOCPP16DataPH->CancelReservation[gunNO].guid, uuid);
  6338. return result;
  6339. }
  6340. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  6341. {
  6342. mtrace();
  6343. int result = FAIL;
  6344. int gunIndex = 0;
  6345. char typeStr[16]={0};
  6346. char comfirmstr[20];
  6347. int specificId = FALSE;
  6348. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  6349. json_object *ChangeAvailability;
  6350. ChangeAvailability = json_tokener_parse(payload);
  6351. if(!is_error(ChangeAvailability))
  6352. {
  6353. // Required data
  6354. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  6355. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  6356. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  6357. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  6358. }
  6359. json_object_put(ChangeAvailability);
  6360. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6361. {
  6362. ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  6363. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  6364. }
  6365. else if(gunIndex == 0)
  6366. {
  6367. for(int i=0; i < gunTotalNumber; i++)
  6368. {
  6369. ShmOCPP16DataPH->ChangeAvailability[i].ConnectorId= gunIndex;
  6370. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[i].Type, "%s", typeStr);
  6371. }
  6372. }
  6373. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  6374. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6375. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  6376. {
  6377. specificId = TRUE;
  6378. }
  6379. if(specificId == FALSE)
  6380. goto end;
  6381. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  6382. {
  6383. //----------------------gunIndex is 0 ------------------------------------------------//
  6384. if(gunIndex == 0)
  6385. {
  6386. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6387. {
  6388. for(int i=0; i < gunTotalNumber; i++)
  6389. {
  6390. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6391. {
  6392. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  6393. {
  6394. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6395. {
  6396. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6397. goto end;
  6398. }
  6399. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6400. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6401. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6402. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6403. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6404. {
  6405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6406. goto end;
  6407. }
  6408. }
  6409. }//END FOR CHAdeMO_QUANTITY
  6410. for (int index = 0; index < CCS_QUANTITY; index++)
  6411. {
  6412. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  6413. {
  6414. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  6415. {
  6416. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6417. goto end;
  6418. }
  6419. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6420. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6421. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6422. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6423. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6424. {
  6425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6426. goto end;
  6427. }
  6428. }
  6429. }//END FOR CCS_QUANTITY
  6430. for (int index = 0; index < GB_QUANTITY; index++)
  6431. {
  6432. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  6433. {
  6434. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6435. {
  6436. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6437. goto end;
  6438. }
  6439. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6440. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6441. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6442. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6443. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6444. {
  6445. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6446. goto end;
  6447. }
  6448. }
  6449. }// END FOR GB_QUANTITY
  6450. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6451. {
  6452. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  6453. {
  6454. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6455. {
  6456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6457. goto end;
  6458. }
  6459. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6460. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6461. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6462. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6463. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6464. {
  6465. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6466. goto end;
  6467. }
  6468. }
  6469. }// END FOR GENERAL_GUN_QUANTITY
  6470. for (int index = 0; index < AC_QUANTITY; index++)
  6471. {
  6472. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  6473. {
  6474. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6475. {
  6476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6477. goto end;
  6478. }
  6479. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6480. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6481. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6482. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6483. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6484. {
  6485. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6486. goto end;
  6487. }
  6488. }
  6489. }//END FOR AC_QUANTITY
  6490. }// END FOR gunTotalNumber
  6491. }
  6492. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6493. {
  6494. for(int i=0; i < gunTotalNumber; i++)
  6495. {
  6496. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  6497. {
  6498. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6499. goto end;
  6500. }
  6501. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6502. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  6503. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  6504. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  6505. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6506. {
  6507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6508. goto end;
  6509. }
  6510. }
  6511. }
  6512. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6513. goto end;
  6514. }
  6515. //----------------------gunIndex is not 0 ------------------------------------------------//
  6516. //check Transaction active
  6517. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6518. {
  6519. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  6520. {
  6521. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  6522. {
  6523. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6524. goto end;
  6525. }
  6526. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6527. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6528. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6529. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6530. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6531. {
  6532. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6533. goto end;
  6534. }
  6535. else
  6536. {
  6537. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  6538. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6539. goto end;
  6540. }
  6541. }
  6542. }//END FOR CHAdeMO_QUANTITY
  6543. for (int index = 0; index < CCS_QUANTITY; index++)
  6544. {
  6545. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  6546. {
  6547. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  6548. {
  6549. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6550. goto end;
  6551. }
  6552. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6553. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6554. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6555. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6556. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6557. {
  6558. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6559. goto end;
  6560. }
  6561. else
  6562. {
  6563. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  6564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6565. goto end;
  6566. }
  6567. }
  6568. }//END FOR CCS_QUANTITY
  6569. for (int index = 0; index < GB_QUANTITY; index++)
  6570. {
  6571. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  6572. {
  6573. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6574. {
  6575. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6576. goto end;
  6577. }
  6578. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6579. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6580. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6581. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6582. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6583. {
  6584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6585. goto end;
  6586. }
  6587. else
  6588. {
  6589. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  6590. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6591. goto end;
  6592. }
  6593. }
  6594. }// END FOR GB_QUANTITY
  6595. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6596. {
  6597. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  6598. {
  6599. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6600. {
  6601. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6602. goto end;
  6603. }
  6604. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  6605. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  6606. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  6607. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  6608. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6609. {
  6610. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6611. goto end;
  6612. }
  6613. else
  6614. {
  6615. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  6616. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6617. goto end;
  6618. }
  6619. }
  6620. }// END FOR GENERAL_GUN_QUANTITY
  6621. for (int index = 0; index < AC_QUANTITY; index++)
  6622. {
  6623. if ((gunIndex > 0)&&(gunType[gunIndex-1] ==GUN_TYPE_AC))
  6624. {
  6625. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  6626. {
  6627. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6628. goto end;
  6629. }
  6630. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  6631. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  6632. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  6633. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  6634. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  6635. {
  6636. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  6637. goto end;
  6638. }
  6639. else
  6640. {
  6641. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  6642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6643. goto end;
  6644. }
  6645. }
  6646. }//END FOR AC_QUANTITY
  6647. }//END FOR AvailabilityTypeStr[Inoperative]
  6648. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  6649. {
  6650. //----------------------gunIndex is 0 ------------------------------------------------//
  6651. if(gunIndex == 0)
  6652. {
  6653. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6654. {
  6655. for(int i=0; i < gunTotalNumber; i++)
  6656. {
  6657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6658. {
  6659. 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
  6660. {
  6661. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6662. goto end;
  6663. }
  6664. }//END FOR CHAdeMO_QUANTITY
  6665. for (int index = 0; index < CCS_QUANTITY; index++)
  6666. {
  6667. 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
  6668. {
  6669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6670. goto end;
  6671. }
  6672. }//END FOR CCS_QUANTITY
  6673. for (int index = 0; index < GB_QUANTITY; index++)
  6674. {
  6675. 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
  6676. {
  6677. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6678. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6679. goto end;
  6680. }
  6681. }// END FOR GB_QUANTITY
  6682. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6683. {
  6684. 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
  6685. {
  6686. //ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6687. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6688. goto end;
  6689. }
  6690. }// END FOR GENERAL_GUN_QUANTITY
  6691. for (int index = 0; index < AC_QUANTITY; index++)
  6692. {
  6693. 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
  6694. {
  6695. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6696. goto end;
  6697. }
  6698. }//END FOR CHAdeMO_QUANTITY
  6699. }// END FOR gunTotalNumber
  6700. }
  6701. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  6702. {
  6703. for(int i=0; i < gunTotalNumber; i++)
  6704. {
  6705. for (int index = 0; index < AC_QUANTITY; index++)
  6706. {
  6707. 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
  6708. {
  6709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  6710. goto end;
  6711. }
  6712. }//END FOR CHAdeMO_QUANTITY
  6713. } // END FOR gunTotalNumber
  6714. }
  6715. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6716. goto end;
  6717. }
  6718. //----------------------gunIndex is not 0 ------------------------------------------------//
  6719. //check Transaction active
  6720. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6721. {
  6722. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6723. {
  6724. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6725. goto end;
  6726. }
  6727. }//END FOR CHAdeMO_QUANTITY
  6728. for (int index = 0; index < CCS_QUANTITY; index++)
  6729. {
  6730. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6731. {
  6732. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6733. goto end;
  6734. }
  6735. }//END FOR CCS_QUANTITY
  6736. for (int index = 0; index < GB_QUANTITY; index++)
  6737. {
  6738. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6739. {
  6740. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6741. goto end;
  6742. }
  6743. }// END FOR GB_QUANTITY
  6744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6745. {
  6746. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6747. {
  6748. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6749. goto end;
  6750. }
  6751. }// END FOR GENERAL_GUN_QUANTITY
  6752. for (int index = 0; index < AC_QUANTITY; index++)
  6753. {
  6754. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  6755. {
  6756. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  6757. goto end;
  6758. }
  6759. }//END FOR AC_QUANTITY
  6760. }//END FOR AvailabilityTypeStr[Operative]
  6761. end:
  6762. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6763. {
  6764. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  6765. }
  6766. else
  6767. {
  6768. sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  6769. }
  6770. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  6771. {
  6772. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6773. ShmOCPP16DataPH->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  6774. }
  6775. else if(gunIndex == 0)
  6776. {
  6777. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  6778. {
  6779. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  6780. ShmOCPP16DataPH->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  6781. }
  6782. }
  6783. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  6784. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6785. return result;
  6786. }
  6787. int handleChangeConfigurationRequest(char *uuid, char *payload)
  6788. {
  6789. mtrace();
  6790. int result = FAIL;
  6791. char keystr[40]={0};
  6792. char valuestr[256]={0};
  6793. char comfirmstr[20]={0};
  6794. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  6795. json_object *ChangeConfiguration;
  6796. ChangeConfiguration = json_tokener_parse(payload);
  6797. if(!is_error(ChangeConfiguration))
  6798. {
  6799. // Required data
  6800. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  6801. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  6802. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  6803. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  6804. }
  6805. json_object_put(ChangeConfiguration);
  6806. if((uuid==NULL) || (payload ==NULL) )
  6807. {
  6808. DEBUG_ERROR("Payload is null\n");
  6809. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6810. }
  6811. else
  6812. {
  6813. int status = setKeyValue(keystr, valuestr);
  6814. switch(status)
  6815. {
  6816. case ConfigurationStatus_Accepted:
  6817. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  6818. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationReq = 1;
  6819. StoreConfigurationTable();
  6820. break;
  6821. case RebootRequired:
  6822. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  6823. StoreConfigurationTable();
  6824. break;
  6825. case NotSupported:
  6826. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  6827. break;
  6828. case ConfigurationStatus_Rejected:
  6829. default:
  6830. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  6831. break;
  6832. }
  6833. }
  6834. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  6835. ShmOCPP16DataPH->MsMsg.bits.ChangeConfigurationConf = 1;
  6836. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6837. {
  6838. ChageWebSocketPingInterval(atoi(valuestr));
  6839. }
  6840. if(((strcmp(keystr,"AuthorizationKey")==0) || ((strcmp(keystr,"SecurityProfile")==0))) &&
  6841. (strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  6842. {
  6843. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  6844. SetOcppConnStatus(FALSE);
  6845. }
  6846. return result;
  6847. }
  6848. int handleClearCacheRequest(char *uuid, char *payload)
  6849. {
  6850. mtrace();
  6851. int result = FAIL;
  6852. char comfirmstr[20];
  6853. char rmFileCmd[100]={0};
  6854. struct stat stats;
  6855. DEBUG_INFO("handleClearCacheRequest...\n");
  6856. stat("/Storage/OCPP_PH", &stats);
  6857. // Check for directory existence
  6858. if (S_ISDIR(stats.st_mode) == 1)
  6859. {}
  6860. else
  6861. {
  6862. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6863. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP_PH");
  6864. system(rmFileCmd);
  6865. }
  6866. if(OCPP_cleanLocalCache())
  6867. {
  6868. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6869. }
  6870. else
  6871. {
  6872. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6873. }
  6874. sendClearCacheConfirmation(uuid, comfirmstr);
  6875. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  6876. return result;
  6877. }
  6878. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6879. {
  6880. mtrace();
  6881. int result = FAIL;
  6882. int resultRename;
  6883. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6884. char chargingProfilePurposeStr[26]={0};
  6885. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6886. char tempchargingProfilePurposeStr[26]={0};
  6887. char str[100]={0};
  6888. char fname[200]={0};
  6889. char comfirmstr[20]={0};
  6890. char word[1600]={0};
  6891. int clearflag = FALSE;
  6892. int chargingProfileIdIsNULL = FALSE;
  6893. int connectorIsNULL = FALSE;
  6894. int chargingProfilePurposeIsNULL = FALSE;
  6895. int stackLevelIsNULL = FALSE;
  6896. //int GotoEnd = FALSE;
  6897. FILE *fptr1, *fptr2;
  6898. char temp[] = "/Storage/OCPP_PH/ClearChargingProfiletemp.json"; // Create temp file
  6899. int n_chargingProfile=0;
  6900. int isEmptyFile = FALSE;
  6901. char sLineWord[1600]={0};
  6902. char chargingProfiles[10][100]={0};
  6903. int ChargeProfileCount = 0;
  6904. int ch;
  6905. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6906. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6907. json_object *ClearChargingProfile;
  6908. ClearChargingProfile = json_tokener_parse(payload);
  6909. if(!is_error(ClearChargingProfile))
  6910. {
  6911. // Optional data
  6912. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6913. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6914. else
  6915. chargingProfileIdIsNULL = TRUE;
  6916. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6917. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6918. else
  6919. connectorIsNULL = TRUE;
  6920. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6921. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6922. else
  6923. chargingProfilePurposeIsNULL = TRUE;
  6924. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6925. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6926. else
  6927. stackLevelIsNULL = TRUE;
  6928. }
  6929. json_object_put(ClearChargingProfile);
  6930. if(connectorIsNULL == FALSE)
  6931. {
  6932. switch(connectorIdInt)
  6933. {
  6934. case 0:
  6935. if(chargingProfilePurposeIsNULL == TRUE)
  6936. {
  6937. int l = 0;
  6938. strcpy(fname, ChargePointMaxProfile_JSON);
  6939. if((access(fname,F_OK))!=-1)
  6940. {
  6941. strcpy(chargingProfiles[l], fname);
  6942. l = l + 1;
  6943. }
  6944. strcpy(fname, TxDefaultProfile_0_JSON);
  6945. if((access(fname,F_OK))!=-1)
  6946. {
  6947. strcpy(chargingProfiles[l], fname);
  6948. l = l + 1;
  6949. }
  6950. ChargeProfileCount = l;
  6951. }
  6952. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6953. {
  6954. strcpy(fname, ChargePointMaxProfile_JSON);
  6955. if((access(fname,F_OK))!=-1)
  6956. {
  6957. strcpy(chargingProfiles[0], fname);
  6958. ChargeProfileCount = 1;
  6959. }
  6960. }
  6961. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6962. {
  6963. strcpy(fname, TxDefaultProfile_0_JSON);
  6964. if((access(fname,F_OK))!=-1)
  6965. {
  6966. strcpy(chargingProfiles[0], fname);
  6967. ChargeProfileCount = 1;
  6968. }
  6969. }
  6970. break;
  6971. default:
  6972. if(chargingProfilePurposeIsNULL == TRUE)
  6973. {
  6974. int m = 0;
  6975. memset(fname, 0, ARRAY_SIZE(fname));
  6976. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6977. if((access(fname,F_OK))!=-1)
  6978. {
  6979. strcpy(chargingProfiles[m], fname);
  6980. m = m + 1;
  6981. }
  6982. memset(fname, 0, ARRAY_SIZE(fname));
  6983. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  6984. if((access(fname,F_OK))!=-1)
  6985. {
  6986. strcpy(chargingProfiles[m], fname);
  6987. m = m + 1;
  6988. }
  6989. ChargeProfileCount = m;
  6990. }
  6991. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6992. {
  6993. //strcpy(fname, TxDefaultProfile_1_JSON);
  6994. sprintf(fname, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  6995. if((access(fname,F_OK))!=-1)
  6996. {
  6997. strcpy(chargingProfiles[0], fname);
  6998. ChargeProfileCount = 1;
  6999. }
  7000. }
  7001. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  7002. {
  7003. sprintf(fname, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  7004. if((access(fname,F_OK))!=-1)
  7005. {
  7006. strcpy(chargingProfiles[0], fname);
  7007. ChargeProfileCount = 1;
  7008. }
  7009. //strcpy(fname, TxProfile_1_JSON);
  7010. }
  7011. //strcpy(fname, ChargePointMaxProfile_JSON );
  7012. break;
  7013. }
  7014. }
  7015. else // Check all Charging Profiles
  7016. {
  7017. int i = 0;
  7018. char fnametemp[200]={0};
  7019. ChargeProfileCount = 0;
  7020. //Check ChargePointMaxProfile.json exit
  7021. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  7022. {
  7023. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/ChargePointMaxProfile.json");
  7024. i = i + 1;
  7025. }
  7026. //Check TxDefaultProfile_0.json exit
  7027. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  7028. {
  7029. strcpy(chargingProfiles[i], "/Storage/OCPP_PH/TxDefaultProfile_0.json");
  7030. i = i + 1;
  7031. }
  7032. //Check TxDefaultProfile_%d.json
  7033. for(int j=1; j <= gunTotalNumber; j++)
  7034. {
  7035. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7036. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  7037. if((access(fnametemp,F_OK))!=-1)
  7038. {
  7039. strcpy(chargingProfiles[i], fnametemp);
  7040. i = i + 1;
  7041. }
  7042. }
  7043. //Check TxProfile_%d.json
  7044. for(int j=1; j <= gunTotalNumber; j++)
  7045. {
  7046. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  7047. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  7048. if((access(fnametemp,F_OK))!=-1)
  7049. {
  7050. strcpy(chargingProfiles[i], fnametemp);
  7051. i = i + 1;
  7052. }
  7053. }
  7054. ChargeProfileCount = i;
  7055. }// End connectorIsNULL is TRUE
  7056. if(ChargeProfileCount == 0)
  7057. {
  7058. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7059. goto end;
  7060. }
  7061. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  7062. {
  7063. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7064. goto end;
  7065. }
  7066. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  7067. {
  7068. memset(str, 0, ARRAY_SIZE(str));
  7069. // clear temp file
  7070. sprintf(str,"rm -f %s",temp);
  7071. system(str);
  7072. for(int k=0; k < ChargeProfileCount; k++)
  7073. {
  7074. memset(str, 0, ARRAY_SIZE(str));
  7075. //clear file in C
  7076. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7077. system(str);
  7078. }
  7079. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7080. goto end;
  7081. }
  7082. else if(connectorIsNULL == TRUE)
  7083. {
  7084. for(int k=0; k < ChargeProfileCount; k++)
  7085. {
  7086. fptr1 = fopen(chargingProfiles[k], "r");
  7087. fptr2 = fopen("/Storage/OCPP_PH/ClearChargingProfiletemp.json", "w+");
  7088. //Check Charging Profile Count
  7089. while(fscanf(fptr1, "%s", word) != EOF)
  7090. {
  7091. //DEBUG_INFO("word=%s\n",word);
  7092. if(strstr(word, "chargingProfileId")!= NULL)
  7093. {
  7094. //DEBUG_INFO("test chargingProfileId \n");
  7095. n_chargingProfile = n_chargingProfile + 1;
  7096. //DEBUG_INFO("chargingProfileId Found\n");
  7097. }
  7098. }
  7099. rewind(fptr1);
  7100. //search Charging Profile Element
  7101. //int i= 0;
  7102. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7103. {
  7104. json_object *tmpProfilee;
  7105. tmpProfilee = json_tokener_parse(sLineWord);
  7106. if(!is_error(tmpProfilee))
  7107. {
  7108. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7109. {
  7110. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7111. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7112. }
  7113. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7114. {
  7115. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7116. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7117. }
  7118. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7119. {
  7120. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7121. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7122. }
  7123. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7124. {
  7125. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7126. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7127. }
  7128. }
  7129. json_object_put(tmpProfilee);
  7130. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7131. {
  7132. //------- not write to fptr2-------//
  7133. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7134. //clearflag = TRUE;
  7135. }
  7136. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7137. {
  7138. //------- not write to fptr2-------//
  7139. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7140. }
  7141. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7142. {
  7143. //------- not write to fptr2-------//
  7144. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7145. }
  7146. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  7147. {
  7148. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7149. }
  7150. else
  7151. {
  7152. fprintf(fptr2, sLineWord);//writing data into file
  7153. }
  7154. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7155. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7156. if(clearflag == TRUE)
  7157. {
  7158. fclose(fptr1);
  7159. fclose(fptr2);
  7160. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7161. system(str);
  7162. // clear temp file
  7163. sprintf(str,"rm -f %s",temp);
  7164. system(str);
  7165. }
  7166. else
  7167. {
  7168. fclose(fptr1);
  7169. fclose(fptr2);
  7170. memset(str, 0, ARRAY_SIZE(str));
  7171. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7172. system(str);
  7173. resultRename = rename(temp, chargingProfiles[k]);
  7174. if(resultRename == 0)
  7175. {
  7176. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  7177. }
  7178. else
  7179. {
  7180. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  7181. }
  7182. if(comfirmstr[0]== 0)
  7183. {
  7184. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7185. }
  7186. //Check chargingProfile is empty file
  7187. /*------ Read the file ----------------*/
  7188. fptr1=fopen(chargingProfiles[k],"r");
  7189. ch=fgetc(fptr1);
  7190. rewind(fptr1);
  7191. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7192. if(ch!=EOF)
  7193. {
  7194. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7195. {
  7196. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7197. if(sLineWord[0]=='\0')
  7198. {
  7199. isEmptyFile = TRUE;
  7200. break;
  7201. }
  7202. else
  7203. {
  7204. isEmptyFile = FALSE;
  7205. break;
  7206. }
  7207. }
  7208. }
  7209. else
  7210. isEmptyFile = TRUE;
  7211. fclose(fptr1);
  7212. if(isEmptyFile == TRUE)
  7213. {
  7214. memset(str, 0, ARRAY_SIZE(str));
  7215. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7216. system(str);
  7217. }
  7218. }
  7219. }// End of while(int k=0; k < ChargePointCount; k++)
  7220. }
  7221. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  7222. {
  7223. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  7224. for(int k=0; k < ChargeProfileCount; k++)
  7225. {
  7226. fptr1 = fopen(chargingProfiles[k], "r");
  7227. fptr2 = fopen(temp, "w+");
  7228. //Check Charging Profile Count
  7229. while(fscanf(fptr1, "%s", word) != EOF)
  7230. {
  7231. //DEBUG_INFO("word=%s\n",word);
  7232. if(strstr(word, "chargingProfileId")!= NULL)
  7233. {
  7234. n_chargingProfile = n_chargingProfile + 1;
  7235. }
  7236. }
  7237. rewind(fptr1);
  7238. //search Charging Profile Element
  7239. //int i= 0;
  7240. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  7241. {
  7242. json_object *tmpProfilee;
  7243. tmpProfilee = json_tokener_parse(sLineWord);
  7244. if(!is_error(tmpProfilee))
  7245. {
  7246. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  7247. {
  7248. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  7249. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  7250. }
  7251. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  7252. {
  7253. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  7254. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  7255. }
  7256. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  7257. {
  7258. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  7259. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  7260. }
  7261. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  7262. {
  7263. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  7264. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  7265. }
  7266. }
  7267. json_object_put(tmpProfilee);
  7268. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  7269. {
  7270. //------- not write to fptr2-------//
  7271. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7272. //clearflag = TRUE;
  7273. }
  7274. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  7275. {
  7276. //------- not write to fptr2-------//
  7277. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7278. }
  7279. else if(stackLevelIsNULL == TRUE)
  7280. {
  7281. //Clear Whole File
  7282. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  7283. clearflag = TRUE;
  7284. break;
  7285. }
  7286. else
  7287. {
  7288. fprintf(fptr2, sLineWord);//writing data into file
  7289. }
  7290. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7291. }
  7292. if(clearflag == TRUE)
  7293. {
  7294. fclose(fptr1);
  7295. fclose(fptr2);
  7296. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7297. system(str);
  7298. // clear temp file
  7299. sprintf(str,"rm -f %s",temp);
  7300. system(str);
  7301. }
  7302. else
  7303. {
  7304. fclose(fptr1);
  7305. fclose(fptr2);
  7306. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7307. system(str);
  7308. resultRename = rename(temp, chargingProfiles[k]);
  7309. if(resultRename == 0)
  7310. {
  7311. DEBUG_INFO("File ChargingProfile renamed successfully");
  7312. }
  7313. else
  7314. {
  7315. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  7316. }
  7317. if(comfirmstr[0]== 0)
  7318. {
  7319. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  7320. }
  7321. //Check chargingProfile is empty file
  7322. /*------ Read the file ----------------*/
  7323. fptr1=fopen(chargingProfiles[k],"r");
  7324. ch=fgetc(fptr1);
  7325. rewind(fptr1);
  7326. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  7327. if(ch!=EOF)
  7328. {
  7329. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  7330. {
  7331. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  7332. if(sLineWord[0]=='\0')
  7333. {
  7334. isEmptyFile = TRUE;
  7335. break;
  7336. }
  7337. else
  7338. {
  7339. isEmptyFile = FALSE;
  7340. break;
  7341. }
  7342. }
  7343. }
  7344. else
  7345. isEmptyFile = TRUE;
  7346. fclose(fptr1);
  7347. if(isEmptyFile == TRUE)
  7348. {
  7349. memset(str, 0, ARRAY_SIZE(str));
  7350. sprintf(str,"rm -f %s",chargingProfiles[k]);
  7351. system(str);
  7352. }
  7353. /*------- End of reading ---------------*/
  7354. }
  7355. } // while(int k=0; k < ChargeProfileCount; k++)
  7356. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  7357. end:
  7358. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  7359. {
  7360. if(connectorIdInt == 0)
  7361. {
  7362. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  7363. {
  7364. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  7365. }
  7366. }
  7367. else
  7368. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  7369. }
  7370. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  7371. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  7372. return result;
  7373. }
  7374. void createFirmwareVersionByDataTransfer(void)
  7375. {
  7376. json_object *FirmwareDataTransfer = json_object_new_object();
  7377. // AC & DC model
  7378. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  7379. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  7380. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  7381. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  7382. // DC model
  7383. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  7384. {
  7385. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  7386. {
  7387. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7388. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7389. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  7390. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  7391. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7392. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7393. }
  7394. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  7395. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  7396. {
  7397. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  7398. }
  7399. }
  7400. else
  7401. {
  7402. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  7403. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  7404. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  7405. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  7406. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  7407. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  7408. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  7409. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  7410. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  7411. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  7412. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  7413. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  7414. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  7415. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  7416. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  7417. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  7418. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  7419. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  7420. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  7421. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  7422. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  7423. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  7424. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  7425. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  7426. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  7427. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  7428. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  7429. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  7430. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  7431. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  7432. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  7433. }
  7434. // 4G model
  7435. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  7436. {
  7437. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  7438. }
  7439. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].VendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  7440. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  7441. sprintf((char*)ShmOCPP16DataPH->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  7442. json_object_put(FirmwareDataTransfer);
  7443. }
  7444. int handleDataTransferRequest(char *uuid, char *payload)
  7445. {
  7446. mtrace();
  7447. json_object *response = json_object_new_object();
  7448. int result = FAIL;
  7449. char tempvendorId[255]={0};
  7450. char tempmessageId[50]={0};
  7451. char tempdata[512]={0};
  7452. char message[2048]={0};
  7453. DEBUG_INFO("handleDataTransferRequest...\n");
  7454. if((uuid != NULL) && (payload != NULL))
  7455. {
  7456. json_object *DataTransfer;
  7457. DataTransfer = json_tokener_parse(payload);
  7458. if(!is_error(DataTransfer))
  7459. {
  7460. // Required data
  7461. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  7462. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  7463. // Optional data
  7464. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  7465. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  7466. if(json_object_object_get(DataTransfer, "data") != NULL)
  7467. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  7468. result = PASS;
  7469. }
  7470. json_object_put(DataTransfer);
  7471. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  7472. {
  7473. // Send all moudle firmware version on EVSE
  7474. createFirmwareVersionByDataTransfer();
  7475. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7476. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16DataPH->DataTransfer[0].Data));
  7477. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7478. json_object_put(response);
  7479. }
  7480. else if(strstr(tempmessageId, "ID_Tmate") != NULL)
  7481. {
  7482. system("/usr/bin/run_tmate_restart.sh &");
  7483. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7484. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7485. json_object_put(response);
  7486. }
  7487. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  7488. {
  7489. json_object *data;
  7490. data = json_tokener_parse(tempdata);
  7491. if(!is_error(data))
  7492. {
  7493. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  7494. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  7495. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  7496. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  7497. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  7498. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  7499. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  7500. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  7501. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  7502. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  7503. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7504. }
  7505. else
  7506. {
  7507. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7508. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7509. }
  7510. json_object_put(data);
  7511. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7512. json_object_put(response);
  7513. }
  7514. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  7515. {
  7516. json_object *data;
  7517. data = json_tokener_parse(tempdata);
  7518. if(!is_error(data))
  7519. {
  7520. memset(&ShmOCPP16DataPH->Cost.SetUserPrice, 0x00, sizeof(struct StrcutSetUserPrice));
  7521. if(json_object_object_get(data, "idToken") != NULL)
  7522. {
  7523. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.idToken, "%s", json_object_get_string(json_object_object_get(data, "idToken")));
  7524. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  7525. }
  7526. if(json_object_object_get(data, "price") != NULL)
  7527. {
  7528. sprintf((char*)ShmOCPP16DataPH->Cost.SetUserPrice.price, "%s", json_object_get_string(json_object_object_get(data, "price")));
  7529. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  7530. }
  7531. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7532. }
  7533. else
  7534. {
  7535. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7536. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7537. }
  7538. json_object_put(data);
  7539. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7540. json_object_put(response);
  7541. }
  7542. else if(strstr(tempmessageId, "RunningCost") != NULL)
  7543. {
  7544. json_object *data;
  7545. data = json_tokener_parse(tempdata);
  7546. if(!is_error(data))
  7547. {
  7548. if(json_object_object_get(data, "txId") != NULL)
  7549. {
  7550. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7551. for(int idx = 0;idx<gunTotalNumber;idx++)
  7552. {
  7553. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7554. {
  7555. memset(&ShmOCPP16DataPH->Cost.RunningCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7556. ShmOCPP16DataPH->Cost.RunningCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7557. if(json_object_object_get(data, "description") != NULL)
  7558. {
  7559. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7560. sprintf((char*)ShmOCPP16DataPH->Cost.RunningCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7561. }
  7562. }
  7563. }
  7564. }
  7565. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7566. }
  7567. else
  7568. {
  7569. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7570. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7571. }
  7572. json_object_put(data);
  7573. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7574. json_object_put(response);
  7575. }
  7576. else if(strstr(tempmessageId, "FinalCost") != NULL)
  7577. {
  7578. json_object *data;
  7579. data = json_tokener_parse(tempdata);
  7580. if(!is_error(data))
  7581. {
  7582. if(json_object_object_get(data, "txId") != NULL)
  7583. {
  7584. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  7585. for(int idx = 0;idx<gunTotalNumber;idx++)
  7586. {
  7587. if(ShmOCPP16DataPH->StartTransaction[idx].ResponseTransactionId == json_object_get_int(json_object_object_get(data, "txId")))
  7588. {
  7589. memset(&ShmOCPP16DataPH->Cost.FinalCost[idx], 0x00, sizeof(struct StrcutRunningFinalCost));
  7590. ShmOCPP16DataPH->Cost.FinalCost[idx].txId = json_object_get_int(json_object_object_get(data, "txId"));
  7591. if(json_object_object_get(data, "description") != NULL)
  7592. {
  7593. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  7594. sprintf((char*)ShmOCPP16DataPH->Cost.FinalCost[idx].description, "%s", json_object_get_string(json_object_object_get(data, "description")));
  7595. }
  7596. }
  7597. }
  7598. }
  7599. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7600. }
  7601. else
  7602. {
  7603. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7604. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7605. }
  7606. json_object_put(data);
  7607. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7608. json_object_put(response);
  7609. }
  7610. else if(strstr(tempmessageId, "ID_ConfigQR") != NULL)
  7611. {
  7612. json_object *data;
  7613. data = json_tokener_parse(tempdata);
  7614. if(!is_error(data))
  7615. {
  7616. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7617. if(json_object_object_get(data, "Content_Type") != NULL)
  7618. {
  7619. 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))
  7620. {
  7621. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  7622. if(json_object_object_get(data, "Customization_Conent") != NULL)
  7623. {
  7624. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  7625. }
  7626. }
  7627. else
  7628. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7629. }
  7630. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7631. }
  7632. else
  7633. {
  7634. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7635. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7636. }
  7637. json_object_put(data);
  7638. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7639. json_object_put(response);
  7640. }
  7641. else if(strstr(tempmessageId, "ID_DsiplayLcdPage") != NULL)
  7642. {
  7643. json_object *data;
  7644. data = json_tokener_parse(tempdata);
  7645. if(!is_error(data))
  7646. {
  7647. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7648. if(json_object_object_get(data, "Page_Index") != NULL)
  7649. {
  7650. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  7651. }
  7652. if(json_object_object_get(data, "Duration") != NULL)
  7653. {
  7654. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  7655. }
  7656. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  7657. }
  7658. else
  7659. {
  7660. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7661. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7662. }
  7663. json_object_put(data);
  7664. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7665. json_object_put(response);
  7666. }
  7667. else if(strstr(tempmessageId, "ID_CpConfiguration") != NULL)
  7668. {
  7669. json_object *data;
  7670. data = json_tokener_parse(tempdata);
  7671. if(!is_error(data))
  7672. {
  7673. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  7674. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  7675. {
  7676. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  7677. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  7678. else
  7679. {
  7680. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7681. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7682. }
  7683. }
  7684. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  7685. {
  7686. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  7687. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  7688. else
  7689. {
  7690. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7691. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7692. }
  7693. }
  7694. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  7695. {
  7696. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  7697. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  7698. else
  7699. {
  7700. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7701. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7702. }
  7703. }
  7704. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  7705. {
  7706. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  7707. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  7708. else
  7709. {
  7710. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7711. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7712. }
  7713. }
  7714. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  7715. {
  7716. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  7717. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  7718. else
  7719. {
  7720. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7721. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7722. }
  7723. }
  7724. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  7725. {
  7726. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  7727. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  7728. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  7729. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  7730. else
  7731. {
  7732. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7733. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7734. }
  7735. }
  7736. if(strstr(json_object_get_string(json_object_object_get(response, "status")), "Accepted") != NULL)
  7737. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  7738. }
  7739. else
  7740. {
  7741. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  7742. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  7743. }
  7744. json_object_put(data);
  7745. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  7746. json_object_put(response);
  7747. }
  7748. else
  7749. {
  7750. // Can not find valid message id
  7751. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  7752. }
  7753. }
  7754. else
  7755. {
  7756. // Payload is null
  7757. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  7758. }
  7759. LWS_Send(message);
  7760. return result;
  7761. }
  7762. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  7763. {
  7764. mtrace();
  7765. int result = FAIL;
  7766. int connectorIdInt, durationInt;
  7767. char chargingRateUnitStr[4]={0};
  7768. char comfirmstr[20];
  7769. int confirmPeriods = 0;
  7770. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  7771. json_object *GetCompositeSchedule;
  7772. GetCompositeSchedule = json_tokener_parse(payload);
  7773. if(!is_error(GetCompositeSchedule))
  7774. {
  7775. // Required data
  7776. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  7777. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  7778. else
  7779. connectorIdInt = -1;
  7780. if(json_object_object_get(GetCompositeSchedule, "duration"))
  7781. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  7782. else
  7783. durationInt = 86400;
  7784. // Optional data
  7785. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  7786. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  7787. }
  7788. json_object_put(GetCompositeSchedule);
  7789. memset(ShmOCPP16DataPH->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  7790. if((connectorIdInt == 0) ||
  7791. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  7792. {
  7793. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  7794. struct StructChargingProfile tmpProfile[1];
  7795. if(strstr(chargingRateUnitStr, "W") != NULL)
  7796. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], FALSE);
  7797. else
  7798. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], TRUE);
  7799. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7800. {
  7801. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7802. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7803. }
  7804. ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  7805. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  7806. memcpy(&ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  7807. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  7808. {
  7809. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  7810. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  7811. if((ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  7812. (ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0) &&
  7813. (idx<(ARRAY_SIZE(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod)-1)?(ShmOCPP16DataPH->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx+1].StartPeriod==0):TRUE))
  7814. {
  7815. confirmPeriods = idx;
  7816. break;
  7817. }
  7818. }
  7819. if((confirmPeriods == 0) && (tmpProfile[0].ChargingProfileId > 0))
  7820. {
  7821. confirmPeriods += 1;
  7822. }
  7823. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  7824. }
  7825. else
  7826. {
  7827. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  7828. }
  7829. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  7830. return result;
  7831. }
  7832. int handleGetConfigurationRequest(char *uuid, char *payload)
  7833. {
  7834. mtrace();
  7835. int result = FAIL;
  7836. int MaxKeySupported = 0;
  7837. int n_keys = 0;
  7838. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  7839. DEBUG_INFO("handleGetConfigurationRequest...\n");
  7840. json_object *GetConfiguration;
  7841. GetConfiguration = json_tokener_parse(payload);
  7842. if(!is_error(GetConfiguration))
  7843. {
  7844. // Optional data
  7845. if(json_object_object_get(GetConfiguration, "key") != NULL)
  7846. {
  7847. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  7848. {
  7849. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  7850. n_keys = idx + 1;
  7851. }
  7852. }
  7853. }
  7854. json_object_put(GetConfiguration);
  7855. UnknownKeynum = 0;
  7856. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  7857. MaxKeySupported = GetConfigurationMaxKeysNUM;
  7858. memset(ShmOCPP16DataPH->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  7859. memset(ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  7860. if(n_keys != 0)
  7861. {
  7862. for(int i=0;i<n_keys;i++)
  7863. {
  7864. getKeyValue(requestKey[i]);
  7865. }
  7866. }
  7867. else
  7868. {
  7869. DEBUG_INFO("There is no key in Message, get all configuration\n");
  7870. getKeyValue("");
  7871. }
  7872. processUnkownKey();
  7873. sendGetConfigurationConfirmation(uuid);
  7874. return result;
  7875. }
  7876. static char fnamePlusPath[100]={0};
  7877. static char fnamePWithNoPath[60]={0};
  7878. void checkUploadLog(void)
  7879. {
  7880. FILE *fp;
  7881. /* Open the command for reading. */
  7882. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  7883. if (fp == NULL) {
  7884. DEBUG_WARN("Failed to run command\n" );
  7885. exit(1);
  7886. }
  7887. int ftppathlen = 0;
  7888. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  7889. int i = 0;
  7890. /* Read the output a line at a time - output it. */
  7891. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  7892. if(i==0)
  7893. {
  7894. ftppathlen = strlen(fnamePlusPath);
  7895. DEBUG_INFO("%s\n", fnamePlusPath);
  7896. fnamePlusPath[ftppathlen]='\0';
  7897. break;
  7898. }
  7899. i= i+1;
  7900. }
  7901. /* close */
  7902. pclose(fp);
  7903. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  7904. {
  7905. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  7906. {
  7907. fnamePlusPath[k]='\0';
  7908. }
  7909. }
  7910. i=1;
  7911. //char fname[60]={0};
  7912. while(i < ftppathlen)
  7913. {
  7914. int len=ftppathlen-i;
  7915. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  7916. {
  7917. DEBUG_INFO("compare '/' all right\n");
  7918. break;
  7919. }
  7920. i=i+1;
  7921. }
  7922. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  7923. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  7924. fnamePWithNoPath[i+1] = '\0';
  7925. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  7926. {
  7927. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  7928. {
  7929. fnamePWithNoPath[j]='\0';
  7930. }
  7931. }
  7932. FILE* fp1 = fopen(fnamePlusPath, "r");
  7933. if (fp1)
  7934. {
  7935. DEBUG_INFO("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  7936. // file exists
  7937. fclose(fp1);
  7938. }
  7939. else
  7940. {
  7941. // file doesn't exist
  7942. DEBUG_WARN("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  7943. }
  7944. }
  7945. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  7946. {
  7947. mtrace();
  7948. int result = FAIL;
  7949. time_t CurrentTime;
  7950. struct tm *tm;
  7951. pthread_t th_Status;
  7952. CurrentTime = time(NULL);
  7953. tm = localtime(&CurrentTime);
  7954. memset(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetDiagnostics.ResponseFileName));
  7955. 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);
  7956. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  7957. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  7958. return result;
  7959. }
  7960. void* GetDiagnosticsProcess(void* data)
  7961. {
  7962. pthread_detach(pthread_self());
  7963. mtrace();
  7964. int retriesInt=0, retryIntervalInt=0;
  7965. char locationstr[1024]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  7966. 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};
  7967. int port=0;
  7968. int isSuccess = FALSE;
  7969. char ftpbuf[200]={0};
  7970. char cmdBuf[2048];
  7971. struct tm *tmNow;
  7972. time_t CurrentTime;
  7973. struct tm tmStart;
  7974. struct tm tmStop;
  7975. CurrentTime = time(NULL);
  7976. tmNow=localtime(&CurrentTime);
  7977. uint16_t targetYear, targetMonth;
  7978. json_object *GetDiagnostics;
  7979. DEBUG_INFO("GetDiagnosticsProcess...\n");
  7980. GetDiagnostics = json_tokener_parse(data);
  7981. if(!is_error(GetDiagnostics))
  7982. {
  7983. // Required data
  7984. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  7985. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  7986. // Optional data
  7987. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  7988. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  7989. else
  7990. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  7991. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  7992. retryIntervalInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  7993. else
  7994. retryIntervalInt = 30;
  7995. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  7996. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  7997. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  7998. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  7999. }
  8000. json_object_put(GetDiagnostics);
  8001. // Pack log to compress file
  8002. 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) &&
  8003. (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))
  8004. {
  8005. // Pack system log
  8006. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8007. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8008. targetYear = tmStart.tm_year;
  8009. targetMonth = tmStart.tm_mon;
  8010. do
  8011. {
  8012. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8013. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog", cmdBuf, targetYear, targetMonth);
  8014. if(targetMonth+1>=13)
  8015. {
  8016. targetYear += 1;
  8017. targetMonth = 1;
  8018. }
  8019. else
  8020. {
  8021. targetMonth += 1;
  8022. }
  8023. }while((targetYear < (tmNow->tm_year+1900)) ||
  8024. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8025. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  8026. sprintf(cmdBuf, "%s /Storage/OCPP/*.db", cmdBuf);
  8027. system(cmdBuf);
  8028. // Pack charging & event log
  8029. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  8030. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  8031. targetYear = tmStart.tm_year;
  8032. targetMonth = tmStart.tm_mon;
  8033. do
  8034. {
  8035. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  8036. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog", cmdBuf, targetYear, targetMonth);
  8037. if(targetMonth+1>=13)
  8038. {
  8039. targetYear += 1;
  8040. targetMonth = 1;
  8041. }
  8042. else
  8043. {
  8044. targetMonth += 1;
  8045. }
  8046. }while((targetYear < (tmNow->tm_year+1900)) ||
  8047. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  8048. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  8049. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  8050. system(cmdBuf);
  8051. // Combine log file
  8052. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  8053. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  8054. }
  8055. else
  8056. {
  8057. system("exec /root/logPackTools 'log' 6");
  8058. }
  8059. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16DataPH->GetDiagnostics.ResponseFileName);
  8060. system(cmdBuf);
  8061. checkUploadLog();
  8062. //****************location*******************/
  8063. if(strcmp(locationstr,"")==0)
  8064. {
  8065. DEBUG_INFO("location is <Empty>!\n");
  8066. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8067. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8068. goto end;
  8069. }
  8070. memset(protocol, 0, ARRAY_SIZE(protocol));
  8071. memset(user, 0, ARRAY_SIZE(user) );
  8072. memset(password, 0, ARRAY_SIZE(password));
  8073. memset(host, 0, ARRAY_SIZE(host));
  8074. memset(path, 0, ARRAY_SIZE(path));
  8075. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  8076. memset(host1, 0, ARRAY_SIZE(host1));
  8077. memset(path1, 0, ARRAY_SIZE(path1));
  8078. /*location: ftp://user:password@host:port/path*/
  8079. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  8080. if((access(fnamePlusPath,F_OK))!=-1)
  8081. {
  8082. DEBUG_INFO("fnamePlusPath exist.\n");
  8083. }
  8084. else
  8085. {
  8086. DEBUG_INFO("fnamePlusPath not exist!\n");
  8087. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8088. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8089. goto end;
  8090. }
  8091. if(strchr(locationstr,'@')==NULL)
  8092. {
  8093. sscanf(locationstr,
  8094. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8095. protocol, host, &port, path);
  8096. strcpy(user,"anonymous");
  8097. strcpy(password,"");
  8098. }
  8099. else
  8100. {
  8101. //DEBUG_INFO("pch=%s\n", pch);
  8102. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8103. protocol, user, password, host, &port, path);
  8104. }
  8105. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  8106. {
  8107. DEBUG_INFO("protocol is not ftp/http ! \n");
  8108. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8109. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8110. goto end;
  8111. }
  8112. if(strncmp(locationstr,"http", 4) == 0)
  8113. {
  8114. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  8115. sprintf(ftppath,"/%s", path);
  8116. do
  8117. {
  8118. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8119. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8120. sleep(3);
  8121. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  8122. if(!isSuccess)
  8123. {
  8124. DEBUG_INFO("Diagnostics fail.\n");
  8125. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8126. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8127. sleep(retryIntervalInt);
  8128. }
  8129. else
  8130. {
  8131. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8132. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8133. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8134. }
  8135. retriesInt--;
  8136. }while((isSuccess == 0)&&(retriesInt >= 0));
  8137. }
  8138. else
  8139. {
  8140. sscanf(host,"%[^/]%s",host1, path1);
  8141. if(strlen(path) > 0)
  8142. sprintf(ftppath,"/%s", path);
  8143. else
  8144. sprintf(ftppath,"/%s", path1);
  8145. int ftppathlen=strlen(ftppath);
  8146. int i=1;
  8147. char filenametemp[50];
  8148. while(i < ftppathlen)
  8149. {
  8150. int len=ftppathlen-i;
  8151. if(ftppath[len]== 47) // '/' ascll code: 47
  8152. {
  8153. DEBUG_INFO("find '/' all right\n");
  8154. break;
  8155. }
  8156. i=i+1;
  8157. }
  8158. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  8159. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8160. filenametemp[i+1] = 0;
  8161. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  8162. if(port == 0)
  8163. port = 21;
  8164. do
  8165. {
  8166. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  8167. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8168. sleep(3);
  8169. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  8170. if(!isSuccess)
  8171. {
  8172. DEBUG_INFO("Diagnostics fail.\n");
  8173. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  8174. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8175. sleep(retryIntervalInt);
  8176. }
  8177. else
  8178. {
  8179. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  8180. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  8181. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8182. }
  8183. retriesInt--;
  8184. }while((!isSuccess)&&(retriesInt >= 0));
  8185. }
  8186. end:
  8187. system("rm -f /mnt/*");
  8188. sleep(5);
  8189. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8190. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  8191. pthread_exit(NULL);
  8192. }
  8193. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  8194. {
  8195. mtrace();
  8196. int result = FAIL;
  8197. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  8198. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  8199. {
  8200. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  8201. locallistVersion = -1;
  8202. }
  8203. else
  8204. {
  8205. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  8206. OCPP_getListVerion();
  8207. }
  8208. //from db.OCPP_getListVerion
  8209. ShmOCPP16DataPH->GetLocalListVersion.ResponseListVersion = locallistVersion;
  8210. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionReq = 1;
  8211. sendGetLocalListVersionConfirmation(uuid,"");
  8212. //ShmOCPP16DataPH->MsMsg.bits.GetLocalListVersionConf = 1;
  8213. return result;
  8214. }
  8215. int handleRemoteStartRequest(char *uuid, char *payload)
  8216. {
  8217. mtrace();
  8218. int result = FAIL;
  8219. int connectorIdInt=0;
  8220. int tempIndex = 0;
  8221. int connectorIdIsNULL, chargingProfileIsNULL;
  8222. char comfirmstr[20]={0};
  8223. char cmdBuf[512];
  8224. json_object *RemoteStartTransaction;
  8225. FILE *fp;
  8226. DEBUG_INFO("handleRemoteStartRequest ...\n");
  8227. if(server_pending == TRUE)
  8228. {
  8229. return 0;
  8230. }
  8231. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  8232. RemoteStartTransaction = json_tokener_parse(payload);
  8233. if(!is_error(RemoteStartTransaction))
  8234. {
  8235. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  8236. {
  8237. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  8238. if(connectorIdInt <= gunTotalNumber)
  8239. {
  8240. memset(&ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  8241. // Required data
  8242. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  8243. // Optional data
  8244. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  8245. {
  8246. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  8247. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  8248. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  8249. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  8250. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  8251. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  8252. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  8253. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  8254. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  8255. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  8256. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  8257. sprintf((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  8258. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  8259. {
  8260. 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")));
  8261. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  8262. 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"));
  8263. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  8264. 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"));
  8265. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  8266. 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")));
  8267. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8268. {
  8269. 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++)
  8270. {
  8271. 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"));
  8272. 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"));
  8273. 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)
  8274. 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"));
  8275. }
  8276. }
  8277. }
  8278. }
  8279. else
  8280. chargingProfileIsNULL = TRUE;
  8281. }
  8282. }
  8283. else
  8284. connectorIdIsNULL = TRUE;
  8285. }
  8286. else
  8287. connectorIdIsNULL = TRUE;
  8288. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  8289. {
  8290. DEBUG_WARN("Connector id is NULL\n.");
  8291. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8292. goto end;
  8293. }
  8294. /*
  8295. enum _SYSTEM_STATUS
  8296. {
  8297. S_BOOTING = 0,
  8298. S_IDLE, = 1
  8299. S_AUTHORIZING, = 2
  8300. S_REASSIGN_CHECK, = 3
  8301. S_REASSIGN, = 4
  8302. S_PRECHARGE, = 5
  8303. S_PREPARING_FOR_EV, = 6
  8304. S_PREPARING_FOR_EVSE, = 7
  8305. S_CHARGING, = 8
  8306. S_TERMINATING, = 9
  8307. S_COMPLETE, = 10
  8308. S_ALARM, = 11
  8309. S_FAULT = 12
  8310. }
  8311. */
  8312. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  8313. {
  8314. //check Transaction active
  8315. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8316. {
  8317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8318. {
  8319. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8320. }
  8321. else
  8322. {
  8323. tempIndex = connectorIdInt -1;
  8324. }
  8325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8326. {
  8327. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  8328. {
  8329. 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))
  8330. {
  8331. //Reserved
  8332. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8333. }
  8334. 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))
  8335. {
  8336. //Reserved
  8337. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8338. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8339. goto end;
  8340. }
  8341. else
  8342. {
  8343. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8344. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  8345. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  8346. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  8347. {
  8348. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  8349. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8350. goto end;
  8351. }
  8352. }//END FOR ELSE
  8353. }
  8354. }// END FOR CHAdeMO_QUANTITY
  8355. }
  8356. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8357. {
  8358. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8359. {
  8360. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8361. }
  8362. else
  8363. {
  8364. tempIndex = connectorIdInt -1;
  8365. }
  8366. for (int index = 0; index < CCS_QUANTITY; index++)
  8367. {
  8368. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8369. {
  8370. 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))
  8371. {
  8372. //Reserved
  8373. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8374. }
  8375. 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))
  8376. {
  8377. //Reserved
  8378. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8379. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8380. goto end;
  8381. }
  8382. else
  8383. {
  8384. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8385. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8386. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8387. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8388. {
  8389. DEBUG_WARN("CCS connector not allow start\n.");
  8390. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8391. goto end;
  8392. }
  8393. }// END FOR ELSE
  8394. }
  8395. }// END FOR CCS_QUANTITY
  8396. }
  8397. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8398. {
  8399. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8400. {
  8401. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  8402. }
  8403. else
  8404. {
  8405. tempIndex = connectorIdInt -1;
  8406. }
  8407. for (int index = 0; index < GB_QUANTITY; index++)
  8408. {
  8409. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  8410. {
  8411. 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))
  8412. {
  8413. //Reserved
  8414. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8415. }
  8416. 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))
  8417. {
  8418. //Reserved
  8419. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8420. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8421. goto end;
  8422. }
  8423. else
  8424. {
  8425. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8426. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8427. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8428. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8429. {
  8430. DEBUG_WARN("GB connector not allow start\n.");
  8431. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8432. goto end;
  8433. }
  8434. }// END FOR ELSE
  8435. }
  8436. } // END FOR GB_QUANTITY
  8437. }
  8438. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8439. {
  8440. tempIndex = connectorIdInt -1;
  8441. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8442. {
  8443. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  8444. {
  8445. 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))
  8446. {
  8447. //Reserved
  8448. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8449. }
  8450. 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))
  8451. {
  8452. //Reserved
  8453. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8454. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8455. goto end;
  8456. }
  8457. else
  8458. {
  8459. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8460. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8461. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8462. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8463. {
  8464. DEBUG_WARN("GB connector not allow start\n.");
  8465. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8466. goto end;
  8467. }
  8468. }// END FOR ELSE
  8469. }
  8470. } // END FOR GB_QUANTITY
  8471. }
  8472. else
  8473. {
  8474. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8475. {
  8476. tempIndex = 2;
  8477. }
  8478. else
  8479. {
  8480. tempIndex = connectorIdInt -1;
  8481. }
  8482. for (int index = 0; index < AC_QUANTITY; index++)
  8483. {
  8484. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  8485. {
  8486. 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))
  8487. {
  8488. //Reserved
  8489. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  8490. }
  8491. 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))
  8492. {
  8493. //Reserved
  8494. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  8495. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8496. goto end;
  8497. }
  8498. else
  8499. {
  8500. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8501. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  8502. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  8503. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  8504. {
  8505. DEBUG_WARN("AC connector not allow start\n.");
  8506. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8507. goto end;
  8508. }
  8509. }//END FOR ELSE
  8510. }
  8511. }// END FOR AC_QUANTITY
  8512. }
  8513. if(chargingProfileIsNULL == FALSE)
  8514. {
  8515. if(strcmp((char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8516. {
  8517. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8518. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8519. //memset idTag
  8520. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8521. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8522. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8523. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8524. // Save profile to file
  8525. sprintf(cmdBuf, "rm -f /Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8526. system(cmdBuf);
  8527. sprintf(cmdBuf, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  8528. fp = fopen(cmdBuf, "w");
  8529. 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));
  8530. fclose(fp);
  8531. }
  8532. else
  8533. {
  8534. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  8535. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8536. }
  8537. }
  8538. else
  8539. {
  8540. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  8541. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8542. //memset idTag
  8543. memset((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  8544. strcpy((char *)ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8545. memset((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  8546. strcpy((char *)ShmOCPP16DataPH->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].IdTag);
  8547. }
  8548. }
  8549. else
  8550. {
  8551. DEBUG_WARN("Connector id over\n.");
  8552. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8553. //sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8554. }
  8555. end:
  8556. json_object_put(RemoteStartTransaction);
  8557. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  8558. {
  8559. ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  8560. sprintf((char *)ShmOCPP16DataPH->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  8561. }
  8562. //OCPP send RemoteStartConfirmation by first.
  8563. sendRemoteStartConfirmation(uuid, comfirmstr);
  8564. return result;
  8565. }
  8566. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  8567. {
  8568. mtrace();
  8569. int result = FAIL;
  8570. int match = FALSE;
  8571. int GunNO = 0;
  8572. int tempIndex = 0;
  8573. int transactionIdInt=0;
  8574. int transactionIdIsNULL= TRUE;
  8575. char comfirmstr[20];
  8576. json_object *RemoteStopTransaction;
  8577. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  8578. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  8579. if(server_pending == TRUE)
  8580. {
  8581. return 0;
  8582. }
  8583. RemoteStopTransaction = json_tokener_parse(payload);
  8584. if(!is_error(RemoteStopTransaction))
  8585. {
  8586. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  8587. {
  8588. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  8589. transactionIdIsNULL = FALSE;
  8590. }
  8591. }
  8592. json_object_put(RemoteStopTransaction);
  8593. if(transactionIdIsNULL == FALSE)
  8594. {
  8595. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  8596. {
  8597. if(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  8598. {
  8599. //check Transaction active
  8600. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8601. {
  8602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8603. {
  8604. tempIndex = ((gun_index==2) ? 1: 0);
  8605. }
  8606. else
  8607. {
  8608. tempIndex = gun_index;
  8609. }
  8610. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8611. {
  8612. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8613. {
  8614. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8615. {
  8616. match = TRUE;
  8617. GunNO = gun_index;
  8618. }
  8619. }
  8620. }// END FOR CHAdeMO_QUANTITY
  8621. }
  8622. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8623. {
  8624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8625. {
  8626. tempIndex = ((gun_index==2) ? 1: 0);
  8627. }
  8628. else
  8629. {
  8630. tempIndex = gun_index;
  8631. }
  8632. for (int index = 0; index < CCS_QUANTITY; index++)
  8633. {
  8634. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8635. {
  8636. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8637. {
  8638. match = TRUE;
  8639. GunNO = gun_index;
  8640. }
  8641. }
  8642. }// END FOR CCS_QUANTITY
  8643. }
  8644. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8645. {
  8646. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8647. {
  8648. tempIndex = ((gun_index==2) ? 1: 0);
  8649. }
  8650. else
  8651. {
  8652. tempIndex = gun_index;
  8653. }
  8654. for (int index = 0; index < GB_QUANTITY; index++)
  8655. {
  8656. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8657. {
  8658. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8659. {
  8660. match = TRUE;
  8661. GunNO = gun_index;
  8662. }
  8663. }
  8664. }// END FOR GB_QUANTITY
  8665. }
  8666. else if(gunType[gun_index] == GUN_TYPE_DO)
  8667. {
  8668. tempIndex = gun_index;
  8669. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8670. {
  8671. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8672. {
  8673. 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
  8674. {
  8675. match = TRUE;
  8676. GunNO = gun_index;
  8677. }
  8678. }
  8679. }// END FOR GB_QUANTITY
  8680. }
  8681. else
  8682. {
  8683. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8684. {
  8685. tempIndex = 2;
  8686. }
  8687. else
  8688. {
  8689. tempIndex = gun_index;
  8690. }
  8691. for (int index = 0; index < AC_QUANTITY; index++)
  8692. {
  8693. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8694. {
  8695. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  8696. {
  8697. match = TRUE;
  8698. GunNO = gun_index;
  8699. }
  8700. }
  8701. }// END FOR CHAdeMO_QUANTITY
  8702. } // END FOR AC ELSE
  8703. }// CHECK IF ResponseTransactionId == transactionIdInt
  8704. }//END FOR
  8705. if( match == TRUE)
  8706. {
  8707. ShmOCPP16DataPH->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  8708. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  8709. sprintf((char *)ShmOCPP16DataPH->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  8710. }
  8711. else
  8712. {
  8713. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8714. }
  8715. }
  8716. else
  8717. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  8718. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  8719. return result;
  8720. }
  8721. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  8722. {
  8723. mtrace();
  8724. int result = FAIL;
  8725. int connectorIdInt=0, reservationIdInt=0;
  8726. int tempIndex = 0;
  8727. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  8728. char comfirmstr[20]={0};
  8729. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  8730. int c = 0;
  8731. char *loc;
  8732. //char *ptr;
  8733. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  8734. strcpy(sstrtemp, stringtrimspace(payload));
  8735. //***(1)connectorId ****/
  8736. c=0;
  8737. loc = strstr(sstrtemp, "connectorId");
  8738. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8739. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  8740. {
  8741. sstr[c] = loc[strlen("connectorId")+2+c];
  8742. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8743. c++;
  8744. }
  8745. sstr[c] = '\0';
  8746. connectorIdInt = atoi(sstr);
  8747. //***(2)expiryDate ****/
  8748. loc = strstr(sstrtemp, "expiryDate");
  8749. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8750. c = 0;
  8751. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  8752. {
  8753. sstr[c] = loc[3+strlen("expiryDate")+c];
  8754. c++;
  8755. }
  8756. sstr[c] = '\0';
  8757. strcpy(expiryDatestr, sstr);
  8758. //***(3)idTag ****/
  8759. loc = strstr(sstrtemp, "idTag");
  8760. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8761. c = 0;
  8762. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  8763. {
  8764. sstr[c] = loc[3+strlen("idTag")+c];
  8765. c++;
  8766. }
  8767. sstr[c] = '\0';
  8768. strcpy(idTagstr, sstr);
  8769. //***(4)parentIdTag ****/
  8770. loc = strstr(sstrtemp, "parentIdTag");
  8771. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8772. c = 0;
  8773. if(loc == NULL)
  8774. {
  8775. strcpy(parentIdTagstr, "");
  8776. }
  8777. else
  8778. {
  8779. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8780. {
  8781. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8782. c++;
  8783. }
  8784. sstr[c] = '\0';
  8785. strcpy(parentIdTagstr, sstr);
  8786. }
  8787. //***(5)reservationId ****/
  8788. c=0;
  8789. loc = strstr(sstrtemp, "reservationId");
  8790. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8791. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  8792. {
  8793. sstr[c] = loc[strlen("reservationId")+2+c];
  8794. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8795. c++;
  8796. }
  8797. sstr[c] = '\0';
  8798. reservationIdInt = atoi(sstr);
  8799. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8800. /*
  8801. enum SYSTEM_STATUS
  8802. {
  8803. SYS_MODE_BOOTING = 0,
  8804. SYS_MODE_IDLE = 1,
  8805. SYS_MODE_AUTHORIZING = 2,
  8806. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  8807. SYS_MODE_REASSIGN = 4,
  8808. SYS_MODE_PREPARING = 5,
  8809. SYS_MODE_PREPARE_FOR_EV = 6,
  8810. SYS_MODE_PREPARE_FOR_EVSE = 7,
  8811. SYS_MODE_CHARGING = 8,
  8812. SYS_MODE_TERMINATING = 9,
  8813. SYS_MODE_COMPLETE = 10,
  8814. SYS_MODE_ALARM = 11,
  8815. SYS_MODE_FAULT = 12,
  8816. SYS_MODE_RESERVATION = 13,
  8817. SYS_MODE_BOOKING = 14,
  8818. SYS_MODE_MAINTAIN = 15,
  8819. SYS_MODE_DEBUG = 16,
  8820. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  8821. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  8822. SYS_MODE_UPDATE = 19
  8823. };
  8824. */
  8825. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  8826. {
  8827. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8828. goto end;
  8829. }
  8830. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  8831. {
  8832. //check Transaction active
  8833. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  8834. {
  8835. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8836. {
  8837. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8838. }
  8839. else
  8840. {
  8841. tempIndex = connectorIdInt -1;
  8842. }
  8843. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8844. {
  8845. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8846. {
  8847. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  8848. {
  8849. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8850. {
  8851. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8852. {
  8853. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8854. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8855. }
  8856. 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'))
  8857. {
  8858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8859. }
  8860. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8861. {
  8862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8863. }
  8864. else
  8865. {
  8866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8867. }
  8868. }
  8869. 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
  8870. {
  8871. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8872. }
  8873. }
  8874. else
  8875. {
  8876. //replace reservation
  8877. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8879. }
  8880. }
  8881. } // END FOR CHAdeMO_QUANTITY
  8882. }
  8883. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  8884. {
  8885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8886. {
  8887. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8888. }
  8889. else
  8890. {
  8891. tempIndex = connectorIdInt -1;
  8892. }
  8893. for (int index = 0; index < CCS_QUANTITY; index++)
  8894. {
  8895. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8896. {
  8897. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  8898. {
  8899. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8900. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  8901. {
  8902. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8903. {
  8904. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8906. }
  8907. 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'))
  8908. {
  8909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8910. }
  8911. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  8912. {
  8913. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8914. }
  8915. else
  8916. {
  8917. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8918. }
  8919. }
  8920. 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
  8921. {
  8922. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8923. }
  8924. }
  8925. else
  8926. {
  8927. //replace reservation
  8928. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8929. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8930. }
  8931. }
  8932. } // END FOR CCS_QUANTITY
  8933. }
  8934. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  8935. {
  8936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8937. {
  8938. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8939. }
  8940. else
  8941. {
  8942. tempIndex = connectorIdInt -1;
  8943. }
  8944. for (int index = 0; index < GB_QUANTITY; index++)
  8945. {
  8946. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8947. {
  8948. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8949. {
  8950. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8951. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  8952. {
  8953. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8954. {
  8955. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8956. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8957. }
  8958. 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'))
  8959. {
  8960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8961. }
  8962. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  8963. {
  8964. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8965. }
  8966. else
  8967. {
  8968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8969. }
  8970. }
  8971. 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
  8972. {
  8973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8974. }
  8975. }
  8976. else
  8977. {
  8978. //replace reservation
  8979. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  8980. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8981. }
  8982. }
  8983. }// END FOR GB_QUANTITY
  8984. }
  8985. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  8986. {
  8987. tempIndex = connectorIdInt -1;
  8988. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8989. {
  8990. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8991. {
  8992. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  8993. {
  8994. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8995. 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
  8996. {
  8997. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8998. {
  8999. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9001. }
  9002. 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'))
  9003. {
  9004. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9005. }
  9006. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9007. {
  9008. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9009. }
  9010. else
  9011. {
  9012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9013. }
  9014. }
  9015. 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
  9016. {
  9017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9018. }
  9019. }
  9020. else
  9021. {
  9022. //replace reservation
  9023. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9024. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9025. }
  9026. }
  9027. }// END FOR GB_QUANTITY
  9028. }
  9029. else
  9030. {
  9031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9032. {
  9033. tempIndex = 2;
  9034. }
  9035. else
  9036. {
  9037. tempIndex = (connectorIdInt -1);
  9038. }
  9039. for (int index = 0; index < AC_QUANTITY; index++)
  9040. {
  9041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9042. {
  9043. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9044. {
  9045. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  9046. {
  9047. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9048. {
  9049. 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))
  9050. {
  9051. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9052. }
  9053. else
  9054. {
  9055. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9057. }
  9058. }
  9059. 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'))
  9060. {
  9061. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9062. }
  9063. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  9064. {
  9065. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9066. }
  9067. else
  9068. {
  9069. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9070. }
  9071. }
  9072. 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
  9073. {
  9074. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9075. }
  9076. }
  9077. else
  9078. {
  9079. //replace reservation
  9080. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  9081. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9082. }
  9083. }
  9084. } // END FOR AC_QUANTITY
  9085. }
  9086. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9087. }
  9088. else if(connectorIdInt == 0)
  9089. {
  9090. //check Transaction active
  9091. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9092. {
  9093. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  9094. {
  9095. 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'))
  9096. {
  9097. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9098. goto end;
  9099. }
  9100. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9101. {
  9102. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9103. goto end;
  9104. }
  9105. 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
  9106. {
  9107. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9108. goto end;
  9109. }
  9110. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9111. {
  9112. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9113. goto end;
  9114. }
  9115. }
  9116. }// END FOR CHAdeMO_QUANTITY
  9117. for (int index = 0; index < CCS_QUANTITY; index++)
  9118. {
  9119. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  9120. {
  9121. 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'))
  9122. {
  9123. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9124. goto end;
  9125. }
  9126. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  9127. {
  9128. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9129. goto end;
  9130. }
  9131. 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
  9132. {
  9133. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9134. goto end;
  9135. }
  9136. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9137. {
  9138. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9139. goto end;
  9140. }
  9141. }
  9142. } // END FOR CCS_QUANTITY
  9143. for (int index = 0; index < GB_QUANTITY; index++)
  9144. {
  9145. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  9146. {
  9147. 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'))
  9148. {
  9149. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9150. goto end;
  9151. }
  9152. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9153. {
  9154. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9155. goto end;
  9156. }
  9157. 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
  9158. {
  9159. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9160. goto end;
  9161. }
  9162. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9163. {
  9164. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9165. goto end;
  9166. }
  9167. }
  9168. } // END FOR GB_QUANTITY
  9169. for (int index = 0; index < AC_QUANTITY; index++)
  9170. {
  9171. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  9172. {
  9173. 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'))
  9174. {
  9175. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  9176. goto end;
  9177. }
  9178. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  9179. {
  9180. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9181. goto end;
  9182. }
  9183. 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
  9184. {
  9185. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  9186. goto end;
  9187. }
  9188. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9189. {
  9190. 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))
  9191. {
  9192. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  9193. goto end;
  9194. }
  9195. }
  9196. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  9197. {
  9198. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9199. goto end;
  9200. }
  9201. }
  9202. }// END FOR AC_QUANTITY
  9203. //The connectorId is 0
  9204. ShmOCPP16DataPH->CsMsg.bits[0].ReserveNowReq = 1;
  9205. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  9206. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  9207. ShmOCPP16DataPH->ReserveNow[0].ConnectorId = connectorIdInt;
  9208. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  9209. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].IdTag, "%s" , idTagstr);
  9210. sprintf((char *)ShmOCPP16DataPH->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  9211. ShmOCPP16DataPH->ReserveNow[0].ReservationId = reservationIdInt;
  9212. strcpy((char *)ShmOCPP16DataPH->ReserveNow[0].guid, uuid);
  9213. result = TRUE;
  9214. return result;
  9215. }
  9216. else
  9217. {
  9218. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  9219. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  9220. }
  9221. if(strcmp(comfirmstr,"Accepted") == 0)
  9222. {
  9223. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  9224. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  9225. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  9226. sprintf((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  9227. ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  9228. strcpy((char *)ShmOCPP16DataPH->ReserveNow[connectorIdInt-1].guid, uuid);
  9229. result = TRUE;
  9230. return result;
  9231. }
  9232. end:
  9233. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  9234. //ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  9235. return result;
  9236. }
  9237. int handleResetRequest(char *uuid, char *payload)
  9238. {
  9239. mtrace();
  9240. int result = FAIL;
  9241. char sstr[10]={0},sstrtemp[30]={ 0 };
  9242. char typestr[10]={0};
  9243. char comfirmstr[20]={0};
  9244. int c = 0;
  9245. char *loc;
  9246. DEBUG_INFO("handleResetRequest...\n");
  9247. strcpy(sstrtemp, stringtrimspace(payload));
  9248. loc = strstr(sstrtemp, "type");
  9249. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9250. c = 0;
  9251. while (loc[3+strlen("type")+c] != '\"')
  9252. {
  9253. sstr[c] = loc[3+strlen("type")+c];
  9254. c++;
  9255. }
  9256. sstr[c] = '\0';
  9257. strcpy(typestr,sstr);
  9258. sprintf((char *)ShmOCPP16DataPH->Reset.Type, "%s" ,typestr);
  9259. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  9260. {
  9261. ShmOCPP16DataPH->MsMsg.bits.ResetReq = 1;
  9262. strcpy((char *)ShmOCPP16DataPH->Reset.guid, uuid);
  9263. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Accepted]);
  9264. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9265. }
  9266. else
  9267. {
  9268. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  9269. sprintf((char *)ShmOCPP16DataPH->Reset.ResponseStatus, "%s" ,comfirmstr);
  9270. result = PASS;
  9271. }
  9272. sendResetConfirmation(uuid, comfirmstr);
  9273. return result;
  9274. }
  9275. int handleSendLocalListRequest(char *uuid, char *payload)
  9276. {
  9277. mtrace();
  9278. int result = FAIL;
  9279. char comfirmstr[20];
  9280. int checkState_Faulted = FALSE;
  9281. json_object *SendLocalList;
  9282. DEBUG_INFO("handleSendLocalListRequest...\n");
  9283. if(strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  9284. {
  9285. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9286. goto end;
  9287. }
  9288. //check Charge Point state
  9289. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9290. {
  9291. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9292. {
  9293. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9294. }
  9295. }
  9296. for (int index = 0; index < CCS_QUANTITY; index++)
  9297. {
  9298. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9299. {
  9300. checkState_Faulted = TRUE; //OCPP Status
  9301. }
  9302. }
  9303. for (int index = 0; index < GB_QUANTITY; index++)
  9304. {
  9305. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9306. {
  9307. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9308. }
  9309. }
  9310. //check Charge Point state
  9311. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9312. {
  9313. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9314. {
  9315. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9316. }
  9317. }
  9318. //check Charge Point state
  9319. for (int index = 0; index < AC_QUANTITY; index++)
  9320. {
  9321. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  9322. {
  9323. checkState_Faulted = TRUE; //OCPP Status: Faulted
  9324. }
  9325. }
  9326. if(checkState_Faulted == TRUE)
  9327. {
  9328. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9329. goto end;
  9330. }
  9331. // Parsing payload
  9332. SendLocalList = json_tokener_parse(payload);
  9333. if(!is_error(SendLocalList))
  9334. {
  9335. // Required data
  9336. ShmOCPP16DataPH->SendLocalList.ListVersion = json_object_get_int(json_object_object_get(SendLocalList, "listVersion"));
  9337. sprintf((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  9338. // Optional data
  9339. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  9340. {
  9341. //Check UpdateType
  9342. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9343. {
  9344. //Local list full update
  9345. DEBUG_INFO("Local list full update.\n");
  9346. OCPP_getListVerion();
  9347. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9348. {
  9349. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  9350. goto end;
  9351. }
  9352. OCPP_cleanLocalList();
  9353. }
  9354. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9355. {
  9356. //Local list different update
  9357. DEBUG_INFO("Local list different update.\n");
  9358. OCPP_getListVerion();
  9359. if(ShmOCPP16DataPH->SendLocalList.ListVersion < locallistVersion)
  9360. {
  9361. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  9362. goto end;
  9363. }
  9364. }
  9365. else
  9366. {
  9367. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  9368. goto end;
  9369. }
  9370. memset(ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  9371. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  9372. {
  9373. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag, "%s", json_object_get_string(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTag")));
  9374. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  9375. {
  9376. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  9377. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate") != NULL)
  9378. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "expiryDate")));
  9379. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag") != NULL)
  9380. sprintf((char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "parentIdTag")));
  9381. }
  9382. // Add to db
  9383. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9384. {
  9385. //Local list full update
  9386. DEBUG_INFO("Local list full update item: %d, listVer: %d, %s, %s, %s, %s.\n",
  9387. idx,
  9388. ShmOCPP16DataPH->SendLocalList.ListVersion,
  9389. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9390. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9391. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9392. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9393. // update list
  9394. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  9395. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9396. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9397. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9398. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9399. }
  9400. else if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9401. {
  9402. DEBUG_INFO("Local list diff update item: %d,listVer: %d, %s, %s, %s, %s.\n",
  9403. idx,
  9404. ShmOCPP16DataPH->SendLocalList.ListVersion,
  9405. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9406. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9407. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9408. ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9409. OCPP_addLocalList(ShmOCPP16DataPH->SendLocalList.ListVersion,
  9410. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTag,
  9411. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ParentIdTag,
  9412. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.ExpiryDate,
  9413. (char*)ShmOCPP16DataPH->SendLocalList.LocalAuthorizationList[idx].IdTagInfo.Status);
  9414. }
  9415. }
  9416. }
  9417. else
  9418. {
  9419. //Check UpdateType
  9420. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Full]) == 0)
  9421. {
  9422. //Local list full update
  9423. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  9424. OCPP_cleanLocalList();
  9425. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9426. goto end;
  9427. }
  9428. if(strcmp((char*)ShmOCPP16DataPH->SendLocalList.UpdateType, UpdateTypeStr[Differential]) == 0)
  9429. {
  9430. //Local list different update
  9431. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  9432. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9433. goto end;
  9434. }
  9435. }
  9436. result = PASS;
  9437. }
  9438. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  9439. end:
  9440. json_object_put(SendLocalList);
  9441. sendSendLocalListConfirmation(uuid, comfirmstr);
  9442. return result;
  9443. }
  9444. #define MAX 200
  9445. int handleSetChargingProfileRequest(char *uuid, char *payload)
  9446. {
  9447. mtrace();
  9448. int result = FAIL;
  9449. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  9450. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  9451. char chargingProfilePurposeStr[30]={0};
  9452. char chargingProfileKindStr[16]={0};
  9453. char recurrencyKindStr[10]={0};
  9454. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  9455. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  9456. int chargingSchedulePeriodCount = 0;
  9457. char comfirmstr[20]={0};
  9458. int meet= FALSE;
  9459. FILE *fptr1;
  9460. char filename[MAX]={0};
  9461. char tempfile[] = "/Storage/OCPP_PH/SetChargingProfiletemp.json";
  9462. char rmFileCmd[50]={0};
  9463. char tempchargingProfilePurposeStr[30]={0};
  9464. char word[1600]={0};
  9465. int n_chargingProfile = 0;
  9466. json_object *SetChargingProfile;
  9467. DEBUG_INFO("handleSetChargingProfileRequest\n");
  9468. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  9469. SetChargingProfile = json_tokener_parse(payload);
  9470. if(!is_error(SetChargingProfile))
  9471. {
  9472. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  9473. {
  9474. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  9475. if(connectorIdInt == 0)
  9476. {
  9477. memset(&ShmOCPP16DataPH->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  9478. ShmOCPP16DataPH->SetChargingProfile[0].ConnectorId = connectorIdInt;
  9479. }
  9480. else
  9481. {
  9482. memset(&ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  9483. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  9484. }
  9485. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  9486. }
  9487. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  9488. {
  9489. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9490. {
  9491. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9492. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9493. {
  9494. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9495. }
  9496. else
  9497. {
  9498. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  9499. }
  9500. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  9501. }
  9502. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9503. {
  9504. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  9505. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9506. {
  9507. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  9508. }
  9509. else
  9510. {
  9511. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  9512. }
  9513. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  9514. }
  9515. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9516. {
  9517. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9518. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9519. {
  9520. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9521. }
  9522. else
  9523. {
  9524. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  9525. }
  9526. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  9527. }
  9528. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  9529. {
  9530. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  9531. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9532. {
  9533. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9534. }
  9535. else
  9536. {
  9537. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  9538. }
  9539. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  9540. }
  9541. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  9542. {
  9543. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  9544. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9545. {
  9546. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  9547. }
  9548. else
  9549. {
  9550. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  9551. }
  9552. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  9553. }
  9554. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  9555. {
  9556. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  9557. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9558. {
  9559. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9560. }
  9561. else
  9562. {
  9563. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  9564. }
  9565. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  9566. }
  9567. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  9568. {
  9569. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  9570. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9571. {
  9572. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  9573. }
  9574. else
  9575. {
  9576. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  9577. }
  9578. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  9579. }
  9580. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  9581. {
  9582. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  9583. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9584. {
  9585. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  9586. }
  9587. else
  9588. {
  9589. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  9590. }
  9591. //DEBUG_INFO("validToStr: %s\n", validToStr);
  9592. }
  9593. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  9594. {
  9595. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  9596. {
  9597. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  9598. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9599. {
  9600. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9601. }
  9602. else
  9603. {
  9604. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  9605. }
  9606. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  9607. }
  9608. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  9609. {
  9610. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  9611. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9612. {
  9613. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9614. }
  9615. else
  9616. {
  9617. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  9618. }
  9619. //DEBUG_INFO("durationInt: %d\n", durationInt);
  9620. }
  9621. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  9622. {
  9623. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  9624. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9625. {
  9626. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9627. }
  9628. else
  9629. {
  9630. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  9631. }
  9632. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  9633. }
  9634. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  9635. {
  9636. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  9637. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9638. {
  9639. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9640. }
  9641. else
  9642. {
  9643. strcpy((char *)ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  9644. }
  9645. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  9646. }
  9647. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  9648. {
  9649. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  9650. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  9651. if(chargingSchedulePeriodCount <= 10)
  9652. {
  9653. 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++)
  9654. {
  9655. 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)
  9656. {
  9657. 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"));
  9658. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9659. {
  9660. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9661. }
  9662. else
  9663. {
  9664. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  9665. }
  9666. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  9667. }
  9668. 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)
  9669. {
  9670. 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"));
  9671. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9672. {
  9673. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9674. }
  9675. else
  9676. {
  9677. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  9678. }
  9679. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  9680. }
  9681. 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)
  9682. {
  9683. 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"));
  9684. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  9685. {
  9686. ShmOCPP16DataPH->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9687. }
  9688. else
  9689. {
  9690. ShmOCPP16DataPH->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  9691. }
  9692. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  9693. }
  9694. }
  9695. }
  9696. }
  9697. }
  9698. }
  9699. }
  9700. json_object_put(SetChargingProfile);
  9701. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  9702. {
  9703. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9704. goto end;
  9705. }
  9706. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  9707. {
  9708. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  9709. if(connectorIdInt != 0)
  9710. {
  9711. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9712. goto end;
  9713. }
  9714. strcpy(filename, ChargePointMaxProfile_JSON );
  9715. fptr1 = fopen(filename, "r");
  9716. if (!fptr1)
  9717. {
  9718. //file not exist
  9719. DEBUG_INFO("Unable to open the input file!!\n");
  9720. fptr1 = fopen(filename, "w+");
  9721. }
  9722. else
  9723. {
  9724. //Check Charging Profile Count
  9725. while(fscanf(fptr1, "%s", word) != EOF)
  9726. {
  9727. //DEBUG_INFO("word=%s\n",word);
  9728. if(strstr(word, "chargingProfileId")!= NULL)
  9729. {
  9730. //DEBUG_INFO("test chargingProfileId \n");
  9731. n_chargingProfile = n_chargingProfile + 1;
  9732. //DEBUG_INFO("chargingProfileId Found\n");
  9733. }
  9734. }
  9735. }
  9736. fclose(fptr1);
  9737. }
  9738. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  9739. {
  9740. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  9741. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9742. {
  9743. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9744. goto end;
  9745. }
  9746. memset(filename, 0, ARRAY_SIZE(filename));
  9747. sprintf(filename, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", connectorIdInt);
  9748. fptr1 = fopen(filename, "r");
  9749. if (!fptr1)
  9750. {
  9751. //file not exist
  9752. //DEBUG_INFO("Unable to open the input file!!\n");
  9753. fptr1 = fopen(filename, "w+");
  9754. }
  9755. else
  9756. {
  9757. //Check Charging Profile Count
  9758. while(fscanf(fptr1, "%s", word) != EOF)
  9759. {
  9760. //DEBUG_INFO("word=%s\n",word);
  9761. if(strstr(word, "chargingProfileId")!= NULL)
  9762. {
  9763. //DEBUG_INFO("test chargingProfileId \n");
  9764. n_chargingProfile = n_chargingProfile + 1;
  9765. //DEBUG_INFO("chargingProfileId Found\n");
  9766. }
  9767. }
  9768. }
  9769. fclose(fptr1);
  9770. }
  9771. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  9772. {
  9773. //printf("set chargingProfile 1-4\n");
  9774. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  9775. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  9776. if(connectorIdInt == 0)
  9777. {
  9778. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9779. goto end;
  9780. }
  9781. int tempIndex = 0;
  9782. //check Transaction active
  9783. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  9784. {
  9785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9786. {
  9787. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9788. }
  9789. else
  9790. {
  9791. tempIndex = connectorIdInt -1;
  9792. }
  9793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9794. {
  9795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  9796. {
  9797. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus) &&
  9798. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9799. {
  9800. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9801. {
  9802. meet = TRUE;
  9803. break;
  9804. }
  9805. }
  9806. }
  9807. }
  9808. }
  9809. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  9810. {
  9811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9812. {
  9813. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9814. }
  9815. else
  9816. {
  9817. tempIndex = connectorIdInt -1;
  9818. }
  9819. for (int index = 0; index < CCS_QUANTITY; index++)
  9820. {
  9821. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9822. {
  9823. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus) &&
  9824. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9825. {
  9826. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9827. {
  9828. meet = TRUE;
  9829. break;
  9830. }
  9831. }
  9832. }
  9833. }
  9834. }
  9835. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  9836. {
  9837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9838. {
  9839. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9840. }
  9841. else
  9842. {
  9843. tempIndex = connectorIdInt -1;
  9844. }
  9845. for (int index = 0; index < GB_QUANTITY; index++)
  9846. {
  9847. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9848. {
  9849. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus) &&
  9850. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9851. {
  9852. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9853. {
  9854. meet = TRUE;
  9855. break;
  9856. }
  9857. }
  9858. }
  9859. }
  9860. }
  9861. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  9862. {
  9863. tempIndex = connectorIdInt -1;
  9864. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9865. {
  9866. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9867. {
  9868. if((SYS_MODE_PREPARING <= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus) &&
  9869. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_TERMINATING)) // S_CHARGING
  9870. {
  9871. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9872. {
  9873. meet = TRUE;
  9874. break;
  9875. }
  9876. }
  9877. }
  9878. }
  9879. }
  9880. else
  9881. {
  9882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9883. {
  9884. tempIndex = 2;
  9885. }
  9886. else
  9887. {
  9888. tempIndex = (connectorIdInt -1);
  9889. }
  9890. for (int index = 0; index < AC_QUANTITY; index++)
  9891. {
  9892. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9893. {
  9894. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9895. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // S_CHARGING
  9896. {
  9897. if(transactionIdInt == ShmOCPP16DataPH->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9898. {
  9899. meet = TRUE;
  9900. break;
  9901. }
  9902. }
  9903. }
  9904. }
  9905. }
  9906. //check Transaction active
  9907. if(meet == FALSE)
  9908. {
  9909. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9910. goto end;
  9911. }
  9912. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9913. {
  9914. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9915. goto end;
  9916. }
  9917. sprintf(filename, "/Storage/OCPP_PH/TxProfile_%d.json", connectorIdInt);
  9918. fptr1 = fopen(filename, "r");
  9919. if (!fptr1)
  9920. {
  9921. //file not exist
  9922. DEBUG_INFO("Unable to open the input file!!\n");
  9923. fptr1 = fopen(filename, "w+");
  9924. }
  9925. else
  9926. {
  9927. //Check Charging Profile Count
  9928. while(fscanf(fptr1, "%s", word) != EOF)
  9929. {
  9930. //DEBUG_INFO("word=%s\n",word);
  9931. if(strstr(word, "chargingProfileId")!= NULL)
  9932. {
  9933. //DEBUG_INFO("test chargingProfileId \n");
  9934. n_chargingProfile = n_chargingProfile + 1;
  9935. //DEBUG_INFO("chargingProfileId Found\n");
  9936. }
  9937. }
  9938. }
  9939. fclose(fptr1);
  9940. }
  9941. // Check ChargeProfileMaxStackLevel
  9942. if(n_chargingProfile >= atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9943. {
  9944. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9945. goto end;
  9946. }
  9947. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9948. {
  9949. int i = 0;
  9950. char fnametemp[200]={0};
  9951. n_chargingProfile = 0;
  9952. //Check ChargePointMaxProfile.json exit
  9953. if((access("/Storage/OCPP_PH/ChargePointMaxProfile.json",F_OK))!=-1)
  9954. {
  9955. fptr1 = fopen("/Storage/OCPP_PH/ChargePointMaxProfile.json", "r");
  9956. //Check Charging Profile Count
  9957. while(fscanf(fptr1, "%s", word) != EOF)
  9958. {
  9959. //DEBUG_INFO("word=%s\n",word);
  9960. if(strstr(word, "chargingProfileId")!= NULL)
  9961. {
  9962. //DEBUG_INFO("test chargingProfileId \n");
  9963. n_chargingProfile = n_chargingProfile + 1;
  9964. i = i + 1;
  9965. //DEBUG_INFO("chargingProfileId Found\n");
  9966. }
  9967. memset(word, 0, ARRAY_SIZE(word));
  9968. }
  9969. fclose(fptr1);
  9970. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9971. }
  9972. //Check TxDefaultProfile_0.json exit
  9973. if((access("/Storage/OCPP_PH/TxDefaultProfile_0.json",F_OK))!=-1)
  9974. {
  9975. i = 0;
  9976. fptr1 = fopen("/Storage/OCPP_PH/TxDefaultProfile_0.json", "r");
  9977. //Check Charging Profile Count
  9978. while(fscanf(fptr1, "%s", word) != EOF)
  9979. {
  9980. //DEBUG_INFO("word=%s\n",word);
  9981. if(strstr(word, "chargingProfileId")!= NULL)
  9982. {
  9983. //DEBUG_INFO("test chargingProfileId \n");
  9984. n_chargingProfile = n_chargingProfile + 1;
  9985. i = i + 1;
  9986. //DEBUG_INFO("chargingProfileId Found\n");
  9987. }
  9988. memset(word, 0, ARRAY_SIZE(word));
  9989. }
  9990. fclose(fptr1);
  9991. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9992. }
  9993. //Check TxDefaultProfile_%d.json
  9994. for(int j=1; j <= gunTotalNumber; j++)
  9995. {
  9996. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9997. sprintf(fnametemp, "/Storage/OCPP_PH/TxDefaultProfile_%d.json", j);
  9998. if((access(fnametemp,F_OK))!=-1)
  9999. {
  10000. i = 0;
  10001. fptr1 = fopen(fnametemp, "r");
  10002. //Check Charging Profile Count
  10003. while(fscanf(fptr1, "%s", word) != EOF)
  10004. {
  10005. //DEBUG_INFO("word=%s\n",word);
  10006. if(strstr(word, "chargingProfileId")!= NULL)
  10007. {
  10008. //DEBUG_INFO("test chargingProfileId \n");
  10009. n_chargingProfile = n_chargingProfile + 1;
  10010. i = i + 1;
  10011. //DEBUG_INFO("chargingProfileId Found\n");
  10012. }
  10013. memset(word, 0, ARRAY_SIZE(word));
  10014. }
  10015. fclose(fptr1);
  10016. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10017. }
  10018. }
  10019. //Check TxProfile_%d.json
  10020. for(int j=1; j <= gunTotalNumber; j++)
  10021. {
  10022. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10023. sprintf(fnametemp, "/Storage/OCPP_PH/TxProfile_%d.json", j);
  10024. if((access(fnametemp,F_OK))!=-1)
  10025. {
  10026. i = 0;
  10027. fptr1 = fopen(fnametemp, "r");
  10028. //Check Charging Profile Count
  10029. while(fscanf(fptr1, "%s", word) != EOF)
  10030. {
  10031. //DEBUG_INFO("word=%s\n",word);
  10032. if(strstr(word, "chargingProfileId")!= NULL)
  10033. {
  10034. //DEBUG_INFO("test chargingProfileId \n");
  10035. n_chargingProfile = n_chargingProfile + 1;
  10036. i = i + 1;
  10037. //DEBUG_INFO("chargingProfileId Found\n");
  10038. }
  10039. memset(word, 0, ARRAY_SIZE(word));
  10040. }
  10041. fclose(fptr1);
  10042. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  10043. }
  10044. }
  10045. if( n_chargingProfile > atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  10046. {
  10047. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  10048. goto end;
  10049. }
  10050. }
  10051. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  10052. //**********************************Write to File********************************************************/
  10053. FILE *infile;
  10054. FILE *outfile;
  10055. infile = fopen (filename, "r");
  10056. outfile = fopen (tempfile, "w");
  10057. int d =0;
  10058. d = fgetc(infile);
  10059. rewind(infile);
  10060. if(d == EOF)
  10061. {
  10062. // Profile is empty
  10063. fprintf(outfile,"%s\n",payload);
  10064. fclose(infile);
  10065. fclose(outfile);
  10066. sprintf(rmFileCmd,"rm -f %s",filename);
  10067. system(rmFileCmd);
  10068. rename(tempfile, filename);
  10069. }
  10070. else
  10071. {
  10072. // Profile is not empty
  10073. char buf[2048]={0};
  10074. int ChargingProfileAdded = FALSE;
  10075. while (fgets(buf, sizeof(buf), infile) != NULL)
  10076. {
  10077. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  10078. json_object *tmpChargingProfile;
  10079. tmpChargingProfile = json_tokener_parse(buf);
  10080. if(!is_error(SetChargingProfile))
  10081. {
  10082. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  10083. {
  10084. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  10085. }
  10086. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  10087. {
  10088. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  10089. {
  10090. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  10091. }
  10092. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  10093. {
  10094. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  10095. }
  10096. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  10097. {
  10098. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  10099. }
  10100. }
  10101. }
  10102. json_object_put(tmpChargingProfile);
  10103. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  10104. {
  10105. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10106. {
  10107. //DEBUG_INFO("update set chargingProfile to file -0\n");
  10108. if(ChargingProfileAdded == FALSE)
  10109. {
  10110. fprintf(outfile,"%s\n",payload);
  10111. ChargingProfileAdded = TRUE;
  10112. }
  10113. }
  10114. else
  10115. {
  10116. if(tempstackLevelInt < stackLevelInt)
  10117. {
  10118. if(ChargingProfileAdded == FALSE)
  10119. {
  10120. fprintf(outfile,"%s\n",buf);
  10121. fprintf(outfile,"%s\n",payload);
  10122. ChargingProfileAdded = TRUE;
  10123. }
  10124. else
  10125. {
  10126. fprintf(outfile,"%s\n",buf);
  10127. }
  10128. }
  10129. else
  10130. {
  10131. if(ChargingProfileAdded == FALSE)
  10132. {
  10133. fprintf(outfile,"%s\n",buf);
  10134. fprintf(outfile,"%s\n",payload);
  10135. ChargingProfileAdded = TRUE;
  10136. }
  10137. else
  10138. {
  10139. fprintf(outfile,"%s\n",buf);
  10140. }
  10141. }
  10142. }
  10143. }
  10144. else
  10145. {
  10146. if(tempchargingProfileIdInt < chargingProfileIdInt)
  10147. {
  10148. if(ChargingProfileAdded == FALSE)
  10149. {
  10150. fprintf(outfile,"%s\n",buf);
  10151. fprintf(outfile,"%s\n",payload);
  10152. ChargingProfileAdded = TRUE;
  10153. }
  10154. else
  10155. {
  10156. fprintf(outfile,"%s\n",buf);
  10157. }
  10158. }
  10159. else if(tempstackLevelInt < stackLevelInt)
  10160. {
  10161. if(ChargingProfileAdded == FALSE)
  10162. {
  10163. fprintf(outfile,"%s\n",buf);
  10164. fprintf(outfile,"%s\n",payload);
  10165. ChargingProfileAdded = TRUE;
  10166. }
  10167. else
  10168. {
  10169. fprintf(outfile,"%s\n",buf);
  10170. }
  10171. }
  10172. else
  10173. {
  10174. if(ChargingProfileAdded == FALSE)
  10175. {
  10176. fprintf(outfile,"%s\n",buf);
  10177. fprintf(outfile,"%s\n",payload);
  10178. ChargingProfileAdded = TRUE;
  10179. }
  10180. else
  10181. {
  10182. fprintf(outfile,"%s\n",buf);
  10183. }
  10184. }
  10185. }
  10186. } // end of while loop
  10187. fclose(infile);
  10188. fclose(outfile);
  10189. sprintf(rmFileCmd,"rm -f %s",filename);
  10190. system(rmFileCmd);
  10191. rename(tempfile, filename);
  10192. }
  10193. sleep(1);
  10194. result = TRUE;
  10195. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  10196. end:
  10197. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  10198. {
  10199. if(connectorIdInt == 0)
  10200. {
  10201. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10202. {
  10203. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16DataPH->SmartChargingProfile[idx], TRUE);
  10204. }
  10205. }
  10206. else
  10207. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16DataPH->SmartChargingProfile[connectorIdInt-1], TRUE);
  10208. }
  10209. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  10210. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10211. return result;
  10212. }
  10213. int handleTriggerMessageRequest(char *uuid, char *payload)
  10214. {
  10215. mtrace();
  10216. int result = FAIL;
  10217. int connectorIdIsNULL = FALSE;
  10218. int connectorIdInt =0;
  10219. char sstr[40]={0},sstrtemp[100]={ 0 };
  10220. char requestedMessagestr[40]={0};
  10221. char comfirmstr[20]={0};
  10222. int c = 0;
  10223. char *loc;
  10224. DEBUG_INFO("handleTriggerMessageRequest\n");
  10225. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  10226. strcpy(sstrtemp, stringtrimspace(payload));
  10227. c = 0;
  10228. loc = strstr(sstrtemp, "requestedMessage");
  10229. while (loc[3+strlen("requestedMessage")+c] != '\"')
  10230. {
  10231. sstr[c] = loc[3+strlen("requestedMessage")+c];
  10232. c++;
  10233. }
  10234. sstr[c] = '\0';
  10235. strcpy(requestedMessagestr, sstr);
  10236. c = 0;
  10237. loc = strstr(sstrtemp, "connectorId");
  10238. if(loc == NULL)
  10239. {
  10240. connectorIdIsNULL = TRUE;
  10241. }
  10242. else
  10243. {
  10244. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10245. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  10246. {
  10247. sstr[c] = loc[strlen("connectorId")+2+c];
  10248. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10249. c++;
  10250. }
  10251. sstr[c] = '\0';
  10252. connectorIdInt = atoi(sstr);
  10253. }
  10254. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  10255. {
  10256. sprintf((char *)ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  10257. ShmOCPP16DataPH->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  10258. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10259. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  10260. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  10261. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  10262. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  10263. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  10264. {
  10265. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10266. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10267. return TRUE;
  10268. }
  10269. else
  10270. {
  10271. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10272. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10273. }
  10274. }
  10275. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  10276. {
  10277. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  10278. sendTriggerMessageConfirmation(uuid,comfirmstr);
  10279. return TRUE;
  10280. }
  10281. //==========================
  10282. // Trigger message
  10283. //==========================
  10284. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10285. {
  10286. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10287. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10288. {
  10289. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10290. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10291. }
  10292. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10293. }
  10294. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  10295. {
  10296. if(strlen((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status) == 0)
  10297. sprintf((char*)ShmOCPP16DataPH->DiagnosticsStatusNotification.Status, "%s", DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  10298. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
  10299. }
  10300. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  10301. {
  10302. //sendBootNotificationRequest();
  10303. server_sign = FALSE;
  10304. }
  10305. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  10306. {
  10307. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10308. }
  10309. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  10310. {
  10311. if(connectorIdIsNULL == FALSE)
  10312. {
  10313. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10314. {
  10315. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  10316. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  10317. }
  10318. }
  10319. else
  10320. {
  10321. for(int idx=0;idx< gunTotalNumber;idx++)
  10322. {
  10323. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10324. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10325. }
  10326. }
  10327. }
  10328. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  10329. {
  10330. if(connectorIdIsNULL == FALSE)
  10331. {
  10332. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  10333. {
  10334. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].TriggerMessageReq = 1;
  10335. cpinitateMsg.bits[connectorIdInt -1].TriggerStatusNotificationReq = 1;
  10336. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  10337. }
  10338. }
  10339. else
  10340. {
  10341. for(int idx=0;idx< gunTotalNumber;idx++)
  10342. {
  10343. ShmOCPP16DataPH->CsMsg.bits[idx].TriggerMessageReq = 1;
  10344. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = 1;
  10345. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  10346. }
  10347. }
  10348. }
  10349. return result;
  10350. }
  10351. int handleUnlockConnectorRequest(char *uuid, char *payload)
  10352. {
  10353. mtrace();
  10354. int result = FAIL;
  10355. int connectorIdInt =0;
  10356. char comfirmstr[20]={0};
  10357. int tempIndex = 0;
  10358. json_object *UnlockConnector;
  10359. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  10360. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  10361. UnlockConnector = json_tokener_parse(payload);
  10362. if(!is_error(UnlockConnector))
  10363. {
  10364. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  10365. {
  10366. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  10367. }
  10368. }
  10369. json_object_put(UnlockConnector);
  10370. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  10371. if(gunTotalNumber == 0)
  10372. {
  10373. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10374. goto end;
  10375. }
  10376. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  10377. {
  10378. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10379. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  10380. goto end;
  10381. }
  10382. else
  10383. {
  10384. //check Transaction active
  10385. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  10386. {
  10387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10388. {
  10389. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10390. }
  10391. else
  10392. {
  10393. tempIndex = connectorIdInt -1;
  10394. }
  10395. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10396. {
  10397. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10398. {
  10399. //stop Transaction
  10400. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10401. }
  10402. }
  10403. }
  10404. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  10405. {
  10406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10407. {
  10408. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10409. }
  10410. else
  10411. {
  10412. tempIndex = connectorIdInt -1;
  10413. }
  10414. for (int index = 0; index < CCS_QUANTITY; index++)
  10415. {
  10416. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10417. {
  10418. //stop Transaction
  10419. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10420. }
  10421. }
  10422. }
  10423. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  10424. {
  10425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  10426. {
  10427. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  10428. }
  10429. else
  10430. {
  10431. tempIndex = connectorIdInt -1;
  10432. }
  10433. for (int index = 0; index < GB_QUANTITY; index++)
  10434. {
  10435. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  10436. {
  10437. //stop Transaction
  10438. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10439. }
  10440. }
  10441. }
  10442. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  10443. {
  10444. tempIndex = connectorIdInt -1;
  10445. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10446. {
  10447. 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)))
  10448. {
  10449. //stop Transaction
  10450. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10451. }
  10452. }
  10453. }
  10454. else
  10455. {
  10456. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10457. {
  10458. tempIndex = 2;
  10459. }
  10460. else
  10461. {
  10462. tempIndex = connectorIdInt-1;
  10463. }
  10464. for (int index = 0; index < AC_QUANTITY; index++)
  10465. {
  10466. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  10467. {
  10468. ShmOCPP16DataPH->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  10469. }
  10470. }
  10471. }
  10472. ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  10473. strcpy((char *)ShmOCPP16DataPH->UnlockConnector[connectorIdInt-1].guid, uuid);
  10474. result = TRUE;
  10475. return result;
  10476. }
  10477. end:
  10478. //json_object_put(obj); --- remove temporally
  10479. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  10480. return result;
  10481. }
  10482. static char UpdateFirmwarepayloadData[300]={0};
  10483. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  10484. {
  10485. mtrace();
  10486. int result = FAIL;
  10487. pthread_t t;
  10488. sendUpdateFirmwareConfirmation(uuid);
  10489. memset(UpdateFirmwarepayloadData, 0, 300);
  10490. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  10491. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  10492. ////pthread_join(t, NULL); //
  10493. //pthread_detach(t);
  10494. //sendUpdateFirmwareConfirmation(uuid);
  10495. ShmOCPP16DataPH->MsMsg.bits.UpdateFirmwareConf =1;
  10496. return result;
  10497. }
  10498. void *UpdateFirmwareProcess(void *data)
  10499. {
  10500. pthread_detach(pthread_self());
  10501. mtrace();
  10502. int retriesInt =0, retryIntervalInt=0;
  10503. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  10504. int port=0;
  10505. char locationstr[512]={0}, retrieveDatestr[36]={0};
  10506. int isSuccess = 0;
  10507. char ftpbuf[512];
  10508. char temp[100];
  10509. char * pch;
  10510. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  10511. json_object *UpdateFirmware;
  10512. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  10513. if(!is_error(UpdateFirmware))
  10514. {
  10515. // Required data
  10516. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  10517. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  10518. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  10519. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  10520. // Optional data
  10521. if(json_object_object_get(UpdateFirmware, "retries"))
  10522. {
  10523. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  10524. }
  10525. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  10526. {
  10527. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  10528. }
  10529. }
  10530. json_object_put(UpdateFirmware);
  10531. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10532. memset(path, 0, ARRAY_SIZE(path));
  10533. // Wait retrieveData
  10534. if(strlen(retrieveDatestr) > 10)
  10535. {
  10536. do
  10537. {
  10538. sleep(1);
  10539. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  10540. }
  10541. // Ready to download
  10542. system("rm -f /mnt/*");
  10543. if(strncmp(locationstr,"http", 4) == 0)
  10544. {
  10545. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10546. sprintf(ftppath,"/%s", path);
  10547. DEBUG_INFO("locationstr: %s\n", locationstr);
  10548. DEBUG_INFO("protocol: %s\n",protocol);
  10549. DEBUG_INFO("host: %s\n",host);
  10550. DEBUG_INFO("path: %s\n",path);
  10551. DEBUG_INFO("ftppath: %s\n",ftppath);
  10552. int ftppathlen=strlen(ftppath);
  10553. int i=1;
  10554. char filenametemp[50];
  10555. while(i < ftppathlen)
  10556. {
  10557. int len=ftppathlen-i;
  10558. if(ftppath[len]== 47) // '/' ascll code: 47
  10559. {
  10560. DEBUG_INFO("compare '/' all right\n");
  10561. break;
  10562. }
  10563. i=i+1;
  10564. }
  10565. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10566. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10567. filenametemp[i+1] = 0;
  10568. do
  10569. {
  10570. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10571. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10572. sleep(1);
  10573. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  10574. if(!isSuccess)
  10575. {
  10576. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10577. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10578. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10579. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10580. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10581. }
  10582. else
  10583. {
  10584. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10585. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10586. }
  10587. retriesInt--;
  10588. }while((isSuccess == 0)&&(retriesInt >= 0));
  10589. }
  10590. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  10591. {
  10592. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10593. memset(temp, 0, ARRAY_SIZE(temp));
  10594. //DEBUG_INFO("locationstr=%s\n",locationstr);
  10595. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  10596. int ftppathlen=strlen(ftpbuf);
  10597. int i=1;
  10598. char filenametemp[50];
  10599. while(i < ftppathlen)
  10600. {
  10601. int len=ftppathlen-i;
  10602. if(ftpbuf[len]== 47) // '/' ascll code: 47
  10603. {
  10604. DEBUG_INFO(" compare '/' all right\n");
  10605. break;
  10606. }
  10607. i=i+1;
  10608. }
  10609. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10610. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  10611. filenametemp[i+1] = 0;
  10612. strncpy(temp, ftpbuf, ftppathlen-i+1);
  10613. pch=strchr(temp,'@');
  10614. if(pch==NULL)
  10615. {
  10616. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10617. protocol, host, &port, path);
  10618. strcpy(user,"anonymous");
  10619. strcpy(password,"");
  10620. }
  10621. else
  10622. {
  10623. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10624. protocol, user, password, host, &port, path);
  10625. }
  10626. sscanf(host,"%[^/]%s",host1, path1);
  10627. sprintf(ftppath,"%s", path1);
  10628. //DEBUG_INFO("protocol =%s\n",protocol);
  10629. //DEBUG_INFO("user =%s\n",user);
  10630. //DEBUG_INFO("password =%s\n",password);
  10631. //DEBUG_INFO("host1 =%s\n",host1);
  10632. //DEBUG_INFO("port =%d\n",port);
  10633. //DEBUG_INFO("path1 =%s\n",path1);
  10634. //DEBUG_INFO("ftppath=%s\n",ftppath);
  10635. //ftpFile(host, user, password, port, ftppath, fname);
  10636. //download firmware pthred
  10637. if(port == 0)
  10638. {
  10639. port = 21;
  10640. }
  10641. do
  10642. {
  10643. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloading]);
  10644. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10645. sleep(1);
  10646. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  10647. if(!isSuccess)
  10648. {
  10649. //BulldogUtil.sleepMs(interval*1000);
  10650. DEBUG_INFO("Update firmware request and download file fail.\n");
  10651. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10652. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10653. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  10654. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10655. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10656. }
  10657. else
  10658. {
  10659. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Downloaded]);
  10660. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10661. }
  10662. retriesInt--;
  10663. }while((!isSuccess)&&(retriesInt >= 0));
  10664. }
  10665. else
  10666. {
  10667. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  10668. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10669. sleep(1);
  10670. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s",FirmwareStatusStr[FirmwareStatus_Idle]);
  10671. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10672. }
  10673. // OCPPPH only, must announce CSU upgrade firmware
  10674. if(strstr((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, FirmwareStatusStr[FirmwareStatus_Downloaded]) != NULL)ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 1;
  10675. pthread_exit(NULL);
  10676. }
  10677. int handleCertificateSignedRequest(char *uuid, char *payload)
  10678. {
  10679. mtrace();
  10680. int result = PASS;
  10681. json_object *CertificateSigned;
  10682. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10683. CertificateSigned = json_tokener_parse(payload);
  10684. if(!is_error(CertificateSigned))
  10685. {
  10686. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(CertificateSigned, "certificateChain"), 0)));
  10687. }
  10688. json_object_put(CertificateSigned);
  10689. FILE *fp = fopen("/Storage/OCPP_PH/certCP.crt", "w");
  10690. fprintf(fp, "%s", ShmOCPP16DataPH->CertificateSigned.certificateChain);
  10691. fclose(fp);
  10692. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10693. ShmOCPP16DataPH->MsMsg.bits.CertificateSignedReq = 1;
  10694. sprintf((char*)ShmOCPP16DataPH->CertificateSigned.Response_status, "Accepted");
  10695. sendCertificateSignedConfirmation(uuid);
  10696. return result;
  10697. }
  10698. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10699. {
  10700. mtrace();
  10701. int result = PASS;
  10702. json_object *DeleteCertificate;
  10703. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10704. DeleteCertificate = json_tokener_parse(payload);
  10705. if(!is_error(DeleteCertificate))
  10706. {
  10707. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10708. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10709. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10710. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10711. }
  10712. json_object_put(DeleteCertificate);
  10713. /*
  10714. * TODO: Delete certificateSigned process
  10715. */
  10716. ShmOCPP16DataPH->MsMsg.bits.DeleteCertificateReq = 1;
  10717. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.hashAlgorithm);
  10718. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerNameHash);
  10719. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.issuerKeyHash);
  10720. DEBUG_INFO("serialNumber: %s\n", ShmOCPP16DataPH->DeleteCertificate.certificateHashData.serialNumber);
  10721. sprintf((char*)ShmOCPP16DataPH->DeleteCertificate.Response_status, "NotFound");
  10722. sendDeleteCertificateConfirmation(uuid);
  10723. return result;
  10724. }
  10725. int handleExtendedTriggerMessageRequest(char *uuid, char *payload)
  10726. {
  10727. mtrace();
  10728. int result = PASS;
  10729. json_object *ExtendedTriggerMessage;
  10730. DEBUG_INFO("handleExtendedTriggerMessageRequest...\n");
  10731. ExtendedTriggerMessage = json_tokener_parse(payload);
  10732. if(!is_error(ExtendedTriggerMessage))
  10733. {
  10734. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(ExtendedTriggerMessage, "requestedMessage")));
  10735. if(json_object_object_get(ExtendedTriggerMessage, "connectorId") != NULL)
  10736. {
  10737. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = json_object_get_int(json_object_object_get(ExtendedTriggerMessage, "connectorId"));
  10738. }
  10739. else
  10740. {
  10741. ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId = -1;
  10742. }
  10743. }
  10744. json_object_put(ExtendedTriggerMessage);
  10745. DEBUG_INFO("requestedMessage: %s\n", ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage);
  10746. DEBUG_INFO("connectorIdInt: %d\n", ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId);
  10747. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId == 0) || (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > gunTotalNumber))
  10748. {
  10749. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, TriggerMessageStatusStr[TriggerMessageStatus_Rejected]);
  10750. }
  10751. else
  10752. {
  10753. if((strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) != 0 ) &&
  10754. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") != 0) &&
  10755. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  10756. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) != 0) &&
  10757. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) != 0) &&
  10758. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") != 0 ) &&
  10759. (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) != 0 ))
  10760. {
  10761. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  10762. }
  10763. else
  10764. {
  10765. sprintf((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.Response_status, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  10766. }
  10767. }
  10768. sendExtendedTriggerMessageConfirmation(uuid);
  10769. //==========================
  10770. // Trigger message
  10771. //==========================
  10772. if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[BootNotification]) == 0 )
  10773. {
  10774. //sendBootNotificationRequest();
  10775. server_sign = FALSE;
  10776. }
  10777. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "LogStatusNotification") == 0)
  10778. {
  10779. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationReq = 1;
  10780. }
  10781. else if( strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  10782. {
  10783. if((strlen((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status) == 0) ||
  10784. ((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) && (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING)))
  10785. {
  10786. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  10787. sprintf((char*)ShmOCPP16DataPH->FirmwareStatusNotification.Status, "%s", FirmwareStatusStr[FirmwareStatus_Idle]);
  10788. }
  10789. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 1;
  10790. }
  10791. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[Heartbeat]) == 0 )
  10792. {
  10793. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval);
  10794. }
  10795. else if (strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[MeterValues]) == 0 )
  10796. {
  10797. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10798. {
  10799. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId-1].TriggerMeterValue = 1;
  10800. }
  10801. else
  10802. {
  10803. for(int idx=0;idx< gunTotalNumber;idx++)
  10804. {
  10805. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  10806. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  10807. }
  10808. }
  10809. }
  10810. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, "SignChargePointCertificate") == 0 )
  10811. {
  10812. ShmOCPP16DataPH->SpMsg.bits.SignCertificateReq = 1;
  10813. if(access("/Storage/OCPP_PH/certCP.csr",F_OK) == -1)
  10814. {
  10815. 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\" &");
  10816. }
  10817. }
  10818. else if(strcmp((char*)ShmOCPP16DataPH->ExtendedTriggerMessage.requestedMessage, MessageTriggerStr[StatusNotification]) == 0 )
  10819. {
  10820. if((ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId > 0) && (ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId <= gunTotalNumber))
  10821. {
  10822. cpinitateMsg.bits[ShmOCPP16DataPH->ExtendedTriggerMessage.connectorId -1].StatusNotificationReq = 1;
  10823. }
  10824. else
  10825. {
  10826. for(int idx=0;idx< gunTotalNumber;idx++)
  10827. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  10828. }
  10829. }
  10830. return result;
  10831. }
  10832. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10833. {
  10834. mtrace();
  10835. int result = PASS;
  10836. json_object *GetInstalledCertificateIds;
  10837. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10838. GetInstalledCertificateIds = json_tokener_parse(payload);
  10839. if(!is_error(GetInstalledCertificateIds))
  10840. {
  10841. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType, "%s", json_object_get_string(json_object_object_get(GetInstalledCertificateIds, "certificateType")));
  10842. }
  10843. json_object_put(GetInstalledCertificateIds);
  10844. /*
  10845. * TODO: Return installed certificate process
  10846. */
  10847. ShmOCPP16DataPH->MsMsg.bits.GetInstalledCertificateIdsReq = 1;
  10848. DEBUG_INFO("requestedMessage: %s\n", (char*)ShmOCPP16DataPH->GetInstalledCertificateIds.certificateType);
  10849. memset(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData, 0x00, ARRAY_SIZE(ShmOCPP16DataPH->GetInstalledCertificateIds.Response_certificateHashData)*sizeof(struct CertificateHashDataType));
  10850. sprintf((char*)ShmOCPP16DataPH->GetInstalledCertificateIds.Response_status, "NotFound");
  10851. sendGetInstalledCertificateIdsConfirmation(uuid);
  10852. return result;
  10853. }
  10854. int handleGetLogRequest(char *uuid, char *payload)
  10855. {
  10856. mtrace();
  10857. int result = PASS;
  10858. json_object *GetLog;
  10859. DEBUG_INFO("handleGetLogRequest...\n");
  10860. GetLog = json_tokener_parse(payload);
  10861. if(!is_error(GetLog))
  10862. {
  10863. sprintf((char*)ShmOCPP16DataPH->GetLog.logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10864. ShmOCPP16DataPH->GetLog.requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10865. if(json_object_object_get(GetLog, "retries") != NULL)
  10866. {
  10867. ShmOCPP16DataPH->GetLog.retries = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10868. }
  10869. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10870. {
  10871. ShmOCPP16DataPH->GetLog.retryInterval = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10872. }
  10873. sprintf((char*)ShmOCPP16DataPH->GetLog.log.remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10874. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10875. {
  10876. sprintf((char*)ShmOCPP16DataPH->GetLog.log.oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10877. }
  10878. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10879. {
  10880. sprintf((char*)ShmOCPP16DataPH->GetLog.log.latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10881. }
  10882. }
  10883. json_object_put(GetLog);
  10884. /*
  10885. * TODO: Upload log process
  10886. */
  10887. ShmOCPP16DataPH->MsMsg.bits.GetLogReq = 1;
  10888. DEBUG_INFO("logType: %s\n", ShmOCPP16DataPH->GetLog.logType);
  10889. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->GetLog.requestId);
  10890. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->GetLog.retries);
  10891. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->GetLog.retryInterval);
  10892. DEBUG_INFO("remoteLocation: %s\n", ShmOCPP16DataPH->GetLog.log.remoteLocation);
  10893. DEBUG_INFO("oldestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.oldestTimestamp);
  10894. DEBUG_INFO("latestTimestamp: %s\n", ShmOCPP16DataPH->GetLog.log.latestTimestamp);
  10895. sprintf((char*)ShmOCPP16DataPH->GetLog.Response_status, "Rejected");
  10896. sendGetLogConfirmation(uuid);
  10897. return result;
  10898. }
  10899. int handleInstallCertificateRequest(char *uuid, char *payload)
  10900. {
  10901. mtrace();
  10902. int result = PASS;
  10903. json_object *InstallCertificate;
  10904. DEBUG_INFO("handleInstallCertificateRequest...\n");
  10905. InstallCertificate = json_tokener_parse(payload);
  10906. if(!is_error(InstallCertificate))
  10907. {
  10908. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  10909. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  10910. /*
  10911. * TODO: Install certificate process
  10912. */
  10913. ShmOCPP16DataPH->MsMsg.bits.InstallCertificateReq = 1;
  10914. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificateType);
  10915. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP16DataPH->InstallCertificate.certificate);
  10916. sprintf((char*)ShmOCPP16DataPH->InstallCertificate.Response_status, "Rejected");
  10917. sendInstallCertificateConfirmation(uuid);
  10918. }
  10919. json_object_put(InstallCertificate);
  10920. return result;
  10921. }
  10922. int handleSignedUpdateFirmwareRequest(char *uuid, char *payload)
  10923. {
  10924. mtrace();
  10925. int result = PASS;
  10926. json_object *SignedUpdateFirmware;
  10927. DEBUG_INFO("handleSignedUpdateFirmwareRequest...\n");
  10928. SignedUpdateFirmware = json_tokener_parse(payload);
  10929. if(!is_error(SignedUpdateFirmware))
  10930. {
  10931. if(json_object_object_get(SignedUpdateFirmware, "retries") != NULL)
  10932. {
  10933. ShmOCPP16DataPH->SignedUpdateFirmware.retries = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retries"));
  10934. }
  10935. if(json_object_object_get(SignedUpdateFirmware, "retryInterval") != NULL)
  10936. {
  10937. ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "retryInterval"));
  10938. }
  10939. ShmOCPP16DataPH->SignedUpdateFirmware.requestId = json_object_get_int(json_object_object_get(SignedUpdateFirmware, "requestId"));
  10940. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "location")));
  10941. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "retrieveDateTime")));
  10942. if(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime") != NULL)
  10943. {
  10944. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "installDateTime")));
  10945. }
  10946. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signingCertificate")));
  10947. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SignedUpdateFirmware, "firmware"), "signature")));
  10948. }
  10949. json_object_put(SignedUpdateFirmware);
  10950. /*
  10951. * TODO: Upgrade firmware process
  10952. */
  10953. ShmOCPP16DataPH->MsMsg.bits.SignedUpdateFirmwareReq = 1;
  10954. DEBUG_INFO("retries: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retries);
  10955. DEBUG_INFO("retryInterval: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.retryInterval);
  10956. DEBUG_INFO("requestId: %d\n", ShmOCPP16DataPH->SignedUpdateFirmware.requestId);
  10957. DEBUG_INFO("location: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.location);
  10958. DEBUG_INFO("retrieveDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.retrieveDateTime);
  10959. DEBUG_INFO("installDateTime: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.installDateTime);
  10960. DEBUG_INFO("signingCertificate: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signingCertificate);
  10961. DEBUG_INFO("signature: %s\n", ShmOCPP16DataPH->SignedUpdateFirmware.firmware.signature);
  10962. sprintf((char*)ShmOCPP16DataPH->SignedUpdateFirmware.Response_status, "Rejected");
  10963. sendInstallCertificateConfirmation(uuid);
  10964. return result;
  10965. }
  10966. int handleUnknownRequest(char *uuid, char *payload)
  10967. {
  10968. mtrace();
  10969. int result = PASS;
  10970. DEBUG_INFO("handleUnknownRequest...\n");
  10971. sendUnknownConfirmation(uuid);
  10972. result = PASS;
  10973. return result;
  10974. }
  10975. //==========================================
  10976. // Handle server response routine
  10977. //==========================================
  10978. void handleAuthorizeResponse(char *payload, int gun_index)
  10979. {
  10980. mtrace();
  10981. char expiryDatestr[30]={0};
  10982. char parentIdTagstr[20]={0};
  10983. char statusstr[20]={0};
  10984. int expiryDateISNULL=FALSE;
  10985. int parentIdTagISNULL=FALSE;
  10986. DEBUG_INFO("handleAuthorizeResponse...\n");
  10987. json_object *Authorize;
  10988. Authorize = json_tokener_parse(payload);
  10989. if(!is_error(Authorize))
  10990. {
  10991. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  10992. {
  10993. // Required data
  10994. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  10995. // Optional data
  10996. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  10997. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  10998. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  10999. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  11000. }
  11001. }
  11002. json_object_put(Authorize);
  11003. if(expiryDateISNULL == FALSE)
  11004. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  11005. if(parentIdTagISNULL == FALSE)
  11006. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  11007. strcpy((char *)ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.Status, statusstr);
  11008. //Update idTag information to authorization cache if supproted
  11009. if((strcmp((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16DataPH->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  11010. {
  11011. OCPP_addLocalCache((char*)ShmOCPP16DataPH->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  11012. }
  11013. ShmOCPP16DataPH->SpMsg.bits.AuthorizeReq = 0;
  11014. ShmOCPP16DataPH->SpMsg.bits.AuthorizeConf = 1; // inform csu
  11015. authorizeRetryTimes = 0;
  11016. }
  11017. void handleBootNotificationResponse(char *payload, int gun_index)
  11018. {
  11019. mtrace();
  11020. char statusStr[12]={0};
  11021. char currentTimeStr[30]={0};
  11022. int intervalInt = 0;
  11023. DEBUG_INFO("handleBootNotificationResponse...\n");
  11024. json_object *BootNotification;
  11025. BootNotification = json_tokener_parse(payload);
  11026. if(!is_error(BootNotification))
  11027. {
  11028. // Required data
  11029. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  11030. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  11031. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  11032. }
  11033. json_object_put(BootNotification);
  11034. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11035. BootNotificationInterval = intervalInt;
  11036. HeartBeatWaitTime = intervalInt;
  11037. //write back to ShmOCPP16DataPH->BootNotification
  11038. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseCurrentTime, currentTimeStr);
  11039. ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval = intervalInt;
  11040. strcpy((char *)ShmOCPP16DataPH->BootNotification.ResponseStatus, statusStr);
  11041. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  11042. {
  11043. server_sign = TRUE;
  11044. server_pending =FALSE;
  11045. }
  11046. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  11047. {
  11048. server_pending = TRUE;
  11049. }
  11050. syncDateTimeRTC(ShmOCPP16DataPH->BootNotification.ResponseCurrentTime);
  11051. srand(time(NULL));
  11052. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16DataPH->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  11053. SetOcppConnStatus(TRUE);
  11054. ShmOCPP16DataPH->SpMsg.bits.BootNotificationConf = 1;
  11055. }
  11056. void handleDataTransferResponse(char *payload, int gun_index)
  11057. {
  11058. char sstr[160]={0};//sstr[200]={ 0 };
  11059. int c = 0;
  11060. char *loc;
  11061. DEBUG_INFO("handleDataTransferResponse ...\n");
  11062. loc = strstr(payload, "status");
  11063. c = 0;
  11064. while (loc[3+strlen("status")+c] != '\"')
  11065. {
  11066. sstr[c] = loc[3+strlen("status")+c];
  11067. c++;
  11068. }
  11069. sstr[c] = '\0';
  11070. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  11071. }
  11072. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  11073. {
  11074. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  11075. //struct json_object *obj;
  11076. // obj = json_tokener_parse(payload);
  11077. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  11078. ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  11079. //No fields are defined.
  11080. }
  11081. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11082. {
  11083. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  11084. //struct json_object *obj;
  11085. // obj = json_tokener_parse(payload);
  11086. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  11087. ShmOCPP16DataPH->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  11088. //No fields are defined.
  11089. }
  11090. void handleHeartbeatResponse(char *payload, int gun_index)
  11091. {
  11092. mtrace();
  11093. DEBUG_INFO("handleHeartbeatResponse...\n");
  11094. json_object *Heartbeat;
  11095. Heartbeat = json_tokener_parse(payload);
  11096. if(!is_error(Heartbeat))
  11097. {
  11098. // Required data
  11099. sprintf((char *)ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  11100. }
  11101. json_object_put(Heartbeat);
  11102. if(FirstHeartBeat == 0)
  11103. {
  11104. FirstHeartBeat = 1;
  11105. DEBUG_INFO("FirstHeartBeat \n");
  11106. }
  11107. HeartBeatWithNOResponse = 0;
  11108. clientTime.Heartbeat=time((time_t*)NULL);
  11109. syncDateTimeRTC(ShmOCPP16DataPH->Heartbeat.ResponseCurrentTime);
  11110. }
  11111. void handleMeterValuesResponse(char *payload, int gun_index)
  11112. {
  11113. mtrace();
  11114. DEBUG_INFO("handleMeterValuesResponse...\n");
  11115. }
  11116. void handleStartTransactionResponse(char *payload, int gun_index)
  11117. {
  11118. mtrace();
  11119. //int transactionIdInt = 0;
  11120. FILE *outfile;
  11121. char data[100]={0};
  11122. DEBUG_INFO("handleStartTransactionResponse...\n");
  11123. json_object *StartTransaction;
  11124. StartTransaction = json_tokener_parse(payload);
  11125. if(!is_error(StartTransaction))
  11126. {
  11127. // Required data
  11128. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  11129. ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  11130. // Optional data
  11131. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  11132. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  11133. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11134. sprintf((char *)ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  11135. }
  11136. json_object_put(StartTransaction);
  11137. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionConf = 1;
  11138. ShmOCPP16DataPH->CpMsg.bits[gun_index].StartTransactionReq = 0;
  11139. //-----------Start : write to the Queue TransactionId file -----------------//
  11140. if((access("/Storage/OCPP_PH/QueueTransactionId",F_OK))!=-1)
  11141. {}
  11142. else
  11143. {
  11144. FILE *log = fopen("/Storage/OCPP_PH/QueueTransactionId", "w+");
  11145. if(log == NULL)
  11146. {
  11147. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  11148. return ;
  11149. }
  11150. else
  11151. {
  11152. fclose(log);
  11153. }
  11154. }
  11155. // open file for writing
  11156. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  11157. if((ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId !=0))
  11158. {
  11159. outfile = fopen ("/Storage/OCPP_PH/QueueTransactionId", "a");
  11160. sprintf(data,"%d,%s,%d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ConnectorId , ShmOCPP16DataPH->StartTransaction[gun_index].IdTag, ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  11161. fputs(data, outfile);
  11162. fclose (outfile);
  11163. }
  11164. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11165. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11166. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  11167. DEBUG_INFO("transactionId: %d\n", ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId);
  11168. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11169. }
  11170. void handleStatusNotificationResponse(char *payload, int gun_index)
  11171. {
  11172. mtrace();
  11173. DEBUG_INFO("handleStatusNotificationResponse...\n");
  11174. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  11175. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  11176. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  11177. }
  11178. void handleStopTransactionnResponse(char *payload, int gun_index)
  11179. {
  11180. mtrace();
  11181. DEBUG_INFO("handleStopTransactionnResponse...\n");
  11182. json_object *StopTransaction;
  11183. StopTransaction = json_tokener_parse(payload);
  11184. if(!is_error(StopTransaction))
  11185. {
  11186. // Optional data
  11187. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  11188. {
  11189. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  11190. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  11191. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  11192. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  11193. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  11194. }
  11195. }
  11196. json_object_put(StopTransaction);
  11197. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionConf = 1;
  11198. ShmOCPP16DataPH->CpMsg.bits[gun_index].StopTransactionReq = 0;
  11199. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  11200. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  11201. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16DataPH->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  11202. }
  11203. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  11204. {
  11205. mtrace();
  11206. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  11207. ShmOCPP16DataPH->SpMsg.bits.LogStatusNotificationConf = 1;
  11208. }
  11209. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  11210. {
  11211. mtrace();
  11212. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  11213. ShmOCPP16DataPH->SpMsg.bits.SecurityEventNotificationConf = 1;
  11214. }
  11215. void handleSignCertificateResponse(char *payload, int gun_index)
  11216. {
  11217. mtrace();
  11218. DEBUG_INFO("handleSignCertificateResponse...\n");
  11219. json_object *SignCertificate;
  11220. SignCertificate = json_tokener_parse(payload);
  11221. if(!is_error(SignCertificate))
  11222. {
  11223. sprintf((char*)ShmOCPP16DataPH->SignCertificate.Response_status, "%s", json_object_get_string(json_object_object_get(SignCertificate, "status")));
  11224. DEBUG_INFO("status: %s\n", ShmOCPP16DataPH->SignCertificate.Response_status);
  11225. }
  11226. json_object_put(SignCertificate);
  11227. ShmOCPP16DataPH->SpMsg.bits.SignCertificateConf = 1;
  11228. }
  11229. void handleSignedFirmwareStatusNotificationResponse(char *payload, int gun_index)
  11230. {
  11231. mtrace();
  11232. DEBUG_INFO("handleSignedFirmwareStatusNotificationResponse...\n");
  11233. ShmOCPP16DataPH->SpMsg.bits.SignedFirmwareStatusNotificationConf = 1;
  11234. }
  11235. //==========================================
  11236. // Handle Error routine
  11237. //==========================================
  11238. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  11239. {
  11240. mtrace();
  11241. #ifdef SystemLogMessage
  11242. DEBUG_INFO("errorCode: %s\n", errorCode);
  11243. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  11244. DEBUG_INFO("errorDetails: %s\n", payload);
  11245. #endif
  11246. }
  11247. //===============================================
  11248. // Common routine
  11249. //===============================================
  11250. int initialConfigurationTable(void)
  11251. {
  11252. //clock_t start_t, end_t, total_t;
  11253. FILE *fp;
  11254. FILE *outfile;
  11255. char str[512]={0};
  11256. char sstr[256]={0};
  11257. int c = 0;
  11258. char *loc;
  11259. int confVersion = 3;
  11260. DEBUG_INFO("initialConfigurationTable...version: %d\n", confVersion);
  11261. //start_t = clock();
  11262. //printf("Starting of the program, start_t = %ld\n", start_t);
  11263. memset(&(ShmOCPP16DataPH->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  11264. // Check configuration file size is correct
  11265. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))!=-1)
  11266. {
  11267. struct stat st;
  11268. stat("/Storage/OCPP_PH/OCPPConfiguration", &st);
  11269. if(st.st_size < 3100)
  11270. {
  11271. system("rm -f /Storage/OCPP_PH/OCPPConfiguration");
  11272. DEBUG_INFO("OCPPConfiguration file size: %d is smaller than 3100 bytes, restore to default value.\n", st.st_size);
  11273. }
  11274. }
  11275. if((access("/Storage/OCPP_PH/OCPPConfiguration",F_OK))==-1)
  11276. {
  11277. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11278. if(outfile == NULL)
  11279. {
  11280. DEBUG_INFO("Error opening file\n");
  11281. return FALSE;
  11282. }
  11283. /*Core Profile*/
  11284. //AllowOfflineTxForUnknownId
  11285. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11286. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11287. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  11288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11289. //AuthorizationCacheEnabled
  11290. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11291. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11292. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11294. //AuthorizeRemoteTxRequests
  11295. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11296. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11297. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  11298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11299. //BlinkRepeat
  11300. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11301. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11302. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11304. //ClockAlignedDataInterval
  11305. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11306. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11307. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11309. //ConnectionTimeOut
  11310. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11311. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11312. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11313. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11314. //GetConfigurationMaxKeys
  11315. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11316. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11317. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", _GetConfiguration_CNT);
  11318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11319. // HeartbeatInterval
  11320. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11321. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11322. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  11323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11324. // LightIntensity
  11325. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11326. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11327. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11329. // LocalAuthorizeOffline
  11330. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  11331. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11332. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11334. // LocalPreAuthorize
  11335. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 1;
  11336. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11337. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11338. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11339. // MaxEnergyOnInvalidId
  11340. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11341. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11342. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11344. // MeterValuesAlignedData
  11345. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11346. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11347. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11348. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11349. else
  11350. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11352. // MeterValuesAlignedDataMaxLength
  11353. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11354. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11356. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  11357. else
  11358. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "9" );
  11359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11360. // MeterValuesSampledData
  11361. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11362. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11363. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11364. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11365. else
  11366. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11367. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11368. // MeterValuesSampledDataMaxLength
  11369. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11370. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11371. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11372. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  11373. else
  11374. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "9" );
  11375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11376. // MeterValueSampleInterval
  11377. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11378. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11379. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  11380. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11381. // MinimumStatusDuration
  11382. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11383. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11384. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  11385. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  11386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11387. // NumberOfConnectors
  11388. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11389. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11390. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11391. {
  11392. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11393. }
  11394. else
  11395. {
  11396. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11397. }
  11398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11399. // ResetRetries
  11400. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11401. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11402. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11404. // ConnectorPhaseRotation
  11405. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11406. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11407. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11409. // ConnectorPhaseRotationMaxLength
  11410. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11411. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11412. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11413. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11414. // StopTransactionOnEVSideDisconnect
  11415. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11416. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11417. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11418. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11419. // StopTransactionOnInvalidId
  11420. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1; //1;
  11421. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11422. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11423. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11424. // StopTxnAlignedData
  11425. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  11426. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11427. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "" );
  11428. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11429. // StopTxnAlignedDataMaxLength
  11430. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11431. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11432. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11433. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11434. // StopTxnSampledData
  11435. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11436. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11437. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11438. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  11439. else
  11440. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  11441. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11442. // StopTxnSampledDataMaxLength
  11443. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11444. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11446. {
  11447. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 7);
  11448. }
  11449. else
  11450. {
  11451. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 9);
  11452. }
  11453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11454. // SupportedFeatureProfiles
  11455. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11456. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11457. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11459. // SupportedFeatureProfilesMaxLength
  11460. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11461. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11462. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11463. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11464. // TransactionMessageAttempts
  11465. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11466. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11467. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11468. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11469. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11470. // TransactionMessageRetryInterval
  11471. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11472. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11473. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11474. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11475. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11476. // UnlockConnectorOnEVSideDisconnect
  11477. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11478. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11479. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11481. // WebSocketPingInterval
  11482. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11483. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11484. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11486. // QueueOffLineStartTransactionMessage
  11487. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  11488. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  11489. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  11490. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  11491. // AuthorizationKey
  11492. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  11493. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  11494. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, (char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword );
  11495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  11496. // SecurityProfile
  11497. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  11498. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  11499. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11500. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  11501. // DefaultPrice
  11502. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  11503. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  11504. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  11505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  11506. // CustomDisplayCostAndPrice
  11507. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  11508. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  11509. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  11510. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  11511. // CustomIdleFeeAfterStop
  11512. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  11513. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  11514. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  11515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  11516. // Configuration Version
  11517. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 0;
  11518. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  11519. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", confVersion);
  11520. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "true", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  11521. //* Local Auth List Management Profile*/
  11522. #if 0
  11523. //For OCTT Test Case
  11524. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11525. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  11526. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11527. #endif
  11528. #if 1
  11529. //LocalAuthListEnabled
  11530. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11531. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11532. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11534. #endif
  11535. //LocalAuthListMaxLength
  11536. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11537. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11538. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11539. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11540. //SendLocalListMaxLength
  11541. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11542. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11543. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  11544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11545. //ReserveConnectorZeroSupported
  11546. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11547. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11548. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11550. //* Smart Charging Profile */
  11551. //ChargeProfileMaxStackLevel
  11552. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11553. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11554. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11556. // ChargingScheduleAllowedChargingRateUnit
  11557. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11558. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11559. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current,Power" );
  11560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11561. // ChargingScheduleMaxPeriods
  11562. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11563. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11564. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11566. // ConnectorSwitch3to1PhaseSupported
  11567. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11568. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11569. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "FALSE" );
  11570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11571. // MaxChargingProfilesInstalled
  11572. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11573. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11574. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11576. fclose(outfile);
  11577. }
  11578. else
  11579. {
  11580. //DEBUG_INFO("../Storage/OCPP_PH/OCPPConfiguration EXit\n");
  11581. char keystr[60]={0};
  11582. char readonlystr[10]={0};
  11583. char valuestr[256]={0};
  11584. fp = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "r");
  11585. if(fp == NULL) {
  11586. DEBUG_INFO("Error opening file");
  11587. return FALSE;
  11588. }
  11589. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  11590. {
  11591. //DEBUG_INFO("Get Configuration \n");
  11592. if(strlen(str) > 0)
  11593. {
  11594. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  11595. //*************************key*********************************/
  11596. if(strstr(str, "key") != NULL)
  11597. {
  11598. loc = strstr(str, "key");
  11599. c = 0;
  11600. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11601. while ((loc[strlen("key")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11602. {
  11603. sstr[c] = loc[strlen("key")+3+c];
  11604. c++;
  11605. }
  11606. sstr[c] = '\0';
  11607. strcpy(keystr,sstr);
  11608. }
  11609. //*************************readonly*********************************/
  11610. if(strstr(str, "readonly") != NULL)
  11611. {
  11612. loc = strstr(str, "readonly");
  11613. c = 0;
  11614. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11615. while ((loc[strlen("readonly")+2+c] != ',') && (c < (ARRAY_SIZE(sstr)-1)))
  11616. {
  11617. sstr[c] = loc[strlen("readonly")+2+c];
  11618. c++;
  11619. }
  11620. sstr[c] = '\0';
  11621. strcpy(readonlystr,sstr);
  11622. }
  11623. //*************************value*********************************/
  11624. if(strstr(str, "value") != NULL)
  11625. {
  11626. loc = strstr(str, "value");
  11627. c = 0;
  11628. memset(sstr ,0, ARRAY_SIZE(sstr) );
  11629. while ((loc[strlen("value")+3+c] != '\"') && (c < (ARRAY_SIZE(sstr)-1)))
  11630. {
  11631. sstr[c] = loc[strlen("value")+3+c];
  11632. c++;
  11633. }
  11634. sstr[c] = '\0';
  11635. strcpy(valuestr,sstr);
  11636. }
  11637. // DEBUG_INFO("keystr=%s\n",keystr);
  11638. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  11639. // DEBUG_INFO("valuestr=%s\n",valuestr);
  11640. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  11641. {
  11642. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11643. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11644. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  11645. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11646. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  11647. }
  11648. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  11649. {
  11650. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11651. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11652. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  11653. }
  11654. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  11655. {
  11656. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  11658. }
  11659. if(strcmp(keystr, "BlinkRepeat") == 0)
  11660. {
  11661. //Charger.BlinkRepeat = Integer.parseInt(value);
  11662. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11663. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  11664. }
  11665. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  11666. {
  11667. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11668. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  11669. }
  11670. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  11671. {
  11672. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11673. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  11674. }
  11675. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  11676. {
  11677. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11678. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  11679. }
  11680. if(strcmp(keystr, "HeartbeatInterval") == 0)
  11681. {
  11682. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11683. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  11684. HeartBeatWaitTime = atoi(valuestr);
  11685. }
  11686. if(strcmp(keystr, "LightIntensity") == 0)
  11687. {
  11688. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  11690. }
  11691. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  11692. {
  11693. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11694. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  11695. }
  11696. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  11697. {
  11698. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11699. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  11700. }
  11701. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  11702. {
  11703. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11704. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  11705. }
  11706. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  11707. {
  11708. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11709. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11710. }
  11711. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11712. {
  11713. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11714. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11715. }
  11716. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11717. {
  11718. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11719. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11720. }
  11721. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11722. {
  11723. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11724. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11725. }
  11726. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11727. {
  11728. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11729. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11730. }
  11731. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11732. {
  11733. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11734. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11735. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11736. }
  11737. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11738. {
  11739. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11740. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11741. }
  11742. if(strcmp(keystr, "ResetRetries") == 0)
  11743. {
  11744. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11745. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11746. }
  11747. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11748. {
  11749. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11750. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11751. }
  11752. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11753. {
  11754. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11755. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11756. }
  11757. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11758. {
  11759. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11760. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11761. }
  11762. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11763. {
  11764. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11765. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11766. }
  11767. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11768. {
  11769. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11770. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11771. }
  11772. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11773. {
  11774. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11775. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11776. }
  11777. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11778. {
  11779. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11780. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11781. }
  11782. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11783. {
  11784. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11785. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11786. }
  11787. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11788. {
  11789. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11790. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11791. }
  11792. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11793. {
  11794. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11795. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11796. }
  11797. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11798. {
  11799. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11800. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11801. TransactionMessageAttemptsValue = atoi(valuestr);
  11802. }
  11803. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11804. {
  11805. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11806. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11807. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11808. }
  11809. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11810. {
  11811. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11812. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11813. }
  11814. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11815. {
  11816. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11817. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11818. }
  11819. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  11820. {
  11821. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11822. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  11823. }
  11824. if(strcmp(keystr, "AuthorizationKey") == 0)
  11825. {
  11826. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11827. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  11828. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  11829. }
  11830. if(strcmp(keystr, "SecurityProfile") == 0)
  11831. {
  11832. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11833. //sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  11834. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile );
  11835. }
  11836. if(strcmp(keystr, "DefaultPrice") == 0)
  11837. {
  11838. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11839. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  11840. }
  11841. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  11842. {
  11843. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11844. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  11845. }
  11846. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  11847. {
  11848. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11849. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  11850. }
  11851. if(strcmp(keystr, "ConfigurationVersion") == 0)
  11852. {
  11853. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11854. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "%d", atoi(valuestr));
  11855. }
  11856. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11857. {
  11858. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11859. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11860. }
  11861. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11862. {
  11863. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11864. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11865. }
  11866. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11867. {
  11868. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11869. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11870. }
  11871. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11872. {
  11873. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11874. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11875. }
  11876. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11877. {
  11878. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11879. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11880. }
  11881. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11882. {
  11883. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11884. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11885. }
  11886. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11887. {
  11888. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11889. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11890. }
  11891. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11892. {
  11893. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11894. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11895. }
  11896. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11897. {
  11898. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11899. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11900. }
  11901. }
  11902. }
  11903. fclose(fp);
  11904. }
  11905. if(atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData) == confVersion)
  11906. {
  11907. return PASS;
  11908. }
  11909. else
  11910. {
  11911. return FAIL;
  11912. }
  11913. }
  11914. void StoreConfigurationTable(void)
  11915. {
  11916. FILE *outfile;
  11917. outfile = fopen("/Storage/OCPP_PH/OCPPConfiguration" , "w+");
  11918. if(outfile == NULL)
  11919. {
  11920. DEBUG_INFO("Error opening file");
  11921. return ;
  11922. }
  11923. /*Core Profile*/
  11924. //AllowOfflineTxForUnknownId
  11925. /*
  11926. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11927. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11928. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11929. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11930. */
  11931. //DEBUG_INFO("data=%s\n",data);
  11932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11933. //AuthorizationCacheEnabled
  11934. /*
  11935. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11936. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11937. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11938. */
  11939. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11940. //AuthorizeRemoteTxRequests
  11941. /*
  11942. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11943. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11944. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11945. */
  11946. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11947. //BlinkRepeat
  11948. /*
  11949. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11950. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11951. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11952. */
  11953. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11954. //ClockAlignedDataInterval
  11955. /*
  11956. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11957. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11958. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11959. */
  11960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11961. //ConnectionTimeOut
  11962. /*
  11963. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11964. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11965. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11966. */
  11967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11968. //GetConfigurationMaxKeys
  11969. /*
  11970. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11971. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11972. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11973. */
  11974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11975. // HeartbeatInterval
  11976. /*
  11977. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11978. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11979. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11980. */
  11981. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11982. // LightIntensity
  11983. /*
  11984. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11985. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11986. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11987. */
  11988. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11989. // LocalAuthorizeOffline
  11990. /*
  11991. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11992. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11993. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11994. */
  11995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11996. // LocalPreAuthorize
  11997. /*
  11998. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11999. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  12000. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  12001. */
  12002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  12003. // MaxEnergyOnInvalidId
  12004. /*
  12005. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  12006. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  12007. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  12008. */
  12009. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  12010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  12011. // MeterValuesAlignedData
  12012. /*
  12013. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  12014. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  12015. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12016. */
  12017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  12018. // MeterValuesAlignedDataMaxLength
  12019. /*
  12020. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  12021. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  12022. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  12023. */
  12024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  12025. // MeterValuesSampledData
  12026. /*
  12027. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  12028. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  12029. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  12030. */
  12031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  12032. // MeterValuesSampledDataMaxLength
  12033. /*
  12034. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  12035. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  12036. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  12037. */
  12038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  12039. // MeterValueSampleInterval
  12040. /*
  12041. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  12042. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  12043. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  12044. */
  12045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  12046. // MinimumStatusDuration
  12047. /*
  12048. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  12049. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  12050. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  12051. */
  12052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  12053. // NumberOfConnectors
  12054. /*
  12055. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  12056. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  12057. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12058. {
  12059. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  12060. }
  12061. else
  12062. {
  12063. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  12064. }
  12065. */
  12066. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  12067. // ResetRetries
  12068. /*
  12069. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  12070. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  12071. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  12072. */
  12073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  12074. // ConnectorPhaseRotation
  12075. /*
  12076. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  12077. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  12078. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  12079. */
  12080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  12081. // ConnectorPhaseRotationMaxLength
  12082. /*
  12083. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  12084. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  12085. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  12086. */
  12087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  12088. // StopTransactionOnEVSideDisconnect
  12089. /*
  12090. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  12091. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  12092. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  12093. */
  12094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  12095. // StopTransactionOnInvalidId
  12096. /*
  12097. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  12098. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  12099. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  12100. */
  12101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  12102. // StopTxnAlignedData
  12103. /*
  12104. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  12105. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  12106. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  12107. */
  12108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  12109. // StopTxnAlignedDataMaxLength
  12110. /*
  12111. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  12112. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  12113. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  12114. */
  12115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  12116. // StopTxnSampledData
  12117. /*
  12118. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  12119. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  12120. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  12121. */
  12122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  12123. // StopTxnSampledDataMaxLength
  12124. /*
  12125. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  12126. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  12127. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  12128. */
  12129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  12130. // SupportedFeatureProfiles
  12131. /*
  12132. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  12133. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  12134. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  12135. */
  12136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  12137. // SupportedFeatureProfilesMaxLength
  12138. /*
  12139. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  12140. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  12141. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  12142. */
  12143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  12144. // TransactionMessageAttempts
  12145. /*
  12146. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  12147. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  12148. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  12149. */
  12150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  12151. // TransactionMessageRetryInterval
  12152. /*
  12153. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  12154. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  12155. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  12156. */
  12157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12158. // UnlockConnectorOnEVSideDisconnect
  12159. /*
  12160. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  12161. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  12162. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  12163. */
  12164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  12165. // WebSocketPingInterval
  12166. /*
  12167. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  12168. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  12169. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  12170. */
  12171. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  12172. // QueueOffLineStartTransactionMessage
  12173. /*
  12174. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  12175. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  12176. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  12177. */
  12178. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  12179. // AuthorizationKey
  12180. /*
  12181. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  12182. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  12183. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  12184. */
  12185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  12186. // SecurityProfile
  12187. /*
  12188. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  12189. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  12190. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  12191. */
  12192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  12193. // DefaultPrice
  12194. /*
  12195. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  12196. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  12197. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  12198. */
  12199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  12200. // CustomDisplayCostAndPrice
  12201. /*
  12202. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  12203. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  12204. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  12205. */
  12206. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  12207. // CustomIdleFeeAfterStop
  12208. /*
  12209. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  12210. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  12211. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  12212. */
  12213. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  12214. // ConfigurationVersion
  12215. /*
  12216. ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility = 1;
  12217. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemName, "ConfigurationVersion");
  12218. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData, "1" );
  12219. */
  12220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConfigurationVersion", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData);
  12221. //* Local Auth List Management Profile*/
  12222. //LocalAuthListEnabled
  12223. /*
  12224. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  12225. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  12226. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  12227. */
  12228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12229. //LocalAuthListMaxLength
  12230. /*
  12231. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  12232. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  12233. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  12234. */
  12235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  12236. //SendLocalListMaxLength
  12237. /*
  12238. ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  12239. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  12240. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  12241. */
  12242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  12243. //ReserveConnectorZeroSupported
  12244. /*
  12245. ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  12246. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  12247. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  12248. */
  12249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12250. //* Smart Charging Profile */
  12251. //ChargeProfileMaxStackLevel
  12252. /*
  12253. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  12254. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  12255. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  12256. */
  12257. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12258. // ChargingScheduleAllowedChargingRateUnit
  12259. /*
  12260. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  12261. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  12262. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  12263. */
  12264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12265. // ChargingScheduleMaxPeriods
  12266. /*
  12267. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  12268. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  12269. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  12270. */
  12271. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12272. // ConnectorSwitch3to1PhaseSupported
  12273. /*
  12274. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  12275. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  12276. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  12277. */
  12278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12279. // MaxChargingProfilesInstalled
  12280. /*
  12281. ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  12282. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  12283. strcpy((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  12284. */
  12285. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12286. fclose(outfile);
  12287. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12288. }
  12289. void getKeyValue(char *keyReq)
  12290. {
  12291. int isEmpty = FALSE;
  12292. int isKnowKey = FALSE;
  12293. DEBUG_INFO("keyReq = %s\n", keyReq);
  12294. if((keyReq == NULL) || (strlen(keyReq) == 0))
  12295. isEmpty = TRUE;
  12296. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  12297. {
  12298. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  12299. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  12300. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12301. {
  12302. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  12303. }
  12304. else
  12305. {
  12306. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  12307. }
  12308. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  12309. isKnowKey = TRUE;
  12310. }
  12311. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  12312. {
  12313. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  12314. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  12315. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12316. {
  12317. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  12318. }
  12319. else
  12320. {
  12321. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  12322. }
  12323. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  12324. isKnowKey = TRUE;
  12325. }
  12326. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  12327. {
  12328. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  12329. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  12330. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12331. {
  12332. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  12333. }
  12334. else
  12335. {
  12336. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  12337. }
  12338. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  12339. isKnowKey = TRUE;
  12340. }
  12341. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  12342. {
  12343. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  12344. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  12345. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12346. {
  12347. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  12348. }
  12349. else
  12350. {
  12351. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  12352. }
  12353. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  12354. isKnowKey = TRUE;
  12355. }
  12356. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  12357. {
  12358. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  12359. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  12360. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12361. {
  12362. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  12363. }
  12364. else
  12365. {
  12366. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  12367. }
  12368. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  12369. isKnowKey = TRUE;
  12370. }
  12371. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  12372. {
  12373. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  12374. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  12375. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12376. {
  12377. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  12378. }
  12379. else
  12380. {
  12381. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  12382. }
  12383. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  12384. isKnowKey = TRUE;
  12385. }
  12386. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  12387. {
  12388. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  12389. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  12390. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12391. {
  12392. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  12393. }
  12394. else
  12395. {
  12396. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  12397. }
  12398. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  12399. isKnowKey = TRUE;
  12400. }
  12401. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  12402. {
  12403. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  12404. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  12405. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12406. {
  12407. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  12408. }
  12409. else
  12410. {
  12411. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  12412. }
  12413. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  12414. isKnowKey = TRUE;
  12415. }
  12416. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  12417. {
  12418. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  12419. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  12420. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12421. {
  12422. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  12423. }
  12424. else
  12425. {
  12426. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  12427. }
  12428. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  12429. isKnowKey = TRUE;
  12430. }
  12431. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  12432. {
  12433. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  12434. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  12435. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12436. {
  12437. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  12438. }
  12439. else
  12440. {
  12441. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  12442. }
  12443. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  12444. isKnowKey = TRUE;
  12445. }
  12446. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  12447. {
  12448. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  12449. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  12450. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12451. {
  12452. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  12453. }
  12454. else
  12455. {
  12456. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  12457. }
  12458. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  12459. isKnowKey = TRUE;
  12460. }
  12461. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  12462. {
  12463. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  12464. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  12465. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12466. {
  12467. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12468. }
  12469. else
  12470. {
  12471. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12472. }
  12473. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  12474. isKnowKey = TRUE;
  12475. }
  12476. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  12477. {
  12478. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  12479. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  12480. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12481. {
  12482. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12483. }
  12484. else
  12485. {
  12486. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12487. }
  12488. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  12489. isKnowKey = TRUE;
  12490. }
  12491. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  12492. {
  12493. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  12494. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  12495. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12496. {
  12497. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12498. }
  12499. else
  12500. {
  12501. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12502. }
  12503. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  12504. isKnowKey = TRUE;
  12505. }
  12506. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  12507. {
  12508. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  12509. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  12510. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12511. {
  12512. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  12513. }
  12514. else
  12515. {
  12516. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  12517. }
  12518. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  12519. isKnowKey = TRUE;
  12520. }
  12521. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  12522. {
  12523. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  12524. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  12525. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12526. {
  12527. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12528. }
  12529. else
  12530. {
  12531. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12532. }
  12533. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  12534. isKnowKey = TRUE;
  12535. }
  12536. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  12537. {
  12538. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  12539. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  12540. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12541. {
  12542. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  12543. }
  12544. else
  12545. {
  12546. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  12547. }
  12548. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  12549. isKnowKey = TRUE;
  12550. }
  12551. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  12552. {
  12553. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  12554. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  12555. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12556. {
  12557. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  12558. }
  12559. else
  12560. {
  12561. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  12562. }
  12563. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[17].ItemData );
  12564. isKnowKey = TRUE;
  12565. }
  12566. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  12567. {
  12568. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  12569. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  12570. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12571. {
  12572. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  12573. }
  12574. else
  12575. {
  12576. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  12577. }
  12578. sprintf((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", gunTotalNumber);
  12579. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  12580. isKnowKey = TRUE;
  12581. }
  12582. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  12583. {
  12584. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  12585. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  12586. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12587. {
  12588. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  12589. }
  12590. else
  12591. {
  12592. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  12593. }
  12594. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  12595. isKnowKey = TRUE;
  12596. }
  12597. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  12598. {
  12599. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  12600. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  12601. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12602. {
  12603. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  12604. }
  12605. else
  12606. {
  12607. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  12608. }
  12609. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  12610. isKnowKey = TRUE;
  12611. }
  12612. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  12613. {
  12614. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  12615. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  12616. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12617. {
  12618. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12619. }
  12620. else
  12621. {
  12622. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12623. }
  12624. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  12625. isKnowKey = TRUE;
  12626. }
  12627. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  12628. {
  12629. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  12630. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  12631. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12632. {
  12633. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12634. }
  12635. else
  12636. {
  12637. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12638. }
  12639. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  12640. isKnowKey = TRUE;
  12641. }
  12642. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  12643. {
  12644. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  12645. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  12646. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12647. {
  12648. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  12649. }
  12650. else
  12651. {
  12652. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  12653. }
  12654. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  12655. isKnowKey = TRUE;
  12656. }
  12657. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  12658. {
  12659. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  12660. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  12661. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12662. {
  12663. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  12664. }
  12665. else
  12666. {
  12667. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  12668. }
  12669. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  12670. isKnowKey = TRUE;
  12671. }
  12672. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  12673. {
  12674. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  12675. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  12676. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12677. {
  12678. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12679. }
  12680. else
  12681. {
  12682. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12683. }
  12684. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  12685. isKnowKey = TRUE;
  12686. }
  12687. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  12688. {
  12689. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  12690. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  12691. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12692. {
  12693. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  12694. }
  12695. else
  12696. {
  12697. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  12698. }
  12699. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  12700. isKnowKey = TRUE;
  12701. }
  12702. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  12703. {
  12704. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  12705. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  12706. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12707. {
  12708. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12709. }
  12710. else
  12711. {
  12712. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12713. }
  12714. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  12715. isKnowKey = TRUE;
  12716. }
  12717. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  12718. {
  12719. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  12720. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  12721. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12722. {
  12723. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  12724. }
  12725. else
  12726. {
  12727. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  12728. }
  12729. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  12730. isKnowKey = TRUE;
  12731. }
  12732. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  12733. {
  12734. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  12735. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  12736. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12737. {
  12738. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12739. }
  12740. else
  12741. {
  12742. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12743. }
  12744. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  12745. isKnowKey = TRUE;
  12746. }
  12747. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  12748. {
  12749. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  12750. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  12751. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12752. {
  12753. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  12754. }
  12755. else
  12756. {
  12757. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  12758. }
  12759. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  12760. isKnowKey = TRUE;
  12761. }
  12762. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  12763. {
  12764. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  12765. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  12766. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12767. {
  12768. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  12769. }
  12770. else
  12771. {
  12772. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  12773. }
  12774. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  12775. isKnowKey = TRUE;
  12776. }
  12777. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  12778. {
  12779. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  12780. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  12781. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12782. {
  12783. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  12784. }
  12785. else
  12786. {
  12787. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  12788. }
  12789. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  12790. isKnowKey = TRUE;
  12791. }
  12792. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  12793. {
  12794. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  12795. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  12796. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12797. {
  12798. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12799. }
  12800. else
  12801. {
  12802. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12803. }
  12804. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12805. isKnowKey = TRUE;
  12806. }
  12807. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  12808. {
  12809. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  12810. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  12811. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12812. {
  12813. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  12814. }
  12815. else
  12816. {
  12817. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  12818. }
  12819. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  12820. isKnowKey = TRUE;
  12821. }
  12822. /*
  12823. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  12824. {
  12825. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  12826. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  12827. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  12828. {
  12829. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  12830. }
  12831. else
  12832. {
  12833. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  12834. }
  12835. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  12836. isKnowKey = TRUE;
  12837. }*/
  12838. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  12839. {
  12840. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  12841. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  12842. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12843. {
  12844. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  12845. }
  12846. else
  12847. {
  12848. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  12849. }
  12850. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  12851. isKnowKey = TRUE;
  12852. }
  12853. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  12854. {
  12855. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  12856. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  12857. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  12858. {
  12859. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  12860. }
  12861. else
  12862. {
  12863. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  12864. }
  12865. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  12866. isKnowKey = TRUE;
  12867. }
  12868. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  12869. {
  12870. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  12871. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  12872. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12873. {
  12874. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  12875. }
  12876. else
  12877. {
  12878. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  12879. }
  12880. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  12881. isKnowKey = TRUE;
  12882. }
  12883. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  12884. {
  12885. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  12886. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  12887. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12888. {
  12889. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  12890. }
  12891. else
  12892. {
  12893. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  12894. }
  12895. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  12896. isKnowKey = TRUE;
  12897. }
  12898. if(isEmpty || strcmp(keyReq, "ConfigurationVersion") == 0 )
  12899. {
  12900. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConfigurationVersion].Item, "ConfigurationVersion");
  12901. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Key, "ConfigurationVersion");
  12902. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemAccessibility == 1)
  12903. {
  12904. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "0"/*"FALSE"*/);
  12905. }
  12906. else
  12907. {
  12908. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].ReadOnly, "1"/*"TRUE"*/);
  12909. }
  12910. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConfigurationVersion].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConfigurationVersion].ItemData );
  12911. isKnowKey = TRUE;
  12912. }
  12913. #if 1
  12914. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12915. {
  12916. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12917. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12918. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12919. {
  12920. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12921. }
  12922. else
  12923. {
  12924. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12925. }
  12926. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12927. isKnowKey = TRUE;
  12928. }
  12929. #endif
  12930. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12931. {
  12932. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12933. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12934. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12935. {
  12936. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12937. }
  12938. else
  12939. {
  12940. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12941. }
  12942. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12943. isKnowKey = TRUE;
  12944. }
  12945. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12946. {
  12947. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12948. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12949. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12950. {
  12951. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12952. }
  12953. else
  12954. {
  12955. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12956. }
  12957. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12958. isKnowKey = TRUE;
  12959. }
  12960. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12961. {
  12962. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12963. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12964. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12965. {
  12966. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12967. }
  12968. else
  12969. {
  12970. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12971. }
  12972. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12973. isKnowKey = TRUE;
  12974. }
  12975. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12976. {
  12977. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12978. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12979. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12980. {
  12981. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12982. }
  12983. else
  12984. {
  12985. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12986. }
  12987. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12988. isKnowKey = TRUE;
  12989. }
  12990. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12991. {
  12992. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12993. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12994. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12995. {
  12996. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12997. }
  12998. else
  12999. {
  13000. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  13001. }
  13002. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  13003. isKnowKey = TRUE;
  13004. }
  13005. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  13006. {
  13007. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  13008. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  13009. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13010. {
  13011. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  13012. }
  13013. else
  13014. {
  13015. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  13016. }
  13017. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  13018. isKnowKey = TRUE;
  13019. }
  13020. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  13021. {
  13022. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  13023. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  13024. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13025. {
  13026. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  13027. }
  13028. else
  13029. {
  13030. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  13031. }
  13032. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  13033. isKnowKey = TRUE;
  13034. }
  13035. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  13036. {
  13037. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  13038. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  13039. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13040. {
  13041. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  13042. }
  13043. else
  13044. {
  13045. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  13046. }
  13047. strcpy((char *)ShmOCPP16DataPH->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  13048. isKnowKey = TRUE;
  13049. }
  13050. //=========================================================
  13051. if(!isEmpty && !isKnowKey)
  13052. {
  13053. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  13054. strcpy(unknownkey[UnknownKeynum], keyReq);
  13055. UnknownKeynum = UnknownKeynum + 1;
  13056. }
  13057. }
  13058. void processUnkownKey(void)
  13059. {
  13060. DEBUG_INFO("processUnkownKey...\n");
  13061. memset(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  13062. for(int index=0; index < UnknownKeynum; index++)
  13063. {
  13064. if(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  13065. {
  13066. strcpy((char *)(ShmOCPP16DataPH->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  13067. }
  13068. }
  13069. }
  13070. int setKeyValue(char *key, char *value)
  13071. {
  13072. int isSuccess = NotSupported;
  13073. int check_ascii=0;
  13074. char str[256]={0};
  13075. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  13076. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  13077. {
  13078. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  13079. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  13080. {
  13081. strcpy(str, (const char*)value);
  13082. for(int i = 0; str[i]; i++){
  13083. str[i] = tolower(str[i]);
  13084. }
  13085. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13086. isSuccess = ConfigurationStatus_Accepted;
  13087. }
  13088. else
  13089. {
  13090. isSuccess = ConfigurationStatus_Rejected;
  13091. }
  13092. }
  13093. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  13094. {
  13095. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  13096. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  13097. {
  13098. strcpy(str, (const char*)value);
  13099. for(int i = 0; str[i]; i++){
  13100. str[i] = tolower(str[i]);
  13101. }
  13102. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13103. isSuccess = ConfigurationStatus_Accepted;
  13104. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[1].ItemData);
  13105. }
  13106. else
  13107. {
  13108. isSuccess = ConfigurationStatus_Rejected;
  13109. }
  13110. }
  13111. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  13112. {
  13113. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  13114. {
  13115. strcpy(str, (const char*)value);
  13116. for(int i = 0; str[i]; i++)
  13117. {
  13118. str[i] = tolower(str[i]);
  13119. }
  13120. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  13121. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13122. isSuccess = ConfigurationStatus_Accepted;
  13123. }
  13124. else
  13125. {
  13126. isSuccess = ConfigurationStatus_Rejected;
  13127. }
  13128. }
  13129. if(strcmp(key, "BlinkRepeat") == 0)
  13130. {
  13131. //Charger.BlinkRepeat = Integer.parseInt(value);
  13132. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  13133. {
  13134. check_ascii = value[0];
  13135. if( (check_ascii < 48) || (check_ascii > 57) )
  13136. {
  13137. isSuccess = ConfigurationStatus_Rejected;
  13138. }
  13139. else
  13140. {
  13141. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  13142. isSuccess = ConfigurationStatus_Accepted;
  13143. }
  13144. }
  13145. else
  13146. {
  13147. isSuccess = ConfigurationStatus_Rejected;
  13148. }
  13149. }
  13150. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  13151. {
  13152. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  13153. {
  13154. check_ascii = value[0];
  13155. if( (check_ascii < 48) || (check_ascii > 57) )
  13156. {
  13157. isSuccess = ConfigurationStatus_Rejected;
  13158. }
  13159. else
  13160. {
  13161. if((atoi(value) == 0) || (atoi(value) >= 10))
  13162. {
  13163. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  13164. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  13165. isSuccess = ConfigurationStatus_Accepted;
  13166. }
  13167. else
  13168. isSuccess = ConfigurationStatus_Rejected;
  13169. }
  13170. }
  13171. else
  13172. {
  13173. isSuccess = ConfigurationStatus_Rejected;
  13174. }
  13175. }
  13176. if(strcmp(key, "ConnectionTimeOut") == 0 )
  13177. {
  13178. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  13179. {
  13180. check_ascii = value[0];
  13181. if( (check_ascii < 48) || (check_ascii > 57) )
  13182. {
  13183. isSuccess = ConfigurationStatus_Rejected;
  13184. }
  13185. else
  13186. {
  13187. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  13188. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  13189. isSuccess = ConfigurationStatus_Accepted;
  13190. }
  13191. }
  13192. else
  13193. {
  13194. isSuccess = ConfigurationStatus_Rejected;
  13195. }
  13196. }
  13197. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  13198. {
  13199. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  13200. {
  13201. check_ascii = value[0];
  13202. if( (check_ascii < 48) || (check_ascii > 57) )
  13203. {
  13204. isSuccess = ConfigurationStatus_Rejected;
  13205. }
  13206. else
  13207. {
  13208. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13209. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  13210. isSuccess = ConfigurationStatus_Accepted;
  13211. }
  13212. }
  13213. else
  13214. {
  13215. isSuccess = ConfigurationStatus_Rejected;
  13216. }
  13217. }
  13218. if(strcmp(key, "HeartbeatInterval") == 0)
  13219. {
  13220. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  13221. {
  13222. check_ascii = value[0];
  13223. if( (check_ascii < 48) || (check_ascii > 57) )
  13224. {
  13225. isSuccess = ConfigurationStatus_Rejected;
  13226. }
  13227. else
  13228. {
  13229. if((atoi(value) == 0) || (atoi(value) >= 10))
  13230. {
  13231. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  13232. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  13233. HeartBeatWaitTime = atoi(value);
  13234. isSuccess = ConfigurationStatus_Accepted;
  13235. }
  13236. else
  13237. {
  13238. isSuccess = ConfigurationStatus_Rejected;
  13239. }
  13240. }
  13241. }
  13242. else
  13243. {
  13244. isSuccess = ConfigurationStatus_Rejected;
  13245. }
  13246. }
  13247. if(strcmp(key, "LightIntensity") == 0)
  13248. {
  13249. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  13250. {
  13251. check_ascii = value[0];
  13252. if( (check_ascii < 48) || (check_ascii > 57) )
  13253. {
  13254. isSuccess = ConfigurationStatus_Rejected;
  13255. }
  13256. else
  13257. {
  13258. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  13259. isSuccess = ConfigurationStatus_Accepted;
  13260. }
  13261. }
  13262. else
  13263. {
  13264. isSuccess = ConfigurationStatus_Rejected;
  13265. }
  13266. }
  13267. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  13268. {
  13269. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  13270. {
  13271. strcpy(str, (const char*)value);
  13272. for(int i = 0; str[i]; i++)
  13273. {
  13274. str[i] = tolower(str[i]);
  13275. }
  13276. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13277. isSuccess = ConfigurationStatus_Accepted;
  13278. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  13279. }
  13280. else
  13281. {
  13282. isSuccess = ConfigurationStatus_Rejected;
  13283. }
  13284. }
  13285. if(strcmp(key, "LocalPreAuthorize") == 0)
  13286. {
  13287. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  13288. {
  13289. strcpy(str, (const char*)value);
  13290. for(int i = 0; str[i]; i++)
  13291. {
  13292. str[i] = tolower(str[i]);
  13293. }
  13294. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13295. isSuccess = ConfigurationStatus_Accepted;
  13296. }
  13297. else
  13298. {
  13299. isSuccess = ConfigurationStatus_Rejected;
  13300. }
  13301. }
  13302. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  13303. {
  13304. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  13305. {
  13306. check_ascii = value[0];
  13307. if( (check_ascii < 48) || (check_ascii > 57) )
  13308. {
  13309. isSuccess = ConfigurationStatus_Rejected;
  13310. }
  13311. else
  13312. {
  13313. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  13314. isSuccess = ConfigurationStatus_Accepted;
  13315. }
  13316. }
  13317. else
  13318. {
  13319. isSuccess = ConfigurationStatus_Rejected;
  13320. }
  13321. }
  13322. if(strcmp(key, "MeterValuesAlignedData") == 0)
  13323. {
  13324. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  13325. {
  13326. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  13327. isSuccess = ConfigurationStatus_Accepted;
  13328. }
  13329. else
  13330. {
  13331. isSuccess = ConfigurationStatus_Rejected;
  13332. }
  13333. }
  13334. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  13335. {
  13336. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  13337. {
  13338. check_ascii = value[0];
  13339. if( (check_ascii < 48) || (check_ascii > 57) )
  13340. {
  13341. isSuccess = ConfigurationStatus_Rejected;
  13342. }
  13343. else
  13344. {
  13345. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13346. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  13347. isSuccess = ConfigurationStatus_Accepted;
  13348. }
  13349. }
  13350. else
  13351. {
  13352. isSuccess = ConfigurationStatus_Rejected;
  13353. }
  13354. }
  13355. if(strcmp(key, "MeterValuesSampledData") == 0 )
  13356. {
  13357. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  13358. {
  13359. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  13360. isSuccess = ConfigurationStatus_Accepted;
  13361. }
  13362. else
  13363. {
  13364. isSuccess = ConfigurationStatus_Rejected;
  13365. }
  13366. }
  13367. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  13368. {
  13369. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  13370. {
  13371. check_ascii = value[0];
  13372. if( (check_ascii < 48) || (check_ascii > 57) )
  13373. {
  13374. isSuccess = ConfigurationStatus_Rejected;
  13375. }
  13376. else
  13377. {
  13378. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13379. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  13380. isSuccess = ConfigurationStatus_Accepted;
  13381. }
  13382. }
  13383. else
  13384. {
  13385. isSuccess = ConfigurationStatus_Rejected;
  13386. }
  13387. }
  13388. if(strcmp(key, "MeterValueSampleInterval") == 0)
  13389. {
  13390. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  13391. {
  13392. check_ascii = value[0];
  13393. if( (check_ascii < 48) || (check_ascii > 57) )
  13394. {
  13395. isSuccess = ConfigurationStatus_Rejected;
  13396. }
  13397. else
  13398. {
  13399. if((atoi(value) == 0) || (atoi(value) >= 10))
  13400. {
  13401. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  13402. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  13403. isSuccess = ConfigurationStatus_Accepted;
  13404. }
  13405. else
  13406. {
  13407. isSuccess = ConfigurationStatus_Rejected;
  13408. }
  13409. }
  13410. }
  13411. else
  13412. {
  13413. isSuccess = ConfigurationStatus_Rejected;
  13414. }
  13415. }
  13416. if(strcmp(key, "MinimumStatusDuration") == 0)
  13417. {
  13418. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  13419. {
  13420. check_ascii = value[0];
  13421. if( (check_ascii < 48) || (check_ascii > 57) )
  13422. {
  13423. isSuccess = ConfigurationStatus_Rejected;
  13424. }
  13425. else
  13426. {
  13427. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  13428. {
  13429. isSuccess = ConfigurationStatus_Rejected;
  13430. }
  13431. else
  13432. {
  13433. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  13434. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  13435. server_cycle_Status = atoi(value); //StatusNotification Cycle
  13436. isSuccess = ConfigurationStatus_Accepted;
  13437. }
  13438. }
  13439. }
  13440. else
  13441. {
  13442. isSuccess = ConfigurationStatus_Rejected;
  13443. }
  13444. }
  13445. if(strcmp(key, "NumberOfConnectors") == 0)
  13446. {
  13447. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  13448. {
  13449. check_ascii = value[0];
  13450. if( (check_ascii < 48) || (check_ascii > 57) )
  13451. {
  13452. isSuccess = ConfigurationStatus_Rejected;
  13453. }
  13454. else
  13455. {
  13456. //Charger.ResetRetries = Integer.parseInt(value);
  13457. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  13458. isSuccess = ConfigurationStatus_Accepted;
  13459. }
  13460. }
  13461. else
  13462. {
  13463. isSuccess = ConfigurationStatus_Rejected;
  13464. }
  13465. }
  13466. if(strcmp(key, "ResetRetries") == 0)
  13467. {
  13468. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  13469. {
  13470. check_ascii = value[0];
  13471. if( (check_ascii < 48) || (check_ascii > 57) )
  13472. {
  13473. isSuccess = ConfigurationStatus_Rejected;
  13474. }
  13475. else
  13476. {
  13477. //Charger.ResetRetries = Integer.parseInt(value);
  13478. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  13479. isSuccess = ConfigurationStatus_Accepted;
  13480. }
  13481. }
  13482. else
  13483. {
  13484. isSuccess = ConfigurationStatus_Rejected;
  13485. }
  13486. }
  13487. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  13488. {
  13489. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  13490. {
  13491. strcpy(str, (const char*)value);
  13492. for(int i = 0; str[i]; i++)
  13493. {
  13494. str[i] = tolower(str[i]);
  13495. }
  13496. if(strcmp(str, "notapplicable")== 0)
  13497. {
  13498. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  13499. isSuccess = ConfigurationStatus_Accepted;
  13500. }
  13501. else if(strcmp(str, "unknown")== 0)
  13502. {
  13503. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  13504. isSuccess = ConfigurationStatus_Accepted;
  13505. }
  13506. else if(strcmp(str, "rst")== 0)
  13507. {
  13508. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  13509. isSuccess = ConfigurationStatus_Accepted;
  13510. }
  13511. else if(strcmp(str, "rts")== 0)
  13512. {
  13513. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  13514. isSuccess = ConfigurationStatus_Accepted;
  13515. }
  13516. else if(strcmp(str, "srt")== 0)
  13517. {
  13518. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  13519. isSuccess = ConfigurationStatus_Accepted;
  13520. }
  13521. else if(strcmp(str, "str")== 0)
  13522. {
  13523. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  13524. isSuccess = ConfigurationStatus_Accepted;
  13525. }
  13526. else if(strcmp(str, "trs")== 0)
  13527. {
  13528. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  13529. isSuccess = ConfigurationStatus_Accepted;
  13530. }
  13531. else if(strcmp(str, "tsr")== 0)
  13532. {
  13533. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  13534. isSuccess = ConfigurationStatus_Accepted;
  13535. }
  13536. else
  13537. {
  13538. isSuccess = ConfigurationStatus_Rejected;
  13539. }
  13540. }
  13541. else
  13542. {
  13543. isSuccess = ConfigurationStatus_Rejected;
  13544. }
  13545. }
  13546. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  13547. {
  13548. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  13549. {
  13550. check_ascii = value[0];
  13551. if( (check_ascii < 48) || (check_ascii > 57) )
  13552. {
  13553. isSuccess = ConfigurationStatus_Rejected;
  13554. }
  13555. else
  13556. {
  13557. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  13558. isSuccess = ConfigurationStatus_Accepted;
  13559. }
  13560. }
  13561. else
  13562. {
  13563. isSuccess = ConfigurationStatus_Rejected;
  13564. }
  13565. }
  13566. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  13567. {
  13568. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  13569. {
  13570. strcpy(str, (const char*)value);
  13571. for(int i = 0; str[i]; i++)
  13572. {
  13573. str[i] = tolower(str[i]);
  13574. }
  13575. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13576. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13577. isSuccess = ConfigurationStatus_Accepted;
  13578. }
  13579. else
  13580. {
  13581. isSuccess = ConfigurationStatus_Rejected;
  13582. }
  13583. }
  13584. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  13585. {
  13586. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  13587. {
  13588. strcpy(str, (const char*)value);
  13589. for(int i = 0; str[i]; i++)
  13590. {
  13591. str[i] = tolower(str[i]);
  13592. }
  13593. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  13594. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13595. isSuccess = ConfigurationStatus_Accepted;
  13596. }
  13597. else
  13598. {
  13599. isSuccess = ConfigurationStatus_Rejected;
  13600. }
  13601. }
  13602. if(strcmp(key, "StopTxnAlignedData") == 0)
  13603. {
  13604. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  13605. {
  13606. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  13607. isSuccess = ConfigurationStatus_Accepted;
  13608. }
  13609. else
  13610. {
  13611. isSuccess = ConfigurationStatus_Rejected;
  13612. }
  13613. }
  13614. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  13615. {
  13616. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  13617. {
  13618. check_ascii = value[0];
  13619. if( (check_ascii < 48) || (check_ascii > 57) )
  13620. {
  13621. isSuccess = ConfigurationStatus_Rejected;
  13622. }
  13623. else
  13624. {
  13625. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  13626. isSuccess = ConfigurationStatus_Accepted;
  13627. }
  13628. }
  13629. else
  13630. {
  13631. isSuccess = ConfigurationStatus_Rejected;
  13632. }
  13633. }
  13634. if(strcmp(key, "StopTxnSampledData") == 0)
  13635. {
  13636. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  13637. {
  13638. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  13639. isSuccess = ConfigurationStatus_Accepted;
  13640. }
  13641. else
  13642. {
  13643. isSuccess = ConfigurationStatus_Rejected;
  13644. }
  13645. }
  13646. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  13647. {
  13648. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  13649. {
  13650. check_ascii = value[0];
  13651. if( (check_ascii < 48) || (check_ascii > 57) )
  13652. {
  13653. isSuccess = ConfigurationStatus_Rejected;
  13654. }
  13655. else
  13656. {
  13657. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  13658. isSuccess = ConfigurationStatus_Accepted;
  13659. }
  13660. }
  13661. else
  13662. {
  13663. isSuccess = ConfigurationStatus_Rejected;
  13664. }
  13665. }
  13666. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  13667. {
  13668. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  13669. {
  13670. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  13671. isSuccess = ConfigurationStatus_Accepted;
  13672. }
  13673. else
  13674. {
  13675. isSuccess = ConfigurationStatus_Rejected;
  13676. }
  13677. }
  13678. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  13679. {
  13680. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  13681. {
  13682. check_ascii = value[0];
  13683. if( (check_ascii < 48) || (check_ascii > 57) )
  13684. {
  13685. isSuccess = ConfigurationStatus_Rejected;
  13686. }
  13687. else
  13688. {
  13689. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  13690. isSuccess = ConfigurationStatus_Accepted;
  13691. }
  13692. }
  13693. else
  13694. {
  13695. isSuccess = ConfigurationStatus_Rejected;
  13696. }
  13697. }
  13698. if(strcmp(key, "TransactionMessageAttempts") == 0)
  13699. {
  13700. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  13701. {
  13702. check_ascii = value[0];
  13703. if( (check_ascii < 48) || (check_ascii > 57) )
  13704. {
  13705. isSuccess = ConfigurationStatus_Rejected;
  13706. }
  13707. else
  13708. {
  13709. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  13710. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  13711. TransactionMessageAttemptsValue = atoi(value);
  13712. isSuccess = ConfigurationStatus_Accepted;
  13713. }
  13714. }
  13715. else
  13716. {
  13717. isSuccess = ConfigurationStatus_Rejected;
  13718. }
  13719. }
  13720. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  13721. {
  13722. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  13723. {
  13724. check_ascii = value[0];
  13725. if( (check_ascii < 48) || (check_ascii > 57) )
  13726. {
  13727. isSuccess = ConfigurationStatus_Rejected;
  13728. }
  13729. else
  13730. {
  13731. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  13732. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  13733. TransactionMessageRetryIntervalValue = atoi(value);
  13734. isSuccess = ConfigurationStatus_Accepted;
  13735. }
  13736. }
  13737. else
  13738. {
  13739. isSuccess = ConfigurationStatus_Rejected;
  13740. }
  13741. }
  13742. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  13743. {
  13744. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  13745. {
  13746. strcpy(str, (const char*)value);
  13747. for(int i = 0; str[i]; i++)
  13748. {
  13749. str[i] = tolower(str[i]);
  13750. }
  13751. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  13752. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13753. isSuccess = ConfigurationStatus_Accepted;
  13754. }
  13755. else
  13756. {
  13757. isSuccess = ConfigurationStatus_Rejected;
  13758. }
  13759. }
  13760. if(strcmp(key, "WebSocketPingInterval") == 0)
  13761. {
  13762. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  13763. {
  13764. check_ascii = value[0];
  13765. if( (check_ascii < 48) || (check_ascii > 57) )
  13766. {
  13767. isSuccess = ConfigurationStatus_Rejected;
  13768. }
  13769. else
  13770. {
  13771. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  13772. isSuccess = ConfigurationStatus_Accepted;
  13773. }
  13774. }
  13775. else
  13776. {
  13777. isSuccess = ConfigurationStatus_Rejected;
  13778. }
  13779. }
  13780. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  13781. {
  13782. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  13783. {
  13784. strcpy(str, (const char*)value);
  13785. for(int i = 0; str[i]; i++)
  13786. {
  13787. str[i] = tolower(str[i]);
  13788. }
  13789. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13790. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13791. isSuccess = ConfigurationStatus_Accepted;
  13792. }
  13793. else
  13794. {
  13795. isSuccess = ConfigurationStatus_Rejected;
  13796. }
  13797. }
  13798. if(strcmp(key, "AuthorizationKey") == 0)
  13799. {
  13800. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  13801. {
  13802. strcpy(str, (const char*)value);
  13803. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  13804. strcpy((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword, (char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13805. isSuccess = ConfigurationStatus_Accepted;
  13806. }
  13807. else
  13808. {
  13809. isSuccess = ConfigurationStatus_Rejected;
  13810. }
  13811. }
  13812. if(strcmp(key, "SecurityProfile") == 0)
  13813. {
  13814. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  13815. {
  13816. check_ascii = value[0];
  13817. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  13818. {
  13819. isSuccess = ConfigurationStatus_Rejected;
  13820. }
  13821. else if(check_ascii == 0x33)
  13822. {
  13823. isSuccess = NotSupported;
  13824. }
  13825. else
  13826. {
  13827. if(atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  13828. {
  13829. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  13830. ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile = atoi(value);
  13831. isSuccess = ConfigurationStatus_Accepted;
  13832. }
  13833. else
  13834. isSuccess = ConfigurationStatus_Rejected;
  13835. }
  13836. }
  13837. else
  13838. {
  13839. isSuccess = ConfigurationStatus_Rejected;
  13840. }
  13841. }
  13842. if(strcmp(key, "DefaultPrice") == 0)
  13843. {
  13844. if((ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  13845. {
  13846. strcpy(str, (const char*)value);
  13847. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  13848. isSuccess = ConfigurationStatus_Accepted;
  13849. }
  13850. else
  13851. {
  13852. isSuccess = ConfigurationStatus_Rejected;
  13853. }
  13854. }
  13855. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  13856. {
  13857. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  13858. {
  13859. strcpy(str, (const char*)value);
  13860. for(int i = 0; str[i]; i++)
  13861. {
  13862. str[i] = tolower(str[i]);
  13863. }
  13864. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  13865. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13866. isSuccess = ConfigurationStatus_Accepted;
  13867. }
  13868. else
  13869. {
  13870. isSuccess = ConfigurationStatus_Rejected;
  13871. }
  13872. }
  13873. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  13874. {
  13875. if(ShmOCPP16DataPH->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].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[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13884. isSuccess = ConfigurationStatus_Accepted;
  13885. }
  13886. else
  13887. {
  13888. isSuccess = ConfigurationStatus_Rejected;
  13889. }
  13890. }
  13891. #if 0
  13892. //For OCPP Test Case
  13893. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  13894. {
  13895. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13896. {
  13897. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  13898. isSuccess = ConfigurationStatus_Accepted;
  13899. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13900. }
  13901. else
  13902. {
  13903. isSuccess = ConfigurationStatus_Rejected;
  13904. }
  13905. }
  13906. #endif
  13907. #if 1
  13908. if(strcmp(key, "LocalAuthListEnabled") == 0)
  13909. {
  13910. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  13911. {
  13912. strcpy(str, (const char*)value);
  13913. for(int i = 0; str[i]; i++)
  13914. {
  13915. str[i] = tolower(str[i]);
  13916. }
  13917. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13918. isSuccess = ConfigurationStatus_Accepted;
  13919. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  13920. }
  13921. else
  13922. {
  13923. isSuccess = ConfigurationStatus_Rejected;
  13924. }
  13925. }
  13926. #endif
  13927. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  13928. {
  13929. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  13930. {
  13931. check_ascii = value[0];
  13932. if( (check_ascii < 48) || (check_ascii > 57) )
  13933. {
  13934. isSuccess = ConfigurationStatus_Rejected;
  13935. }
  13936. else
  13937. {
  13938. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  13939. isSuccess = ConfigurationStatus_Accepted;
  13940. }
  13941. }
  13942. else
  13943. {
  13944. isSuccess = ConfigurationStatus_Rejected;
  13945. }
  13946. }
  13947. if(strcmp(key, "SendLocalListMaxLength") == 0)
  13948. {
  13949. if(ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  13950. {
  13951. check_ascii = value[0];
  13952. if( (check_ascii < 48) || (check_ascii > 57) )
  13953. {
  13954. isSuccess = ConfigurationStatus_Rejected;
  13955. }
  13956. else
  13957. {
  13958. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  13959. isSuccess = ConfigurationStatus_Accepted;
  13960. }
  13961. }
  13962. else
  13963. {
  13964. isSuccess = ConfigurationStatus_Rejected;
  13965. }
  13966. }
  13967. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  13968. {
  13969. if(ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  13970. {
  13971. strcpy(str, (const char*)value);
  13972. for(int i = 0; str[i]; i++)
  13973. {
  13974. str[i] = tolower(str[i]);
  13975. }
  13976. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13977. isSuccess = ConfigurationStatus_Accepted;
  13978. }
  13979. else
  13980. {
  13981. isSuccess = ConfigurationStatus_Rejected;
  13982. }
  13983. }
  13984. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  13985. {
  13986. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  13987. {
  13988. check_ascii = value[0];
  13989. if( (check_ascii < 48) || (check_ascii > 57) )
  13990. {
  13991. isSuccess = ConfigurationStatus_Rejected;
  13992. }
  13993. else
  13994. {
  13995. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  13996. isSuccess = ConfigurationStatus_Accepted;
  13997. }
  13998. }
  13999. else
  14000. {
  14001. isSuccess = ConfigurationStatus_Rejected;
  14002. }
  14003. }
  14004. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  14005. {
  14006. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  14007. {
  14008. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  14009. isSuccess = ConfigurationStatus_Accepted;
  14010. }
  14011. else
  14012. {
  14013. isSuccess = ConfigurationStatus_Rejected;
  14014. }
  14015. }
  14016. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  14017. {
  14018. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  14019. {
  14020. check_ascii = value[0];
  14021. if( (check_ascii < 48) || (check_ascii > 57) )
  14022. {
  14023. isSuccess = ConfigurationStatus_Rejected;
  14024. }
  14025. else
  14026. {
  14027. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  14028. isSuccess = ConfigurationStatus_Accepted;
  14029. }
  14030. }
  14031. else
  14032. {
  14033. isSuccess = ConfigurationStatus_Rejected;
  14034. }
  14035. }
  14036. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  14037. {
  14038. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  14039. {
  14040. strcpy(str, (const char*)value);
  14041. for(int i = 0; str[i]; i++)
  14042. {
  14043. str[i] = tolower(str[i]);
  14044. }
  14045. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  14046. isSuccess = ConfigurationStatus_Accepted;
  14047. }
  14048. else
  14049. {
  14050. isSuccess = ConfigurationStatus_Rejected;
  14051. }
  14052. }
  14053. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  14054. {
  14055. if(ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  14056. {
  14057. check_ascii = value[0];
  14058. if( (check_ascii < 48) || (check_ascii > 57) )
  14059. {
  14060. isSuccess = ConfigurationStatus_Rejected;
  14061. }
  14062. else
  14063. {
  14064. sprintf((char *)ShmOCPP16DataPH->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  14065. isSuccess = ConfigurationStatus_Accepted;
  14066. }
  14067. }
  14068. else
  14069. {
  14070. isSuccess = ConfigurationStatus_Rejected;
  14071. }
  14072. }
  14073. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14074. return isSuccess;
  14075. }
  14076. int TransactionMessageAttemptsGet(void)
  14077. {
  14078. return TransactionMessageAttemptsValue;
  14079. }
  14080. int FirstHeartBeatResponse(void)
  14081. {
  14082. return FirstHeartBeat;
  14083. }
  14084. int TransactionMessageRetryIntervalGet(void)
  14085. {
  14086. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14087. }
  14088. int ReadHttpStatus(int sock)
  14089. {
  14090. //char c;
  14091. char buff[1024]="",*ptr=buff+1;
  14092. int bytes_received, status;
  14093. DEBUG_INFO("Begin Response ..\n");
  14094. while((bytes_received = recv(sock, ptr, 1, 0))){
  14095. if(bytes_received==-1){
  14096. perror("ReadHttpStatus");
  14097. exit(1);
  14098. }
  14099. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  14100. ptr++;
  14101. }
  14102. *ptr=0;
  14103. ptr=buff+1;
  14104. sscanf(ptr,"%*s %d ", &status);
  14105. DEBUG_INFO("%s\n",ptr);
  14106. DEBUG_INFO("status=%d\n",status);
  14107. DEBUG_INFO("End Response ..\n");
  14108. return (bytes_received>0)?status:0;
  14109. }
  14110. //the only filed that it parsed is 'Content-Length'
  14111. int ParseHeader(int sock)
  14112. {
  14113. //char c;
  14114. char buff[1024]="",*ptr=buff+4;
  14115. int bytes_received;
  14116. DEBUG_INFO("Begin HEADER ..\n");
  14117. while((bytes_received = recv(sock, ptr, 1, 0))){
  14118. if(bytes_received==-1){
  14119. perror("Parse Header");
  14120. exit(1);
  14121. }
  14122. if(
  14123. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  14124. (ptr[-1]=='\r') && (*ptr=='\n' )
  14125. ) break;
  14126. ptr++;
  14127. }
  14128. *ptr=0;
  14129. ptr=buff+4;
  14130. //printf("%s",ptr);
  14131. if(bytes_received){
  14132. ptr=strstr(ptr,"Content-Length:");
  14133. if(ptr){
  14134. sscanf(ptr,"%*s %d",&bytes_received);
  14135. }else
  14136. bytes_received=-1; //unknown size
  14137. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  14138. }
  14139. DEBUG_INFO("End HEADER ..\n");
  14140. return bytes_received ;
  14141. }
  14142. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14143. {
  14144. int result = TRUE;
  14145. char rmFileCmd[100]={0};
  14146. char FilePath[100]={0};
  14147. char ftpbuf[200];
  14148. int systemresult;
  14149. //DEBUG_INFO("filename=%s\n",filename);
  14150. //DEBUG_INFO("url=%s\n",url);
  14151. sprintf(FilePath,"/mnt/%s",filename);
  14152. system("ping 8.8.8.8 &");
  14153. if((access(FilePath,F_OK))!=-1)
  14154. {
  14155. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14156. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14157. system(rmFileCmd);
  14158. }
  14159. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14160. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14161. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14162. systemresult = system(ftpbuf);
  14163. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14164. if(systemresult != 0)
  14165. {
  14166. DEBUG_INFO("http DownLoad error!\n");
  14167. result = FALSE;
  14168. }
  14169. system("pkill ping");
  14170. return result;
  14171. }
  14172. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14173. {
  14174. int result = TRUE;
  14175. char rmFileCmd[100]={0};
  14176. char FilePath[100]={0};
  14177. char ftpbuf[200];
  14178. int systemresult;
  14179. //char temp[100];
  14180. sprintf(FilePath,"/mnt/%s",filename);
  14181. system("ping 8.8.8.8 &");
  14182. if((access(FilePath,F_OK))!=-1)
  14183. {
  14184. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14185. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14186. system(rmFileCmd);
  14187. }
  14188. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14189. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14190. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14191. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14192. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14193. systemresult = system(ftpbuf);
  14194. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14195. if(systemresult != 0)
  14196. {
  14197. DEBUG_WARN("wget error!\n");
  14198. result = FALSE;
  14199. }
  14200. system("pkill ping");
  14201. return result;
  14202. }
  14203. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14204. {
  14205. char rmFileCmd[100]={0};
  14206. char FilePath[100]={0};
  14207. char buf[512];
  14208. int systemresult = 0;
  14209. //DEBUG_INFO("filename=%s\n",filename);
  14210. //DEBUG_INFO("url=%s\n",url);
  14211. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14212. if((access(FilePath,F_OK))!=-1)
  14213. {
  14214. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14215. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14216. system(rmFileCmd);
  14217. }
  14218. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14219. if(fp == NULL)
  14220. {
  14221. DEBUG_INFO("log is NULL\n");
  14222. return FALSE;
  14223. }
  14224. else
  14225. {
  14226. fprintf(fp, "%s\n", url);
  14227. fprintf(fp, "%s\n", filename);
  14228. fclose(fp);
  14229. }
  14230. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14231. if(phpFP == NULL)
  14232. {
  14233. DEBUG_INFO("PHP upload fail.\n");
  14234. return FALSE;
  14235. }
  14236. else
  14237. {
  14238. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14239. {
  14240. if(strstr(buf, "result") != NULL)
  14241. {
  14242. sscanf(buf, "result: %d", &systemresult);
  14243. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14244. }
  14245. }
  14246. pclose(phpFP);
  14247. }
  14248. if(systemresult != 1)
  14249. {
  14250. DEBUG_INFO("HTTP upload error!\n");
  14251. return FALSE;
  14252. }
  14253. return TRUE;
  14254. }
  14255. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14256. {
  14257. struct hostent* server;
  14258. char *IPbuffer;
  14259. char ftpbuf[200];
  14260. int systemresult;
  14261. // To retrieve host information
  14262. server = gethostbyname(location);
  14263. // To convert an Internet network
  14264. // address into ASCII string
  14265. IPbuffer = inet_ntoa(*((struct in_addr*)
  14266. server->h_addr_list[0]));
  14267. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14268. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14269. /* format : ftpput -u username -p passwd IP target source*/
  14270. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14271. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14272. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14273. systemresult = system(ftpbuf);
  14274. DEBUG_INFO("systemresult=%d\n",systemresult);
  14275. if(systemresult != 0)
  14276. {
  14277. DEBUG_INFO("ftpput error!\n");
  14278. return FALSE;
  14279. }
  14280. return TRUE;
  14281. }
  14282. int GetOcppServerURL()
  14283. {
  14284. int result = FALSE;
  14285. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14286. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14287. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14288. struct yuarel url;
  14289. char urlStr[512];
  14290. // OCPPPH only
  14291. sprintf((char*)ShmOCPP16DataPH->OcppServerURL, "wss://ocpp.phihong.com.tw:2013/");
  14292. sprintf((char*)ShmOCPP16DataPH->ChargeBoxId, "%s%s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  14293. if((ShmOCPP16DataPH->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16DataPH->OcppServerURL,"") != 0))
  14294. {
  14295. /*sscanf((const char *)ShmOCPP16DataPH->OcppServerURL,
  14296. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14297. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  14298. memcpy(urlStr, ShmOCPP16DataPH->OcppServerURL, ARRAY_SIZE(ShmOCPP16DataPH->OcppServerURL));
  14299. if(yuarel_parse(&url, urlStr) != -1)
  14300. {
  14301. sprintf(OcppProtocol, "%s", url.scheme);
  14302. sprintf(OcppHost, "%s", url.host);
  14303. if(url.path == NULL)
  14304. OcppTempPath[0] = '\0';
  14305. else
  14306. sprintf(OcppTempPath, "%s", url.path);
  14307. if(url.port == 0)
  14308. {
  14309. if(strcmp(OcppProtocol, "wss") == 0)
  14310. OcppPort = 443;
  14311. else
  14312. OcppPort = 80;
  14313. }
  14314. else
  14315. OcppPort = url.port;
  14316. result = TRUE;
  14317. }
  14318. }
  14319. else
  14320. {
  14321. strcpy(OcppHost,"");
  14322. }
  14323. return result;
  14324. }
  14325. int GetOcppPath()
  14326. {
  14327. int result = FALSE;
  14328. if((ShmOCPP16DataPH->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16DataPH->ChargeBoxId,"") != 0))
  14329. {
  14330. if(OcppTempPath == NULL)
  14331. {
  14332. sprintf(OcppPath,"/%s",ShmOCPP16DataPH->ChargeBoxId);
  14333. }
  14334. else
  14335. {
  14336. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16DataPH->ChargeBoxId);
  14337. }
  14338. result = TRUE;
  14339. goto End;
  14340. }
  14341. else
  14342. {
  14343. strcpy(OcppPath,"");
  14344. }
  14345. End:
  14346. return result;
  14347. }
  14348. int GetOcppPort()
  14349. {
  14350. return OcppPort;
  14351. }
  14352. int GetOcppConnStatus(void)
  14353. {
  14354. return ShmOCPP16DataPH->OcppConnStatus;
  14355. }
  14356. void SetOcppConnStatus(uint8_t status)
  14357. {
  14358. ShmOCPP16DataPH->OcppConnStatus = status;
  14359. }
  14360. int GetHeartBeatWithNOResponse(void)
  14361. {
  14362. return HeartBeatWithNOResponse;
  14363. }
  14364. void SetHeartBeatWithNOResponse(void)
  14365. {
  14366. HeartBeatWithNOResponse = 0;
  14367. }
  14368. void GetStartTransactionIdTag(int gun_index)
  14369. {
  14370. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  14371. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14372. }
  14373. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  14374. {
  14375. char ch;
  14376. FILE *fptr1;
  14377. int temptransactionId;
  14378. char str[100]={0};
  14379. temptransactionId = 0;
  14380. if(((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0')) && isStopTransaction)
  14381. {
  14382. DEBUG_INFO("IdTag is empty.\n");
  14383. return temptransactionId;
  14384. }
  14385. /*------ Read the file ----------------*/
  14386. fptr1=fopen("/Storage/OCPP_PH/QueueTransactionId","r");
  14387. if (!fptr1)
  14388. {
  14389. DEBUG_INFO("QueueTransactionId file open error.\n");
  14390. //printf(" File not found or unable to open the input file!!\n");
  14391. return temptransactionId;
  14392. }
  14393. ch=fgetc(fptr1);
  14394. //printf(" Now the content of the file %s is : \n","/Storage/OCPP_PH/QueueTransactionId");
  14395. rewind(fptr1);
  14396. if(ch!=EOF)
  14397. {
  14398. // printf("%c",ch);
  14399. while (fgets(str, 100, fptr1) != NULL)
  14400. {
  14401. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14402. if(str[0]=='\0')
  14403. {
  14404. break;
  14405. }
  14406. char *revbuf[8] = {0}; // Variable store string split
  14407. int num = 0;// Quantity after string split
  14408. DEBUG_INFO("Transaction queue data= %s\n", str);
  14409. splitstring(str,",",revbuf,&num); // String split
  14410. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  14411. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  14412. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  14413. DEBUG_INFO("------------------------------\n");
  14414. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  14415. {
  14416. if(isStopTransaction)
  14417. {
  14418. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  14419. {
  14420. temptransactionId = atoi(revbuf[2]);
  14421. //break;
  14422. }
  14423. }
  14424. else
  14425. {
  14426. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  14427. {
  14428. temptransactionId = atoi(revbuf[2]);
  14429. //break;
  14430. }
  14431. }
  14432. }
  14433. }
  14434. }
  14435. else
  14436. DEBUG_INFO("EOF\n");
  14437. fclose(fptr1);
  14438. /*------- End of reading ---------------*/
  14439. return temptransactionId;
  14440. }
  14441. void SetTransactionIdZero(int transactionId)
  14442. {
  14443. char ch;
  14444. FILE *fptr1, *fptr2;
  14445. int temptransactionId = 0;
  14446. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP_PH/QueueTransactionIdtemp.json";
  14447. fptr1 = fopen("/Storage/OCPP_PH/QueueTransactionId", "r");
  14448. if (!fptr1)
  14449. {
  14450. //printf(" File not found or unable to open the input file!!\n");
  14451. return ;
  14452. }
  14453. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  14454. if (!fptr2)
  14455. {
  14456. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  14457. fclose(fptr1);
  14458. return ;
  14459. }
  14460. ch=fgetc(fptr1);
  14461. rewind(fptr1);
  14462. if(ch!=EOF)
  14463. {
  14464. // copy all contents to the temporary file except the specific line
  14465. while (fgets(str, 100, fptr1) != NULL)
  14466. {
  14467. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14468. if(str[0]=='\0')
  14469. {
  14470. break;
  14471. }
  14472. char *revbuf[8] = {0};
  14473. int num = 0;
  14474. strcpy(strtemp, str);
  14475. splitstring(str,",",revbuf,&num);
  14476. if(revbuf[2][0] != '\0')
  14477. {
  14478. temptransactionId = atoi(revbuf[2]);
  14479. if(transactionId != temptransactionId)
  14480. {
  14481. fprintf(fptr2, "%s\n", strtemp);
  14482. }
  14483. }
  14484. }
  14485. }
  14486. fclose(fptr1);
  14487. fclose(fptr2);
  14488. remove("/Storage/OCPP_PH/QueueTransactionId"); // remove the original file
  14489. rename(temp, "/Storage/OCPP_PH/QueueTransactionId"); // rename the temporary file to original name
  14490. /*------ Read the file ----------------*/
  14491. }
  14492. int InternetDisconnect(void)
  14493. {
  14494. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  14495. }
  14496. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14497. void storeTempStopTransaction(int gun_index)
  14498. {
  14499. char guid[37]={0};
  14500. int tempIndex = 0;
  14501. char TempStopTransaction[256];
  14502. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  14503. DEBUG_INFO("storeTempStopTransaction...\n");
  14504. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  14505. memset(&ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData));
  14506. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  14507. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14508. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14509. {
  14510. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14511. {
  14512. tempIndex = ((gun_index==2) ? 1: 0);
  14513. }
  14514. else
  14515. {
  14516. tempIndex = gun_index;
  14517. }
  14518. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14519. {
  14520. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14521. {
  14522. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  14523. }
  14524. }// END OF CHAdeMO_QUANTITY
  14525. }
  14526. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14527. {
  14528. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14529. {
  14530. tempIndex = ((gun_index==2) ? 1: 0);
  14531. }
  14532. else
  14533. {
  14534. tempIndex = gun_index;
  14535. }
  14536. for (int index = 0; index < CCS_QUANTITY; index++)
  14537. {
  14538. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14539. {
  14540. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  14541. }
  14542. }// END OF CCS_QUANTITY
  14543. }
  14544. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14545. {
  14546. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14547. {
  14548. tempIndex = ((gun_index==2) ? 1: 0);
  14549. }
  14550. else
  14551. {
  14552. tempIndex = gun_index;
  14553. }
  14554. for (int index = 0; index < GB_QUANTITY; index++)
  14555. {
  14556. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14557. {
  14558. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  14559. }
  14560. }// END OF GB_QUANTITY
  14561. }
  14562. else if(gunType[gun_index] == GUN_TYPE_DO)
  14563. {
  14564. tempIndex = gun_index;
  14565. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14566. {
  14567. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14568. {
  14569. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  14570. }
  14571. }
  14572. }
  14573. else
  14574. {
  14575. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14576. {
  14577. tempIndex = 2;
  14578. }
  14579. else
  14580. {
  14581. tempIndex = gun_index;
  14582. }
  14583. for (int index = 0; index < AC_QUANTITY; index++)
  14584. {
  14585. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14586. {
  14587. ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  14588. }
  14589. }// END OF AC_QUANTITY
  14590. }
  14591. //Stop Transaction Time
  14592. struct timeval tmnow;
  14593. struct tm *tm;
  14594. char buf[28];//, usec_buf[6];
  14595. gettimeofday(&tmnow, NULL);
  14596. time_t t;
  14597. t = time(NULL);
  14598. /*UTC time and date*/
  14599. tm = gmtime(&t);
  14600. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  14601. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp,buf);
  14602. ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId = ShmOCPP16DataPH->StartTransaction[gun_index].ResponseTransactionId;
  14603. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16DataPH->StartTransaction[gun_index].IdTag);
  14604. random_uuid(guid);
  14605. /***********************************transactionData******************************************************/
  14606. memset(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData, 0, sizeof(struct StructMeterValue));
  14607. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  14608. //=================================
  14609. //1. Transaction_Begin
  14610. //=================================
  14611. //============================== Energy.Active.Import.Interval ===========================================
  14612. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14613. {
  14614. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.3f", 0.0); // MeterStart is 0~6553.5 kWh
  14615. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14616. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  14617. 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*/]);
  14618. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14619. 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))
  14620. {
  14621. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  14622. }
  14623. else
  14624. {
  14625. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  14626. }
  14627. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  14628. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14629. }
  14630. //=================================
  14631. //2. Transaction_End
  14632. //=================================
  14633. //2.1====================================== Current.Import L1 ==============================================
  14634. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  14635. {
  14636. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  14637. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  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 < CHAdeMO_QUANTITY; index++)
  14648. {
  14649. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14650. {
  14651. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14652. }
  14653. }// End of for CHAdeMO_QUANTITY
  14654. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14655. }
  14656. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14657. {
  14658. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14659. {
  14660. tempIndex = ((gun_index==2) ? 1: 0);
  14661. }
  14662. else
  14663. {
  14664. tempIndex = gun_index;
  14665. }
  14666. for (int index = 0; index < CCS_QUANTITY; index++)
  14667. {
  14668. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14669. {
  14670. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14671. }
  14672. }// End of for CCS_QUANTITY
  14673. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14674. }
  14675. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14676. {
  14677. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14678. {
  14679. tempIndex = ((gun_index==2) ? 1: 0);
  14680. }
  14681. else
  14682. {
  14683. tempIndex = gun_index;
  14684. }
  14685. for (int index = 0; index < GB_QUANTITY; index++)
  14686. {
  14687. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14688. {
  14689. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14690. }
  14691. }// End of for GB_QUANTITY
  14692. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14693. }
  14694. else if(gunType[gun_index] == GUN_TYPE_DO)
  14695. {
  14696. tempIndex = gun_index;
  14697. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14698. {
  14699. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14700. {
  14701. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  14702. }
  14703. }
  14704. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  14705. }
  14706. else
  14707. {
  14708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14709. {
  14710. tempIndex = 2;
  14711. }
  14712. else
  14713. {
  14714. tempIndex = gun_index;
  14715. }
  14716. for (int index = 0; index < AC_QUANTITY; index++)
  14717. {
  14718. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14719. {
  14720. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  14721. }
  14722. }// End of for AC_QUANTITY
  14723. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14724. }
  14725. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14726. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  14727. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  14728. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  14729. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  14730. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14731. }
  14732. //2.2===================================== Energy.Active.Import.Interval ==========================================
  14733. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Interval") != NULL)
  14734. {
  14735. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14736. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14737. {
  14738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14739. {
  14740. tempIndex = ((gun_index==2) ? 1: 0);
  14741. }
  14742. else
  14743. {
  14744. tempIndex = gun_index;
  14745. }
  14746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14747. {
  14748. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14749. {
  14750. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14751. }
  14752. }// END OF CHAdeMO_QUANTITY
  14753. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14754. }
  14755. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14756. {
  14757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14758. {
  14759. tempIndex = ((gun_index==2) ? 1: 0);
  14760. }
  14761. else
  14762. {
  14763. tempIndex = gun_index;
  14764. }
  14765. for (int index = 0; index < CCS_QUANTITY; index++)
  14766. {
  14767. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14768. {
  14769. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14770. }
  14771. }// END OF CCS_QUANTITY
  14772. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14773. }
  14774. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14775. {
  14776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14777. {
  14778. tempIndex = ((gun_index==2) ? 1: 0);
  14779. }
  14780. else
  14781. {
  14782. tempIndex = gun_index;
  14783. }
  14784. for (int index = 0; index < GB_QUANTITY; index++)
  14785. {
  14786. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14787. {
  14788. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14789. }
  14790. }// END OF GB_QUANTITY
  14791. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14792. }
  14793. else if(gunType[gun_index] == GUN_TYPE_DO)
  14794. {
  14795. tempIndex = gun_index;
  14796. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14797. {
  14798. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14799. {
  14800. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14801. }
  14802. }
  14803. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  14804. }
  14805. else
  14806. {
  14807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14808. {
  14809. tempIndex = 2;
  14810. }
  14811. else
  14812. {
  14813. tempIndex = gun_index;
  14814. }
  14815. for (int index = 0; index < AC_QUANTITY; index++)
  14816. {
  14817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14818. {
  14819. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.3f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  14820. }
  14821. }// END OF AC_QUANTITY
  14822. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14823. }
  14824. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14825. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  14826. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  14827. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  14828. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  14829. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  14830. }
  14831. //2.3====================================== Power.Active.Import =========================================
  14832. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Power.Active.Import") != NULL)
  14833. {
  14834. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14835. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14836. {
  14837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14838. {
  14839. tempIndex = ((gun_index==2) ? 1: 0);
  14840. }
  14841. else
  14842. {
  14843. tempIndex = gun_index;
  14844. }
  14845. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14846. {
  14847. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14848. {
  14849. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14850. }
  14851. } // End for CHAdeMO_QUANTITY
  14852. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14853. }
  14854. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14855. {
  14856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14857. {
  14858. tempIndex = ((gun_index==2) ? 1: 0);
  14859. }
  14860. else
  14861. {
  14862. tempIndex = gun_index;
  14863. }
  14864. for (int index = 0; index < CCS_QUANTITY; index++)
  14865. {
  14866. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14867. {
  14868. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14869. }
  14870. } // END for CCS_QUANTITY
  14871. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14872. }
  14873. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14874. {
  14875. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14876. {
  14877. tempIndex = ((gun_index==2) ? 1: 0);
  14878. }
  14879. else
  14880. {
  14881. tempIndex = gun_index;
  14882. }
  14883. for (int index = 0; index < GB_QUANTITY; index++)
  14884. {
  14885. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14886. {
  14887. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14888. }
  14889. }// END for GB_QUANTITY
  14890. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14891. }
  14892. else if(gunType[gun_index] == GUN_TYPE_DO)
  14893. {
  14894. tempIndex = gun_index;
  14895. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14896. {
  14897. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14898. {
  14899. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14900. }
  14901. }
  14902. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  14903. }
  14904. else
  14905. {
  14906. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14907. {
  14908. tempIndex = 2;
  14909. }
  14910. else
  14911. {
  14912. tempIndex = gun_index;
  14913. }
  14914. for (int index = 0; index < AC_QUANTITY; index++)
  14915. {
  14916. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14917. {
  14918. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  14919. }
  14920. } // END for AC_QUANTITY
  14921. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14922. }
  14923. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14924. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  14925. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  14926. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  14927. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  14928. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  14929. }
  14930. //2.4====================================== Voltage L1 ====================================================
  14931. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  14932. {
  14933. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  14934. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14935. {
  14936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14937. {
  14938. tempIndex = ((gun_index==2) ? 1: 0);
  14939. }
  14940. else
  14941. {
  14942. tempIndex = gun_index;
  14943. }
  14944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14945. {
  14946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  14947. {
  14948. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14949. }
  14950. } // END OF FOR CHAdeMO_QUANTITY
  14951. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14952. }
  14953. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14954. {
  14955. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14956. {
  14957. tempIndex = ((gun_index==2) ? 1: 0);
  14958. }
  14959. else
  14960. {
  14961. tempIndex = gun_index;
  14962. }
  14963. for (int index = 0; index < CCS_QUANTITY; index++)
  14964. {
  14965. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14966. {
  14967. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14968. }
  14969. } // END OF FOR CCS_QUANTITY
  14970. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14971. }
  14972. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14973. {
  14974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14975. {
  14976. tempIndex = ((gun_index==2) ? 1: 0);
  14977. }
  14978. else
  14979. {
  14980. tempIndex = gun_index;
  14981. }
  14982. for (int index = 0; index < GB_QUANTITY; index++)
  14983. {
  14984. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14985. {
  14986. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14987. }
  14988. } // END OF FOR GB_QUANTITY
  14989. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  14990. }
  14991. else if(gunType[gun_index] == GUN_TYPE_DO)
  14992. {
  14993. tempIndex = gun_index;
  14994. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14995. {
  14996. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14997. {
  14998. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  14999. }
  15000. }
  15001. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15002. }
  15003. else
  15004. {
  15005. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15006. {
  15007. tempIndex = 2;
  15008. }
  15009. else
  15010. {
  15011. tempIndex = gun_index;
  15012. }
  15013. for (int index = 0; index < AC_QUANTITY; index++)
  15014. {
  15015. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15016. {
  15017. 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
  15018. }
  15019. } // END OF FOR AC_QUANTITY
  15020. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15021. }
  15022. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15023. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15024. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15025. //strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15026. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15027. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15028. }
  15029. //2.5============================================== End SoC =========================================================
  15030. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15031. {
  15032. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15033. 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))
  15034. {
  15035. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15036. {
  15037. tempIndex = ((gun_index==2) ? 1: 0);
  15038. }
  15039. else
  15040. {
  15041. tempIndex = gun_index;
  15042. }
  15043. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15044. {
  15045. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15046. {
  15047. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15048. {
  15049. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15050. }
  15051. }
  15052. }
  15053. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15054. {
  15055. for (int index = 0; index < CCS_QUANTITY; index++)
  15056. {
  15057. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15058. {
  15059. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15060. }
  15061. }
  15062. }
  15063. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15064. {
  15065. for (int index = 0; index < GB_QUANTITY; index++)
  15066. {
  15067. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15068. {
  15069. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15070. }
  15071. }
  15072. }
  15073. else if(gunType[gun_index] == GUN_TYPE_DO)
  15074. {
  15075. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15076. {
  15077. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15078. {
  15079. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  15080. }
  15081. }
  15082. }
  15083. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15084. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15085. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15086. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15087. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  15088. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15089. } // END FOR DC CASE
  15090. }
  15091. //2.6====================================== Current.Import L2 ==============================================
  15092. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15093. {
  15094. // AC 3 phase L2 current
  15095. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15096. {
  15097. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15098. {
  15099. tempIndex = 2;
  15100. }
  15101. else
  15102. {
  15103. tempIndex = gun_index;
  15104. }
  15105. for (int index = 0; index < AC_QUANTITY; index++)
  15106. {
  15107. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15108. {
  15109. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  15110. }
  15111. }// End of for AC_QUANTITY
  15112. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  15113. }
  15114. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15115. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  15116. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  15117. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  15118. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15119. }
  15120. //2.7====================================== Current.Import L3 ==============================================
  15121. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import") != NULL)
  15122. {
  15123. // AC 3 phase L3 current
  15124. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15125. {
  15126. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15127. {
  15128. tempIndex = 2;
  15129. }
  15130. else
  15131. {
  15132. tempIndex = gun_index;
  15133. }
  15134. for (int index = 0; index < AC_QUANTITY; index++)
  15135. {
  15136. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15137. {
  15138. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  15139. }
  15140. }// End of for AC_QUANTITY
  15141. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  15142. }
  15143. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15144. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  15145. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  15146. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  15147. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15148. }
  15149. //2.9====================================== Voltage L2 ====================================================
  15150. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15151. {
  15152. // AC 3 phase L2 volatge
  15153. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15154. {
  15155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15156. {
  15157. tempIndex = 2;
  15158. }
  15159. else
  15160. {
  15161. tempIndex = gun_index;
  15162. }
  15163. for (int index = 0; index < AC_QUANTITY; index++)
  15164. {
  15165. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15166. {
  15167. 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
  15168. }
  15169. } // END OF FOR AC_QUANTITY
  15170. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  15171. }
  15172. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15173. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  15174. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  15175. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  15176. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15177. }
  15178. //2.10====================================== Voltage L3 ====================================================
  15179. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Voltage") != NULL)
  15180. {
  15181. // AC 3 phase L3 volatge
  15182. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D')))
  15183. {
  15184. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15185. {
  15186. tempIndex = 2;
  15187. }
  15188. else
  15189. {
  15190. tempIndex = gun_index;
  15191. }
  15192. for (int index = 0; index < AC_QUANTITY; index++)
  15193. {
  15194. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15195. {
  15196. 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
  15197. }
  15198. } // END OF FOR AC_QUANTITY
  15199. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  15200. }
  15201. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15202. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  15203. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  15204. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  15205. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15206. }
  15207. //====================== Start SoC ================================
  15208. if(strstr((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "SOC") != NULL)
  15209. {
  15210. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15211. 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))
  15212. {
  15213. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  15214. {
  15215. tempIndex = ((gun_index==2) ? 1: 0);
  15216. }
  15217. else
  15218. {
  15219. tempIndex = gun_index;
  15220. }
  15221. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15222. {
  15223. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15224. {
  15225. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15226. {
  15227. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  15228. }
  15229. }
  15230. }
  15231. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15232. {
  15233. for (int index = 0; index < CCS_QUANTITY; index++)
  15234. {
  15235. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15236. {
  15237. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  15238. }
  15239. }
  15240. }
  15241. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15242. {
  15243. for (int index = 0; index < GB_QUANTITY; index++)
  15244. {
  15245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15246. {
  15247. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  15248. }
  15249. }
  15250. }
  15251. else if(gunType[gun_index] == GUN_TYPE_DO)
  15252. {
  15253. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15254. {
  15255. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15256. {
  15257. sprintf((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  15258. }
  15259. }
  15260. }
  15261. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15262. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  15263. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15264. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  15265. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  15266. strcpy((char *)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15267. } // END FOR DC CASE
  15268. }
  15269. //======================================== Message create ==============================================
  15270. json_object *StopTransaction = json_object_new_object();
  15271. json_object *transactionDatas = json_object_new_array();
  15272. json_object *sampledValues = json_object_new_array();
  15273. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag) > 0)
  15274. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].IdTag));
  15275. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].MeterStop));
  15276. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionId));
  15277. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].Timestamp));
  15278. json_object_object_add(StopTransaction, "reason", json_object_new_string("PowerLoss"));
  15279. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData);idxTrans++)
  15280. {
  15281. json_object *transactionData = json_object_new_object();
  15282. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  15283. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  15284. {
  15285. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  15286. {
  15287. json_object *sampledValue = json_object_new_object();
  15288. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  15289. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  15290. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  15291. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  15292. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  15293. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  15294. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  15295. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  15296. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  15297. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  15298. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  15299. if(strlen((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  15300. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16DataPH->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  15301. json_object_array_add(sampledValues, sampledValue);
  15302. }
  15303. }
  15304. json_object_object_add(transactionData, "sampledValue", sampledValues);
  15305. json_object_array_add(transactionDatas, transactionData);
  15306. }
  15307. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  15308. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  15309. ,MESSAGE_TYPE_CALL
  15310. ,guid
  15311. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  15312. json_object_put(StopTransaction);
  15313. // Check File "TempStopTransaction" Exist
  15314. if((access(TempStopTransaction,F_OK))!=-1)
  15315. {
  15316. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15317. fclose(fopen(TempStopTransaction, "w"));
  15318. }
  15319. else
  15320. {
  15321. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15322. FILE *log = fopen(TempStopTransaction, "w+");
  15323. if(log == NULL)
  15324. {
  15325. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15326. return ;
  15327. }
  15328. else
  15329. {
  15330. fclose(log);
  15331. }
  15332. }
  15333. //Add TempStopTransaction | Update TempStopTransaction
  15334. // open file for writing
  15335. FILE *outfile;
  15336. outfile = fopen (TempStopTransaction, "a");
  15337. //DEBUG_INFO("data = %s\n", queuedata);
  15338. fputs(queuedata, outfile);
  15339. fputs("\n", outfile);
  15340. fclose (outfile);
  15341. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15342. }
  15343. void checkTempStopTransaction(int gun_index)
  15344. {
  15345. FILE *fptr1;
  15346. char ch;
  15347. char str[QUEUE_MESSAGE_LENGTH]={0};
  15348. char guid[37]={0};
  15349. char tempdata[65]={0};
  15350. char connectorStr[2]={0};
  15351. char TempStopTransaction[256];
  15352. sprintf(TempStopTransaction, "/Storage/OCPP_PH/TempStopTransaction_%d", (gun_index+1));
  15353. fptr1 = fopen(TempStopTransaction, "r");
  15354. //TempStopTransaction格式: 槍號,StopTransaction封包
  15355. if (!fptr1)
  15356. {
  15357. //printf(" File not found or unable to open the input file!!\n");
  15358. return ;
  15359. }
  15360. ch=fgetc(fptr1);
  15361. //printf(" Now the content of the file %s is : \n",fname);
  15362. rewind(fptr1);
  15363. if(ch!=EOF)
  15364. {
  15365. // copy all contents to the temporary file except the specific line
  15366. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15367. {
  15368. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15369. if(str[0]=='\0')
  15370. {
  15371. break;
  15372. }
  15373. //TempStopTransaction格式: 槍號,StopTransaction封包
  15374. strncpy(connectorStr, str, 1);
  15375. if(atoi(connectorStr) != (gun_index+1))
  15376. {
  15377. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  15378. fclose(fptr1);
  15379. return ;
  15380. }
  15381. //random_uuid(guid);
  15382. strncpy(guid, str+6, 36); //copy guid
  15383. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15384. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15385. {
  15386. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15387. }
  15388. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15389. OCPP_insert_transaction_msg(NO, str);
  15390. memset(str,0,ARRAY_SIZE(str));
  15391. }
  15392. }
  15393. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15394. fclose(fptr1);
  15395. remove(TempStopTransaction); // remove the original file
  15396. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15397. }
  15398. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15399. {
  15400. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15401. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15402. ShmOCPP16DataPH->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15403. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15404. strcpy((char *)ShmOCPP16DataPH->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15405. }
  15406. int GetWebSocketPingInterval(void)
  15407. {
  15408. return atoi((const char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15409. }
  15410. int GetServerSign(void)
  15411. {
  15412. return server_sign;
  15413. }
  15414. uint8_t GetOcppSecurityProfile()
  15415. {
  15416. return atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  15417. }
  15418. void GetOcppChargerBoxId(uint8_t *data)
  15419. {
  15420. sprintf((char*)data, "%s", ShmOCPP16DataPH->ChargeBoxId);
  15421. }
  15422. void GetOcppSecurityPassword(uint8_t *data)
  15423. {
  15424. sprintf((char*)data, "%s", ShmOCPP16DataPH->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  15425. }
  15426. void SetOcppVersion(uint8_t *version)
  15427. {
  15428. for (uint8_t idx=0; idx<strlen((char*)version); idx++) version[idx] = tolower(version[idx]);
  15429. DEBUG_INFO("ocpp version: %s\n", version);
  15430. if(strstr((char*)version, "ocpp1.6") != NULL)
  15431. {
  15432. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_16;
  15433. }
  15434. else if(strstr((char*)version, "ocpp2.0") != NULL)
  15435. {
  15436. ShmSysConfigAndInfo->SysInfo.OcppRunningVer = OCPP_RUNNING_VERSION_20;
  15437. system("pkill OcppBackend");
  15438. }
  15439. }
  15440. void SetServerSign(int value)
  15441. {
  15442. server_sign = value;
  15443. }
  15444. int GetBootNotificationInterval(void)
  15445. {
  15446. return BootNotificationInterval;
  15447. }
  15448. int GetInternetConn(void)
  15449. {
  15450. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15451. }
  15452. int GetBackendConnectionTimeout(void)
  15453. {
  15454. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15455. }
  15456. int isConnectorInitMode(int gun_index)
  15457. {
  15458. int tempIndex = 0;
  15459. int result = TRUE;
  15460. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15461. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15462. {
  15463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15464. {
  15465. tempIndex = ((gun_index==2) ? 1: 0);
  15466. }
  15467. else
  15468. {
  15469. tempIndex = gun_index;
  15470. }
  15471. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15472. {
  15473. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15474. {
  15475. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15476. } //end of the same index
  15477. }//end of for CHAdeMO_QUANTITY
  15478. }
  15479. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15480. {
  15481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15482. {
  15483. tempIndex = ((gun_index==2) ? 1: 0);
  15484. }
  15485. else
  15486. {
  15487. tempIndex = gun_index;
  15488. }
  15489. for (int index = 0; index < CCS_QUANTITY; index++)
  15490. {
  15491. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15492. {
  15493. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15494. } //end of the same index
  15495. } // end of for CCS_QUANTITY
  15496. }
  15497. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15498. {
  15499. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15500. {
  15501. tempIndex = ((gun_index==2) ? 1: 0);
  15502. }
  15503. else
  15504. {
  15505. tempIndex = gun_index;
  15506. }
  15507. for (int index = 0; index < GB_QUANTITY; index++)
  15508. {
  15509. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15510. {
  15511. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15512. } //end of the same index
  15513. } // end of for GB_QUANTITY
  15514. }
  15515. else if(gunType[gun_index] == GUN_TYPE_DO)
  15516. {
  15517. tempIndex = gun_index;
  15518. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15519. {
  15520. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15521. {
  15522. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15523. } //end of the same index
  15524. }
  15525. }
  15526. else
  15527. {
  15528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15529. {
  15530. tempIndex = 2;
  15531. }
  15532. else
  15533. {
  15534. tempIndex = gun_index;
  15535. }
  15536. for (int index = 0; index < AC_QUANTITY; index++)
  15537. {
  15538. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15539. {
  15540. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15541. }//end of the same index
  15542. }//end of for AC_QUANTITY
  15543. }
  15544. return result;
  15545. }
  15546. void refreshProcDogTimer()
  15547. {
  15548. ShmOCPP16DataPH->procDogTime = time((time_t*)NULL);
  15549. }
  15550. void InitialSystemValue(void)
  15551. {
  15552. int connectorIndex = 0;
  15553. //int valueASCII = 0;
  15554. server_cycle_Status = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  15555. gunTotalNumber=0;
  15556. SystemInitial = 0;
  15557. locallistVersion=0;
  15558. BootNotificationInterval = 0;
  15559. authorizeRetryTimes = 0;
  15560. GunStatusInterval = 10;
  15561. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  15562. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  15563. //Hear Beat
  15564. HeartBeatWithNOResponse = 0;
  15565. HeartBeatWaitTime = atoi((char*)ShmOCPP16DataPH->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  15566. FirstHeartBeat = 0;
  15567. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  15568. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  15569. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15570. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15571. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15572. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15573. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15574. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15575. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15576. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15577. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15578. memset(gunType, 0, ARRAY_SIZE(gunType));
  15579. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15580. {
  15581. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15582. {
  15583. // DO series
  15584. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15585. {
  15586. SystemInitial = SystemInitial + 1;
  15587. gunTotalNumber = gunTotalNumber + 1;
  15588. gunType[connectorIndex] = GUN_TYPE_DO;
  15589. connectorIndex = connectorIndex + 1;
  15590. }
  15591. }
  15592. else
  15593. {
  15594. // DM, DW, DS series
  15595. //check connector / socket type (index: 8, 9, 10)
  15596. for(int index=7; index <10 ; index++)
  15597. {
  15598. if(index != 8)
  15599. {
  15600. // DC Connector
  15601. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15602. {
  15603. SystemInitial = SystemInitial + 1;
  15604. gunTotalNumber = gunTotalNumber + 1;
  15605. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15606. connectorIndex = connectorIndex + 1;
  15607. }
  15608. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15609. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15610. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15611. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15612. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15613. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15614. {
  15615. SystemInitial = SystemInitial + 1;
  15616. gunTotalNumber = gunTotalNumber + 1;
  15617. gunType[connectorIndex] = GUN_TYPE_CCS;
  15618. connectorIndex = connectorIndex + 1;
  15619. }
  15620. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15621. {
  15622. SystemInitial = SystemInitial + 1;
  15623. gunTotalNumber = gunTotalNumber + 1;
  15624. gunType[connectorIndex] = GUN_TYPE_GBT;
  15625. connectorIndex = connectorIndex + 1;
  15626. }
  15627. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15628. {
  15629. SystemInitial = SystemInitial + 1;
  15630. gunTotalNumber = gunTotalNumber + 1;
  15631. gunType[connectorIndex] = GUN_TYPE_DO;
  15632. connectorIndex = connectorIndex + 1;
  15633. }
  15634. }
  15635. else
  15636. {
  15637. // AC Connector
  15638. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15639. {
  15640. SystemInitial = SystemInitial + 1;
  15641. gunTotalNumber = gunTotalNumber + 1;
  15642. gunType[connectorIndex] = GUN_TYPE_AC;
  15643. connectorIndex = connectorIndex + 1;
  15644. }
  15645. }
  15646. }
  15647. }
  15648. //DEBUG_INFO("DC ...\n");
  15649. }
  15650. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15651. {
  15652. //check connector / socket type (index: 8, 9, 10)
  15653. for(int index=7; index <10 ; index++)
  15654. {
  15655. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15656. {
  15657. SystemInitial = SystemInitial + 1;
  15658. gunTotalNumber = gunTotalNumber + 1;
  15659. gunType[connectorIndex] = GUN_TYPE_AC;
  15660. connectorIndex = connectorIndex + 1;
  15661. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15662. }
  15663. }
  15664. }
  15665. //Status && ConnectorPlugIn Setting
  15666. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15667. {
  15668. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15669. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15670. }
  15671. for (int index = 0; index < CCS_QUANTITY; index++)
  15672. {
  15673. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15674. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15675. }
  15676. for (int index = 0; index < GB_QUANTITY; index++)
  15677. {
  15678. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15679. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15680. }
  15681. for (int index = 0; index < AC_QUANTITY; index++)
  15682. {
  15683. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15684. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15685. }
  15686. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15687. {
  15688. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15689. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15690. }
  15691. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15692. {
  15693. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = 0;
  15694. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  15695. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  15696. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15697. memset(&ShmOCPP16DataPH->StatusNotification[gun_index], 0x00, sizeof(struct StructStatusNotification));
  15698. }
  15699. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  15700. clientTime.Heartbeat=time((time_t*)NULL);
  15701. sleep(1);
  15702. }
  15703. void LWS_Send(char *str)
  15704. {
  15705. //=====================================================
  15706. // Check InternetConn 0: disconnected, 1: connected
  15707. //====================================================
  15708. if(GetOcppConnStatus() == 0)
  15709. {
  15710. DEBUG_INFO("offline now !!!\n");
  15711. return;
  15712. }
  15713. // Only disable isWebsocketSendable operation initiated by charger
  15714. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15715. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15716. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15717. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15718. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15719. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15720. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15721. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15722. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15723. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15724. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15725. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15726. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15727. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15728. {
  15729. isWebsocketSendable = 0;
  15730. }
  15731. pthread_mutex_lock(&lock_send);
  15732. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15733. sprintf((char *)SendBuffer, "%s", str);
  15734. SendBufLen = strlen(str);
  15735. pthread_mutex_unlock(&lock_send);
  15736. lws_callback_on_writable(wsi_client);
  15737. //lws_service(context, 0);
  15738. //sleep(1);
  15739. }
  15740. void LWS_SendNow(char *str)
  15741. {
  15742. //=====================================================
  15743. // Check InternetConn 0: disconnected, 1: connected
  15744. //====================================================
  15745. if(GetOcppConnStatus() == 0)
  15746. {
  15747. DEBUG_INFO("offline now !!!\n");
  15748. return;
  15749. }
  15750. // Only disable isWebsocketSendable operation initiated by charger
  15751. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15752. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15753. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15754. || (strstr((char*)str, "\"DiagnosticsStatusNotification\"") != NULL)
  15755. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15756. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15757. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15758. || (strstr((char*)str, "\"StartTransaction\"") != NULL)
  15759. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15760. || (strstr((char*)str, "\"StopTransaction\"") != NULL)
  15761. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15762. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15763. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15764. || (strstr((char*)str, "\"SignedFirmwareStatusNotification\"") != NULL))
  15765. {
  15766. isWebsocketSendable = 0;
  15767. }
  15768. pthread_mutex_lock(&lock_send);
  15769. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15770. sprintf((char *)SendBuffer, "%s", str);
  15771. SendBufLen = strlen(str);
  15772. pthread_mutex_unlock(&lock_send);
  15773. lws_callback_on_writable(wsi_client);
  15774. lws_service(context, 0);
  15775. //sleep(1);
  15776. }